Skip to content

Commit

Permalink
[HUD][BE?] New CheckBoxSelector component (#5858)
Browse files Browse the repository at this point in the history
I see this format used a lot, so I decided to make a component for it
  • Loading branch information
clee2000 authored Nov 4, 2024
1 parent 20f7d98 commit 138d8ee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 94 deletions.
29 changes: 29 additions & 0 deletions torchci/components/CheckBoxSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default function CheckBoxSelector({
value,
setValue,
checkBoxName,
labelText,
}: {
value: boolean;
setValue: (_value: boolean) => void;
checkBoxName: string;
labelText: string;
}) {
return (
<div>
<span
onClick={() => {
setValue(!value);
}}
>
<input
type="checkbox"
name={checkBoxName}
checked={value}
onChange={() => {}}
/>
<label htmlFor={checkBoxName}> {labelText}</label>
</span>
</div>
);
}
24 changes: 9 additions & 15 deletions torchci/pages/failure.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CheckBoxSelector from "components/CheckBoxSelector";
import JobLinks from "components/JobLinks";
import JobSummary from "components/JobSummary";
import LogViewer from "components/LogViewer";
Expand All @@ -22,21 +23,14 @@ function FuzzySearchCheckBox({
setUseFuzzySearch: any;
}) {
return (
<>
<div
onClick={() => {
setUseFuzzySearch(!useFuzzySearch);
}}
>
<input
type="checkbox"
name="useFuzzySearch"
checked={useFuzzySearch}
onChange={() => {}}
/>
<label htmlFor="useFuzzySearch"> Use fuzzy search</label>
</div>
</>
<CheckBoxSelector
checkBoxName="useFuzzySearch"
value={useFuzzySearch}
setValue={() => {
setUseFuzzySearch(!useFuzzySearch);
}}
labelText="Use fuzzy search"
/>
);
}

Expand Down
98 changes: 19 additions & 79 deletions torchci/pages/hud/[repoOwner]/[repoName]/[branch]/[[...page]].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CheckBoxSelector from "components/CheckBoxSelector";
import CopyLink from "components/CopyLink";
import {
GroupHudTableColumns,
Expand Down Expand Up @@ -307,13 +308,17 @@ function GroupFilterableHudTable({
setUseGrouping(false);
}}
/>
<GroupViewCheckBox
useGrouping={useGrouping}
setUseGrouping={setUseGrouping}
<CheckBoxSelector
value={useGrouping}
setValue={(value) => setUseGrouping(value)}
checkBoxName="groupView"
labelText={"Use grouped view"}
/>
<UnstableCheckBox
hideUnstable={hideUnstable}
setHideUnstable={setHideUnstable}
<CheckBoxSelector
value={hideUnstable}
setValue={(value) => setHideUnstable(value)}
checkBoxName="hideUnstable"
labelText={"Hide unstable jobs"}
/>
<MonsterFailuresCheckbox />
<table className={styles.hudTable}>
Expand All @@ -335,62 +340,6 @@ function GroupFilterableHudTable({
);
}

function GroupViewCheckBox({
useGrouping,
setUseGrouping,
}: {
useGrouping: boolean;
setUseGrouping: any;
}) {
return (
<>
<div>
<span
onClick={() => {
setUseGrouping(!useGrouping);
}}
>
<input
type="checkbox"
name="groupView"
checked={useGrouping}
onChange={() => {}}
/>
<label htmlFor="groupView"> Use grouped view</label>
</span>
</div>
</>
);
}

function UnstableCheckBox({
hideUnstable,
setHideUnstable,
}: {
hideUnstable: boolean;
setHideUnstable: any;
}) {
return (
<>
<div>
<span
onClick={() => {
setHideUnstable(!hideUnstable);
}}
>
<input
type="checkbox"
name="hideUnstable"
checked={hideUnstable}
onChange={() => {}}
/>
<label htmlFor="hideUnstable"> Hide unstable jobs</label>
</span>
</div>
</>
);
}

export const MonsterFailuresContext = createContext<
[boolean, ((_value: boolean) => void) | undefined]
>([false, undefined]);
Expand All @@ -415,23 +364,14 @@ export function MonsterFailuresCheckbox() {
MonsterFailuresContext
);
return (
<>
<div title="Replace `X` with a monster icon based on the error line.">
<span
onClick={() => {
setMonsterFailures && setMonsterFailures(!monsterFailures);
}}
>
<input
type="checkbox"
name="monsterFailures"
checked={monsterFailures}
onChange={() => {}}
/>
<label htmlFor="monsterFailures"> Monsterize failures</label>
</span>
</div>
</>
<div title="Replace `X` with a monster icon based on the error line.">
<CheckBoxSelector
value={monsterFailures}
setValue={(value) => setMonsterFailures && setMonsterFailures(value)}
checkBoxName="monsterFailures"
labelText={"Monsterize failures"}
/>
</div>
);
}

Expand Down

0 comments on commit 138d8ee

Please sign in to comment.