Skip to content

Commit b3664f7

Browse files
fix(images): Fix TiCS violations (#5943)
1 parent cffba78 commit b3664f7

File tree

5 files changed

+36
-51
lines changed

5 files changed

+36
-51
lines changed

src/app/images/components/ImagesTable/useImageTableColumns/useImageTableColumns.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const useImageTableColumns = ({
180180
<div
181181
className="p-progress__value"
182182
style={{
183-
width: `${isOptimistic ? 100 : isStopping ? 0 : sync_percentage}%`,
183+
width: `${isOptimistic ? 100 : sync_percentage}%`,
184184
}}
185185
/>
186186
</div>
@@ -314,37 +314,32 @@ const useImageTableColumns = ({
314314
row: Row<Image>;
315315
}) => {
316316
const isCommissioningImage = release === commissioningRelease;
317+
const isCustom = id.endsWith("-custom");
318+
const imageId = Number(id.split("-")[0]);
317319

318-
const isSyncing =
319-
status === "Downloading" || status === "OptimisticDownloading";
320-
const isUpdating =
321-
update_status === "Downloading" ||
322-
update_status === "OptimisticDownloading";
323-
324-
const isOptimistic =
320+
const isOptimisticDownloading =
325321
status === "OptimisticDownloading" ||
326322
update_status === "OptimisticDownloading";
327-
328-
const isStopping =
323+
const isOptimisticStopping =
329324
status === "OptimisticStopping" ||
330325
update_status === "OptimisticStopping";
326+
const isDownloading =
327+
status === "Downloading" || update_status === "Downloading";
331328

332-
const downloadInProgress = isSyncing || isUpdating || isStopping;
333-
329+
const downloadInProgress =
330+
isDownloading || isOptimisticDownloading || isOptimisticStopping;
334331
const downloadAvailable =
335332
status === "Waiting for download" ||
336333
update_status === "Update available";
337334

338335
const canBeDeleted = !isCommissioningImage && !downloadInProgress;
339-
const isCustom = id.endsWith("-custom");
340-
const imageId = Number(id.split("-")[0]);
341336

342337
return getIsGrouped() ? null : (
343338
<div>
344339
{isCustom ? null : downloadInProgress ? (
345340
<Tooltip
346341
message={
347-
!isOptimistic
342+
!isOptimisticDownloading && !isOptimisticStopping
348343
? TOOLTIP_MESSAGES.STOP_SYNC_ACTIVE
349344
: TOOLTIP_MESSAGES.STOP_SYNC_OPTIMISTIC
350345
}
@@ -355,8 +350,8 @@ const useImageTableColumns = ({
355350
className="is-dense u-table-cell-padding-overlap"
356351
disabled={
357352
startSync.isPending ||
358-
isOptimistic ||
359-
isStopping ||
353+
isOptimisticDownloading ||
354+
isOptimisticStopping ||
360355
isCustom
361356
}
362357
hasIcon
@@ -391,7 +386,7 @@ const useImageTableColumns = ({
391386
disabled={
392387
!downloadAvailable ||
393388
stopSync.isPending ||
394-
isStopping ||
389+
isOptimisticStopping ||
395390
isCustom
396391
}
397392
hasIcon

src/app/images/hooks/useOptimisticImages/utils/silentPolling.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ export const parseOptimisticImagesLocalStorage = () => {
5353
return { startingImageIds, stoppingImageIds };
5454
};
5555

56+
const removeImageFromLocalStorage = (imageId: number) => {
57+
const { startingImageIds, stoppingImageIds } =
58+
parseOptimisticImagesLocalStorage();
59+
60+
const updatedStartingIds = startingImageIds.filter((id) => id !== imageId);
61+
const updatedStoppingIds = stoppingImageIds.filter((id) => id !== imageId);
62+
63+
localStorage.setItem(
64+
"optimisticImages",
65+
`OptimisticDownloading=${updatedStartingIds.join(",")};OptimisticStopping=${updatedStoppingIds.join(",")}`
66+
);
67+
};
68+
5669
/**
5770
* Starts a silent polling mechanism to check if optimistically updated images
5871
* have transitioned to "Downloading" state on the backend.
@@ -118,21 +131,8 @@ export const startOrExtendSilentPolling = (queryClient: QueryClient) => {
118131

119132
if (resolved) {
120133
silentPoll.entries.delete(imageId);
121-
const { startingImageIds, stoppingImageIds } =
122-
parseOptimisticImagesLocalStorage();
123-
124134
// Remove the resolved imageId from the appropriate array
125-
const updatedStartingIds = startingImageIds.filter(
126-
(id) => id !== imageId
127-
);
128-
const updatedStoppingIds = stoppingImageIds.filter(
129-
(id) => id !== imageId
130-
);
131-
132-
localStorage.setItem(
133-
"optimisticImages",
134-
`OptimisticDownloading=${updatedStartingIds.join(",")};OptimisticStopping=${updatedStoppingIds.join(",")}`
135-
);
135+
removeImageFromLocalStorage(imageId);
136136
}
137137
}
138138
} catch {
@@ -143,21 +143,8 @@ export const startOrExtendSilentPolling = (queryClient: QueryClient) => {
143143

144144
if (entry.attempts >= MAX_ATTEMPTS_PER_IMAGE) {
145145
silentPoll.entries.delete(imageId);
146-
const { startingImageIds, stoppingImageIds } =
147-
parseOptimisticImagesLocalStorage();
148-
149146
// Remove the timed-out imageId from the appropriate array
150-
const updatedStartingIds = startingImageIds.filter(
151-
(id) => id !== imageId
152-
);
153-
const updatedStoppingIds = stoppingImageIds.filter(
154-
(id) => id !== imageId
155-
);
156-
157-
localStorage.setItem(
158-
"optimisticImages",
159-
`OptimisticDownloading=${updatedStartingIds.join(",")};OptimisticStopping=${updatedStoppingIds.join(",")}`
160-
);
147+
removeImageFromLocalStorage(imageId);
161148
}
162149
}
163150
}

src/app/machines/views/MachineDetails/MachineNetwork/NetworkTable/NetworkTableActions/NetworkTableActions.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactElement } from "react";
1+
import type { ComponentType, ReactElement } from "react";
22

33
import { useSelector } from "react-redux";
44

@@ -209,7 +209,10 @@ const NetworkTableActions = ({
209209
children: `Remove ${getInterfaceTypeText(machine, nic, link)}...`,
210210
onClick: () => {
211211
openSidePanel({
212-
component: RemovePhysicalForm,
212+
// Cast component type to appease TiCS, local compiler shows no error
213+
component: RemovePhysicalForm as ComponentType<
214+
Record<string, unknown>
215+
>,
213216
title: `Remove ${getInterfaceTypeText(machine, nic, link)}`,
214217
props: {
215218
systemId: machine.system_id,

src/app/machines/views/MachineDetails/MachineNetwork/RemovePhysicalForm/RemovePhysicalForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import {
1616
isAlias,
1717
} from "@/app/store/utils";
1818

19-
interface RemovePhysicalProps {
19+
type RemovePhysicalProps = {
2020
link?: NetworkLink | null;
2121
nic?: NetworkInterface | null;
2222
systemId: Machine["system_id"];
23-
}
23+
};
2424

2525
const RemovePhysicalForm = ({
2626
link,

src/app/machines/views/MachineList/MachineListTable/tableModels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const generateSkeletonRows = (
171171
[MachineColumns.POWER]: (
172172
<DoubleRow
173173
primary={<Placeholder>Xxxxxxxxxxx</Placeholder>}
174-
secondary={<Placeholder>Xxxxxxx</Placeholder>}
174+
secondary={<Placeholder>Xxxxxxxxxxx</Placeholder>}
175175
/>
176176
),
177177
[MachineColumns.STATUS]: (

0 commit comments

Comments
 (0)