Skip to content

Commit 45f85b7

Browse files
Take status from latest condition
1 parent 1a4c5a6 commit 45f85b7

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/components/KymaModules/support.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export const enum ModuleTemplateStatus {
1414
Error = 'Error',
1515
}
1616

17+
type ConditionType = {
18+
lastTransitionTime: string;
19+
lastUpdateTime: string;
20+
message: string;
21+
reason: string;
22+
status: string;
23+
type: string;
24+
};
25+
1726
export type KymaResourceSpecModuleType = {
1827
name: string;
1928
channel?: string;
@@ -279,19 +288,31 @@ export function useGetManagerStatus(manager?: ModuleManagerType) {
279288
namespace: manager?.namespace,
280289
},
281290
} as KymaResourceType);
282-
async function fetchModule() {
291+
async function fetchResource() {
283292
try {
284293
const response = await fetch({ relativeUrl: path });
285294
const status = (await response.json())?.status;
286-
setData(status?.conditions?.[0]?.type);
295+
const latest = status?.conditions
296+
?.filter((condition: ConditionType) => condition?.status === 'True')
297+
?.reduce(
298+
(acc: ConditionType, condition: ConditionType) =>
299+
new Date(acc?.lastUpdateTime).getTime() >
300+
new Date(condition?.lastUpdateTime).getTime()
301+
? acc
302+
: condition,
303+
{},
304+
);
305+
if (latest?.type) {
306+
setData(latest.type);
307+
}
287308
} catch (error) {
288309
if (error instanceof Error) {
289310
setError(error);
290311
}
291312
}
292313
}
293314

294-
fetchModule();
315+
fetchResource();
295316
}
296317
// eslint-disable-next-line react-hooks/exhaustive-deps
297318
}, [manager]);

0 commit comments

Comments
 (0)