Skip to content

Commit

Permalink
Merge pull request kubev2v#44 from rszwajko/providerStatus
Browse files Browse the repository at this point in the history
Extract provider status mapper
  • Loading branch information
yaacov authored Sep 19, 2022
2 parents 57ab8e2 + 7c0f49f commit 17896e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
20 changes: 2 additions & 18 deletions pkg/web/src/app/common/components/StatusCondition.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { StatusIcon, StatusType } from '@migtools/lib-ui';
import { getMostSeriousCondition } from '@app/common/helpers';
import { StatusIcon } from '@migtools/lib-ui';
import { getMostSeriousCondition, getStatusType } from '@app/common/helpers';
import { StatusCategoryType } from '@app/common/constants';
import { IStatusCondition } from '@app/queries/types';
import { Button, Popover } from '@patternfly/react-core';
Expand All @@ -22,22 +22,6 @@ export const StatusCondition: React.FunctionComponent<IStatusConditionProps> = (
}: IStatusConditionProps) => {
if (!status) return <StatusIcon status="Loading" label="Validating" />;

const getStatusType = (severity: string): StatusType => {
if (severity === 'Ready' || severity === StatusCategoryType.Required) {
return 'Ok';
}
if (severity === StatusCategoryType.Advisory) {
return 'Info';
}
if (severity === 'Pending') {
return 'Loading';
}
if (severity === StatusCategoryType.Critical || severity === StatusCategoryType.Error) {
return 'Error';
}
return 'Warning';
};

const conditions = status?.conditions || [];
const mostSeriousCondition = getMostSeriousCondition(conditions);

Expand Down
17 changes: 17 additions & 0 deletions pkg/web/src/app/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@app/queries/types';
import { UseQueryResult } from 'react-query';
import { IKubeList } from '@app/client/types';
import { StatusType } from '@migtools/lib-ui';

dayjs.extend(utc);
dayjs.extend(timezone);
Expand All @@ -29,6 +30,22 @@ export const findConditionByCategory = (
return conditions.find((condition) => condition.category === category);
};

export const getStatusType = (severity: string): StatusType => {
if (severity === 'Ready' || severity === StatusCategoryType.Required) {
return 'Ok';
}
if (severity === StatusCategoryType.Advisory) {
return 'Info';
}
if (severity === 'Pending') {
return 'Loading';
}
if (severity === StatusCategoryType.Critical || severity === StatusCategoryType.Error) {
return 'Error';
}
return 'Warning';
};

export const getMostSeriousCondition = (conditions: IStatusCondition[]): string => {
if (findConditionByCategory(conditions, StatusCategoryType.Critical)) {
return StatusCategoryType.Critical;
Expand Down

0 comments on commit 17896e6

Please sign in to comment.