Skip to content

Commit

Permalink
replace fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
yangw-dev committed Feb 14, 2025
1 parent f6415a3 commit d71caab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ChartCheckboxGroups from "./helpers/ChartCheckboxGroups";
import { CheckboxItem } from "./helpers/CheckboxGroup";
import DropList from "./helpers/DropList";
import styles from "./RenderLineChartComponents.module.css";
const defaultCategory = "all";

const RenderLinePickerOptions = ({
lines,
Expand All @@ -18,25 +19,30 @@ const RenderLinePickerOptions = ({
setLines: (line: any[]) => void;
lineFilterConfig: PickerConfig[];
}) => {
const [category, setCategory] = useState<string>("");
const [category, setCategory] = useState<string>(defaultCategory);
const [options, setOptions] = useState<any>([]);
const [groups, setGroups] = useState<any>([]);

useEffect(() => {
renderOptions();
render();
}, [lines, lineFilterConfig]);

function render() {
function renderOptions() {
let options = lineFilterConfig.map((config) => {
return { value: config.category, name: config.category };
});
setOptions(options);
}

function render() {
const config = lineFilterConfig.find((item) => item.category == category);
if (!config) {
setGroups([]);
return;
}

// render checkboxes
const res = config.types.map((type) => {
return {
parentName: type.name,
Expand All @@ -46,16 +52,28 @@ const RenderLinePickerOptions = ({
setGroups(res);
}

function resetLines() {
function resetLines(category: string) {
// clear all lines
const newLines = lines.map((line) => {
line.hidden = true;
return line;
});
// show all lines in the selected category
const config = lineFilterConfig.find((item) => item.category == category);
if (config) {
config.types.forEach((type) => {
newLines.forEach((line) => {
if (containsAllSubstrings(line.id, type.tags)) {
line.hidden = false;
}
});
});
}
setLines(newLines);
}

useEffect(() => {
resetLines();
resetLines(category);
render();
}, [category]);

Expand Down Expand Up @@ -95,7 +113,11 @@ const RenderLinePickerOptions = ({
{options.length > 0 && (
<div className={styles.rowFlexCenter}>
<div>Group by:</div>
<DropList onChange={changeLineCateory} options={options}></DropList>
<DropList
onChange={changeLineCateory}
options={options}
defaultValue={defaultCategory}
></DropList>
</div>
)}
{groups.length > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ import { useState } from "react";
export default function DropList({
onChange,
options,
defaultValue,
}: {
onChange: (value: string) => void;
options: { value: string; name: string }[];
defaultValue?: string;
}) {
const [value, setValue] = useState<string>("unselect");
const [value, setValue] = useState<string>(defaultValue ?? "unselect");

const handleChange = (event: SelectChangeEvent) => {
setValue(event.target.value);
onChange(event.target.value);
};

return (
<div>
<FormControl sx={{ m: 1, minWidth: 80 }}>
<Select value={value} onChange={handleChange} autoWidth>
<MenuItem value={"unselect"}>{"unselect"}</MenuItem>
{defaultValue ?? <MenuItem value={"unselect"}>{"unselect"}</MenuItem>}
{options.map((option, idx) => {
return (
<MenuItem key={idx} value={option.value}>
Expand Down
2 changes: 1 addition & 1 deletion torchci/components/utilization/UtilizationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const UtilizationPage = ({
<Divider />
<LineRectChart
inputLines={timeSeriesList}
chartWidth={1200}
chartWidth={1400}
disableLineTooltip={false}
disableRect={true}
lineFilterConfig={lineFilters}
Expand Down

0 comments on commit d71caab

Please sign in to comment.