Skip to content

Commit 7b148a5

Browse files
authored
[HUD] Move a bunch of code for the main hud tables around (#6988)
Changes: * Get rid of GroupFilterableHudTable by flattening it into the parent (it was sort of a wrapper component) * Get rid of HudTable component by flattening it into the parent * Create a component just for FiltersAndSettings which has the job filter search and the settings * Move this component so that it's in a location that still gets shown even when the HUD data is still being fetched * Fetches data from contexts and the router instead of the input params for all the settings in this component (not sure if this is a good idea. It's nice to not have to pass a ton of things in, but maybe there are perf issues) * Adds a bunch of useRouter everywhere to get params instead of passing it around as an input param (maybe this has perf issues) Should have no visual changes other than the loading thing Pros: * Got rid of some components (flattened them out) -> less confusing * Move a bunch of input params to be fetched in the component from providers -> don't need to to pass things around all the time * job filters + settings are still shown when the hud data is still loading Cons: * Maybe causes worse perf? ex more rerenders? unsure
1 parent dc202fb commit 7b148a5

File tree

1 file changed

+77
-122
lines changed

1 file changed

+77
-122
lines changed

torchci/pages/hud/[repoOwner]/[repoName]/[branch]/[[...page]].tsx

Lines changed: 77 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -283,93 +283,68 @@ function HudTableBody({
283283
);
284284
}
285285

286-
function GroupFilterableHudTable({
287-
params,
288-
children,
289-
groupNames,
290-
useGrouping,
291-
setUseGrouping,
292-
hideUnstable,
293-
setHideUnstable,
294-
hideGreenColumns,
295-
setHideGreenColumns,
296-
}: {
297-
params: HudParams;
298-
children: React.ReactNode;
299-
groupNames: string[];
300-
useGrouping: boolean;
301-
setUseGrouping: any;
302-
hideUnstable: boolean;
303-
setHideUnstable: any;
304-
hideGreenColumns: boolean;
305-
setHideGreenColumns: any;
306-
}) {
286+
function FiltersAndSettings({}: {}) {
287+
const router = useRouter();
288+
const params = packHudParams(router.query);
307289
const { jobFilter, handleSubmit } = useTableFilter(params);
308-
const headerNames = groupNames;
309290
const [mergeEphemeralLF, setMergeEphemeralLF] = useContext(MergeLFContext);
310291
const [settingsPanelOpen, setSettingsPanelOpen] = useState(false);
292+
const [hideUnstable, setHideUnstable] = usePreference("hideUnstable");
293+
const [hideGreenColumns, setHideGreenColumns] =
294+
useHideGreenColumnsPreference();
295+
const [useGrouping, setUseGrouping] = useGroupingPreference(
296+
params.nameFilter
297+
);
311298

312299
return (
313-
<>
314-
<div style={{ position: "relative", clear: "both" }}>
315-
<div className={styles.hudControlsRow}>
316-
<JobFilterInput
317-
currentFilter={jobFilter}
318-
handleSubmit={handleSubmit}
319-
/>
320-
<SettingsPanel
321-
settingGroups={{
322-
// You need to specify both checkBoxName and key for each setting.
323-
// `checkbox name` is used by CheckBoxSelector while `key` is
324-
// used to uniquely identify the component in the settings panel.
325-
// As far as I can CheckBoxSelector cannot read or write `key` but
326-
// React requires us to set key since it's a list element, so we
327-
// end up with some unfortunate duplication.
328-
"View Options": [
329-
<CheckBoxSelector
330-
value={useGrouping}
331-
setValue={(value) => setUseGrouping(value)}
332-
checkBoxName="groupView"
333-
key="groupView"
334-
labelText={"Use grouped view"}
335-
/>,
336-
<MonsterFailuresCheckbox key="monsterFailures" />,
337-
],
338-
"Filter Options": [
339-
<CheckBoxSelector
340-
value={hideUnstable}
341-
setValue={(value) => setHideUnstable(value)}
342-
checkBoxName="hideUnstable"
343-
key="hideUnstable"
344-
labelText={"Hide unstable jobs"}
345-
/>,
346-
<CheckBoxSelector
347-
value={hideGreenColumns}
348-
setValue={(value) => setHideGreenColumns(value)}
349-
checkBoxName="hideGreenColumns"
350-
key="hideGreenColumns"
351-
labelText={"Hide green columns"}
352-
/>,
353-
<CheckBoxSelector
354-
value={mergeEphemeralLF}
355-
setValue={setMergeEphemeralLF}
356-
checkBoxName="mergeEphemeralLF"
357-
key="mergeEphemeralLF"
358-
labelText={"Condense LF, ephemeral jobs"}
359-
/>,
360-
],
361-
}}
362-
isOpen={settingsPanelOpen}
363-
onToggle={() => setSettingsPanelOpen(!settingsPanelOpen)}
364-
/>
365-
</div>
366-
<table className={styles.hudTable} style={{ overflow: "auto" }}>
367-
<GroupHudTableColumns names={headerNames} />
368-
<GroupHudTableHeader names={headerNames} />
369-
{children}
370-
</table>
371-
</div>
372-
</>
300+
<div className={styles.hudControlsRow}>
301+
<JobFilterInput currentFilter={jobFilter} handleSubmit={handleSubmit} />
302+
<SettingsPanel
303+
settingGroups={{
304+
// You need to specify both checkBoxName and key for each setting.
305+
// `checkbox name` is used by CheckBoxSelector while `key` is
306+
// used to uniquely identify the component in the settings panel.
307+
// As far as I can CheckBoxSelector cannot read or write `key` but
308+
// React requires us to set key since it's a list element, so we
309+
// end up with some unfortunate duplication.
310+
"View Options": [
311+
<CheckBoxSelector
312+
value={useGrouping}
313+
setValue={(value) => setUseGrouping(value)}
314+
checkBoxName="groupView"
315+
key="groupView"
316+
labelText={"Use grouped view"}
317+
/>,
318+
<MonsterFailuresCheckbox key="monsterFailures" />,
319+
],
320+
"Filter Options": [
321+
<CheckBoxSelector
322+
value={hideUnstable}
323+
setValue={(value) => setHideUnstable(value)}
324+
checkBoxName="hideUnstable"
325+
key="hideUnstable"
326+
labelText={"Hide unstable jobs"}
327+
/>,
328+
<CheckBoxSelector
329+
value={hideGreenColumns}
330+
setValue={(value) => setHideGreenColumns(value)}
331+
checkBoxName="hideGreenColumns"
332+
key="hideGreenColumns"
333+
labelText={"Hide green columns"}
334+
/>,
335+
<CheckBoxSelector
336+
value={mergeEphemeralLF}
337+
setValue={setMergeEphemeralLF}
338+
checkBoxName="mergeEphemeralLF"
339+
key="mergeEphemeralLF"
340+
labelText={"Condense LF, ephemeral jobs"}
341+
/>,
342+
],
343+
}}
344+
isOpen={settingsPanelOpen}
345+
onToggle={() => setSettingsPanelOpen(!settingsPanelOpen)}
346+
/>
347+
</div>
373348
);
374349
}
375350

@@ -416,18 +391,6 @@ export function MonsterFailuresCheckbox() {
416391
);
417392
}
418393

