Skip to content

Commit

Permalink
More changes based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 4, 2024
1 parent 918a5e3 commit 4405715
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
52 changes: 23 additions & 29 deletions web/src/components/storage/DASDFormatProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,38 @@ import { Progress, Stack } from "@patternfly/react-core";
import { Popup } from "~/components/core";
import { _ } from "~/i18n";
import { useDASDDevices, useDASDRunningFormatJobs } from "~/queries/dasd";
import { FormatSummary } from "~/types/dasd";
import { DASDDevice, FormatSummary } from "~/types/dasd";

const DeviceProgress = ({ device, progress }: { device: DASDDevice; progress: FormatSummary }) => (
<Progress
key={`progress_${device.id}`}
size="sm"
max={progress.total}
value={progress.step}
title={`${device.id} - ${device.deviceName}`}
measureLocation="none"
variant={progress.done ? "success" : undefined}
/>
);

export default function DASDFormatProgress() {
const devices = useDASDDevices();
const runningJobs = useDASDRunningFormatJobs().filter(
(job) => Object.keys(job.summary || {}).length > 0,
);

const ProgressContent = ({ progress }: { progress: { [key: string]: FormatSummary } }) =>
Object.entries(progress).map(([id, { total, step, done }]) => {
const device = devices.find((d) => d.id === id);

return (
<Progress
key={`progress_${id}`}
size="sm"
max={total}
value={step}
title={`${device.id} - ${device.deviceName}`}
measureLocation="none"
variant={done ? "success" : undefined}
/>
);
});

return (
<Popup title={_("Formatting DASD devices")} isOpen={runningJobs.length > 0} disableFocusTrap>
{runningJobs.map((job) => {
return (
<Stack
key={`formatting_progress_${job.jobId}`}
hasGutter
className="dasd-format-progress"
>
<ProgressContent key={`progress_content_${job.jobId}`} progress={job.summary} />
</Stack>
);
})}
<Stack hasGutter className="dasd-format-progress">
{runningJobs.map((job) =>
Object.entries(job.summary).map(([id, progress]) => {
const device = devices.find((d) => d.id === id);
return (
<DeviceProgress key={`${id}-format-progress`} device={device} progress={progress} />
);
}),
)}
</Stack>
</Popup>
);
}
7 changes: 6 additions & 1 deletion web/src/components/storage/DASDTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ const mockSelectedDASD: string[] = [];
jest.mock("~/queries/dasd", () => ({
useDASDDevices: () => mockDASDDevices,
useFilterDASD: () => mockDASDFilter,
useFilterDASDChange: () =>
useFilterDASDMutation: () =>
jest
.fn()
.mockImplementation(() => ({ mutate: (data: FilterDASD) => ({ data: mockDASDFilter }) })),
useSelectedDASD: () => mockSelectedDASD,
useSelectedDASDChange: () => jest.fn().mockImplementation(() => ({ data: mockSelectedDASD })),
useEnableDASDMutation: () => jest.fn(),
useDisableDASDMutation: () => jest.fn(),
useEnableDiagMutation: () => jest.fn(),
useDisableDiagMutation: () => jest.fn(),
useFormatDASDMutation: () => jest.fn(),
}));

describe("DASDTable", () => {
Expand Down

0 comments on commit 4405715

Please sign in to comment.