Skip to content

Commit 4da5641

Browse files
committed
Extract button label helper, replace hardcoded colors with SCSS variables, and remove stale instruction
- Extract nested ternary for button label into getButtonLabel helper - Replace hardcoded color values (#AAA, #777, #333, #555) with SCSS variables ($medium-dark-gray, $muted-gray, $dark-gray); add $muted-gray to colors.scss - Update test to check for force class instead of btn-warning - Remove stale "Check this box before clicking Queue Import" sentence since the dynamic button label makes it self-evident
1 parent d480b8a commit 4da5641

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/components/CollectionImportButton.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ const CollectionImportButton: React.FC<CollectionImportButtonProps> = ({
7373

7474
const feedbackClass = success ? "alert alert-success" : "alert alert-danger";
7575

76-
const buttonLabel = force
77-
? importing
78-
? "Queuing Full Re-import..."
79-
: "Queue Full Re-import"
80-
: importing
81-
? "Queuing..."
82-
: "Queue Import";
76+
const buttonLabel = getButtonLabel(force, importing);
8377

8478
const buttonClass = force
8579
? "btn btn-default collection-import-button force"
@@ -136,8 +130,7 @@ const CollectionImportButton: React.FC<CollectionImportButtonProps> = ({
136130
the last import. Use this to correct metadata that is out of date,
137131
or to resolve issues caused by a previously incomplete import. A
138132
forced re-import will take longer than a regular import because it
139-
re-processes all items. Check this box <em>before</em> clicking
140-
Queue Import.
133+
re-processes all items.
141134
</dd>
142135
</dl>
143136
)}
@@ -149,4 +142,11 @@ const CollectionImportButton: React.FC<CollectionImportButtonProps> = ({
149142
);
150143
};
151144

145+
function getButtonLabel(force: boolean, importing: boolean): string {
146+
if (force) {
147+
return importing ? "Queuing Full Re-import..." : "Queue Full Re-import";
148+
}
149+
return importing ? "Queuing..." : "Queue Import";
150+
}
151+
152152
export default CollectionImportButton;

src/stylesheets/collection.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66

77
i {
8-
color: #AAA;
8+
color: $medium-dark-gray;
99
cursor: pointer;
1010
}
1111
}
@@ -28,13 +28,13 @@
2828
background: none;
2929
border: none;
3030
padding: 0;
31-
color: #777;
31+
color: $muted-gray;
3232
cursor: pointer;
3333
font-size: 0.8rem;
3434
margin-bottom: 1em;
3535

3636
&:hover {
37-
color: #333;
37+
color: $dark-gray;
3838
text-decoration: underline;
3939
}
4040
}
@@ -54,7 +54,7 @@
5454

5555
dd {
5656
margin-left: 0;
57-
color: #555;
57+
color: $muted-gray;
5858
}
5959
}
6060

src/stylesheets/colors.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $red-tint: tint($red, 30%);
1010
$light-gray: #D7D4D0;
1111
$medium-gray: #DDD;
1212
$medium-dark-gray: #AAA;
13+
$muted-gray: #777;
1314
$dark-gray: #080807;
1415
$gray-tint: #F5F5F4;
1516
$gray-border: #CCCCCC;

tests/jest/components/CollectionImportButton.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,20 @@ describe("CollectionImportButton", () => {
165165
).not.toBeInTheDocument();
166166
});
167167

168-
it("button uses btn-warning class when force is checked", async () => {
168+
it("button uses force class when force is checked", async () => {
169169
const user = userEvent.setup();
170170
renderButton();
171171
await expandPanel(user);
172172

173173
const button = screen.getByRole("button", { name: "Queue Import" });
174-
expect(button).toHaveClass("btn-default");
175-
expect(button).not.toHaveClass("btn-warning");
174+
expect(button).not.toHaveClass("force");
176175

177176
await user.click(screen.getByRole("checkbox"));
178177

179178
const forceButton = screen.getByRole("button", {
180179
name: "Queue Full Re-import",
181180
});
182-
expect(forceButton).toHaveClass("btn-warning");
183-
expect(forceButton).not.toHaveClass("btn-default");
181+
expect(forceButton).toHaveClass("force");
184182
});
185183

186184
it("button triggers import with correct args (force=false)", async () => {

0 commit comments

Comments
 (0)