419-
function HudTable({ params }: { params: HudParams }) {
420-
const data = useHudData(params);
421-
if (data === undefined) {
422-
return <LoadingPage />;
423-
}
424-
return (
425-
<>
426-
<GroupedHudTable params={params} data={data} />
427-
</>
428-
);
429-
}
430-
431394
function HudHeader({ params }: { params: HudParams }) {
432395
function handleBranchSubmit(branch: string) {
433396
window.location.href = formatHudUrlForRoute("hud", { ...params, branch });
@@ -525,7 +488,10 @@ export default function Hud() {
525488
style={{ marginLeft: "10px" }}
526489
/>
527490
</div>
528-
<HudTable params={params} />
491+
<div style={{ position: "relative", clear: "both" }}>
492+
<FiltersAndSettings />
493+
<GroupedHudTable params={params} />
494+
</div>
529495
<PageSelector params={params} baseUrl="hud" />
530496
<br />
531497
<div>
@@ -576,13 +542,9 @@ function CopyPermanentLink({
576542
return <CopyLink textToCopy={url} compressed={false} style={style} />;
577543
}
578544

579-
function GroupedHudTable({
580-
params,
581-
data,
582-
}: {
583-
params: HudParams;
584-
data: RowData[];
585-
}) {
545+
function GroupedHudTable({ params }: { params: HudParams }) {
546+
const router = useRouter();
547+
const data = useHudData(params);
586548
const { data: unstableIssuesData } = useSWR<IssueLabelApiResponse>(
587549
`/api/issue/unstable`,
588550
fetcher,
@@ -592,19 +554,16 @@ function GroupedHudTable({
592554
}
593555
);
594556
const jobNames = new Set(
595-
data.flatMap((row) => Array.from(row.nameToJobs.keys()))
557+
data?.flatMap((row) => Array.from(row.nameToJobs.keys()))
596558
);
597559

598-
const [hideUnstable, setHideUnstable] = usePreference("hideUnstable");
599-
const [hideGreenColumns, setHideGreenColumns] =
600-
useHideGreenColumnsPreference();
601-
const [useGrouping, setUseGrouping] = useGroupingPreference(
602-
params.nameFilter
603-
);
560+
const [hideUnstable] = usePreference("hideUnstable");
561+
const [hideGreenColumns] = useHideGreenColumnsPreference();
562+
const [useGrouping] = useGroupingPreference(params.nameFilter);
604563

605564
const { shaGrid, groupNameMapping, jobsWithFailures, groupsWithFailures } =
606565
getGroupingData(
607-
data,
566+
data ?? [],
608567
jobNames,
609568
(!useGrouping && hideUnstable) || (useGrouping && !hideUnstable),
610569
unstableIssuesData ?? []
@@ -614,7 +573,6 @@ function GroupedHudTable({
614573

615574
const { jobFilter } = useTableFilter(params);
616575

617-
const router = useRouter();
618576
useEffect(() => {
619577
// Only run on component mount, this assumes that the user's preference is
620578
// the value in local storage
@@ -688,26 +646,23 @@ function GroupedHudTable({
688646
return true;
689647
});
690648

649+
if (data === undefined) {
650+
return <LoadingPage />;
651+
}
652+
691653
return (
692654
<GroupingContext.Provider
693655
value={{ groupNameMapping, expandedGroups, setExpandedGroups }}
694656
>
695-
<GroupFilterableHudTable
696-
params={params}
697-
groupNames={names}
698-
useGrouping={useGrouping}
699-
setUseGrouping={setUseGrouping}
700-
hideUnstable={hideUnstable}
701-
setHideUnstable={setHideUnstable}
702-
hideGreenColumns={hideGreenColumns}
703-
setHideGreenColumns={setHideGreenColumns}
704-
>
657+
<table className={styles.hudTable} style={{ overflow: "auto" }}>
658+
<GroupHudTableColumns names={names} />
659+
<GroupHudTableHeader names={names} />
705660
<HudTableBody
706661
shaGrid={shaGrid}
707662
names={names}
708663
unstableIssues={unstableIssuesData ?? []}
709664
/>
710-
</GroupFilterableHudTable>
665+
</table>
711666
</GroupingContext.Provider>
712667
);
713668
}

0 commit comments

Comments
 (0)