Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update refresh status in posture account and other minor improvements #2237

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions deepfence_frontend/apps/dashboard/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13616,9 +13616,11 @@
"node_id": { "type": "string" },
"node_name": { "type": "string" },
"refresh_message": { "type": "string" },
"refresh_status": {
"enum": ["STARTING", "IN_PROGRESS", "ERROR", "COMPLETE"],
"type": "string"
"refresh_status": { "type": "string" },
"refresh_status_map": {
"type": "object",
"additionalProperties": { "type": "integer" },
"nullable": true
},
"scan_status_map": {
"type": "object",
Expand Down Expand Up @@ -14587,7 +14589,8 @@
"config": { "type": "object", "additionalProperties": {}, "nullable": true },
"filters": { "$ref": "#/components/schemas/ModelIntegrationFilters" },
"integration_type": { "type": "string" },
"notification_type": { "type": "string" }
"notification_type": { "type": "string" },
"send_summary": { "type": "boolean" }
}
},
"ModelIntegrationFilters": {
Expand Down Expand Up @@ -14625,7 +14628,8 @@
"filters": { "$ref": "#/components/schemas/ModelIntegrationFilters" },
"id": { "type": "integer" },
"integration_type": { "type": "string" },
"notification_type": { "type": "string" }
"notification_type": { "type": "string" },
"send_summary": { "type": "boolean" }
}
},
"ModelInviteUserRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export interface ModelCloudNodeAccountInfo {
* @type {string}
* @memberof ModelCloudNodeAccountInfo
*/
refresh_status?: ModelCloudNodeAccountInfoRefreshStatusEnum;
refresh_status?: string;
/**
*
* @type {{ [key: string]: number; }}
* @memberof ModelCloudNodeAccountInfo
*/
refresh_status_map?: { [key: string]: number; } | null;
/**
*
* @type {{ [key: string]: number; }}
Expand Down Expand Up @@ -113,17 +119,6 @@ export const ModelCloudNodeAccountInfoCloudProviderEnum = {
} as const;
export type ModelCloudNodeAccountInfoCloudProviderEnum = typeof ModelCloudNodeAccountInfoCloudProviderEnum[keyof typeof ModelCloudNodeAccountInfoCloudProviderEnum];

/**
* @export
*/
export const ModelCloudNodeAccountInfoRefreshStatusEnum = {
Starting: 'STARTING',
InProgress: 'IN_PROGRESS',
Error: 'ERROR',
Complete: 'COMPLETE'
} as const;
export type ModelCloudNodeAccountInfoRefreshStatusEnum = typeof ModelCloudNodeAccountInfoRefreshStatusEnum[keyof typeof ModelCloudNodeAccountInfoRefreshStatusEnum];


/**
* Check if a given object implements the ModelCloudNodeAccountInfo interface.
Expand Down Expand Up @@ -155,6 +150,7 @@ export function ModelCloudNodeAccountInfoFromJSONTyped(json: any, ignoreDiscrimi
'node_name': !exists(json, 'node_name') ? undefined : json['node_name'],
'refresh_message': !exists(json, 'refresh_message') ? undefined : json['refresh_message'],
'refresh_status': !exists(json, 'refresh_status') ? undefined : json['refresh_status'],
'refresh_status_map': !exists(json, 'refresh_status_map') ? undefined : json['refresh_status_map'],
'scan_status_map': !exists(json, 'scan_status_map') ? undefined : json['scan_status_map'],
'version': !exists(json, 'version') ? undefined : json['version'],
};
Expand All @@ -180,6 +176,7 @@ export function ModelCloudNodeAccountInfoToJSON(value?: ModelCloudNodeAccountInf
'node_name': value.node_name,
'refresh_message': value.refresh_message,
'refresh_status': value.refresh_status,
'refresh_status_map': value.refresh_status_map,
'scan_status_map': value.scan_status_map,
'version': value.version,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export interface ModelIntegrationAddReq {
* @memberof ModelIntegrationAddReq
*/
notification_type: string;
/**
*
* @type {boolean}
* @memberof ModelIntegrationAddReq
*/
send_summary?: boolean;
}

/**
Expand Down Expand Up @@ -77,6 +83,7 @@ export function ModelIntegrationAddReqFromJSONTyped(json: any, ignoreDiscriminat
'filters': !exists(json, 'filters') ? undefined : ModelIntegrationFiltersFromJSON(json['filters']),
'integration_type': json['integration_type'],
'notification_type': json['notification_type'],
'send_summary': !exists(json, 'send_summary') ? undefined : json['send_summary'],
};
}

Expand All @@ -93,6 +100,7 @@ export function ModelIntegrationAddReqToJSON(value?: ModelIntegrationAddReq | nu
'filters': ModelIntegrationFiltersToJSON(value.filters),
'integration_type': value.integration_type,
'notification_type': value.notification_type,
'send_summary': value.send_summary,
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export interface ModelIntegrationUpdateReq {
* @memberof ModelIntegrationUpdateReq
*/
notification_type?: string;
/**
*
* @type {boolean}
* @memberof ModelIntegrationUpdateReq
*/
send_summary?: boolean;
}

/**
Expand All @@ -82,6 +88,7 @@ export function ModelIntegrationUpdateReqFromJSONTyped(json: any, ignoreDiscrimi
'id': !exists(json, 'id') ? undefined : json['id'],
'integration_type': !exists(json, 'integration_type') ? undefined : json['integration_type'],
'notification_type': !exists(json, 'notification_type') ? undefined : json['notification_type'],
'send_summary': !exists(json, 'send_summary') ? undefined : json['send_summary'],
};
}

Expand All @@ -99,6 +106,7 @@ export function ModelIntegrationUpdateReqToJSON(value?: ModelIntegrationUpdateRe
'id': value.id,
'integration_type': value.integration_type,
'notification_type': value.notification_type,
'send_summary': value.send_summary,
};
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { capitalize } from 'lodash-es';
import { cn } from 'tailwind-preset';
import { CircleSpinner } from 'ui-components';
import { CircleSpinner, Tooltip } from 'ui-components';

import {
ErrorIcon,
Expand All @@ -22,10 +22,12 @@ export const ScanStatusBadge = ({
status,
className,
justIcon = false,
errorMessage,
}: {
status: string;
className?: string;
justIcon?: boolean;
errorMessage?: string;
}) => {
const wrapperClassName = cn(
'flex items-center gap-1.5 text-text-text-and-icon text-p4a',
Expand All @@ -49,10 +51,23 @@ export const ScanStatusBadge = ({
} else if (isScanFailed(status)) {
return (
<div className={wrapperClassName}>
<span className={cn(iconWrapper, 'text-status-error')}>
<ErrorIcon />
</span>
{!justIcon ? <TruncatedText text={scanStatus} /> : null}
{errorMessage ? (
<Tooltip content={errorMessage}>
<div className="flex items-center gap-x-1.5">
<span className={cn(iconWrapper, 'text-status-error')}>
<ErrorIcon />
</span>
{!justIcon ? <TruncatedText text={scanStatus} /> : null}
</div>
</Tooltip>
) : (
<>
<span className={cn(iconWrapper, 'text-status-error')}>
<ErrorIcon />
</span>
{!justIcon ? <TruncatedText text={scanStatus} /> : null}
</>
)}
</div>
);
} else if (isNeverScanned(status)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSuspenseQuery } from '@suspensive/react-query';
import { useIsFetching } from '@tanstack/react-query';
import { capitalize, startCase } from 'lodash-es';
import { capitalize } from 'lodash-es';
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
import {
ActionFunctionArgs,
Expand All @@ -10,6 +10,7 @@ import {
useSearchParams,
} from 'react-router-dom';
import { toast } from 'sonner';
import { cn } from 'tailwind-preset';
import {
Badge,
Breadcrumb,
Expand Down Expand Up @@ -65,7 +66,6 @@ import { getColorForCompliancePercent } from '@/constants/charts';
import { BreadcrumbWrapper } from '@/features/common/BreadcrumbWrapper';
import { useDownloadScan } from '@/features/common/data-component/downloadScanAction';
import { FilterWrapper } from '@/features/common/FilterWrapper';
import { RefreshAccountStatusError } from '@/features/postures/components/RefreshAccountStatusError';
import { providersToNameMapping } from '@/features/postures/pages/Posture';
import {
getDeleteConfirmationDisplayName,
Expand Down Expand Up @@ -915,6 +915,7 @@ const ActionDropdown = ({
if (!scanId || !nodeType) return;
onTableAction(row, ActionEnumType.DELETE_SCAN);
}}
color="error"
>
Delete latest scan
</DropdownItem>
Expand Down Expand Up @@ -1338,23 +1339,17 @@ const AccountTable = ({
cell: (info) => {
if (nodeType?.endsWith?.('_org')) {
const data = info.row.original.scan_status_map ?? {};
const keys = Object.keys(data);
const statuses = Object.keys(data).map((current, index) => {
const statuses = Object.keys(data).map((current) => {
return (
<>
<div className="flex gap-x-1.5 items-center" key={current}>
<span className="text-text-input-value font-medium">
{data[current]}
</span>
<ScanStatusBadge status={current ?? ''} />
{index < keys.length - 1 ? (
<div className="mx-2 w-px h-[20px] bg-bg-grid-border" />
) : null}
</div>
</>
<div className="flex gap-x-1.5 items-center" key={current}>
<span className="text-text-input-value font-medium">
{data[current]}
</span>
<ScanStatusBadge status={current ?? ''} />
</div>
);
});
return <div className="flex gap-x-1.5">{statuses}</div>;
return <div className="space-y-1.5 py-1">{statuses}</div>;
} else {
const value = info.getValue();
return <ScanStatusBadge status={value ?? ''} />;
Expand All @@ -1367,7 +1362,11 @@ const AccountTable = ({
...columnWidth.active,
header: () => 'Active',
cell: (info) => {
return info.getValue() ? 'Yes' : 'No';
return (
<span className={cn({ 'text-status-success': info.getValue() })}>
{info.getValue() ? 'Yes' : 'No'}
</span>
);
},
}),
];
Expand All @@ -1380,7 +1379,9 @@ const AccountTable = ({
...columnWidth.account_name,
header: () => 'Name',
cell: (info) => {
return <TruncatedText text={info.getValue()} />;
return (
<TruncatedText text={info.getValue() || info.row.original.node_name} />
);
},
}),
);
Expand All @@ -1391,14 +1392,28 @@ const AccountTable = ({
...columnWidth.refresh_status,
header: () => 'Refresh status',
cell: (info) => {
if (isRefreshAccountFailed(info.getValue())) {
return (
<RefreshAccountStatusError
errorMessage={info.row.original.refresh_message ?? 'Unknown error'}
/>
);
if (nodeType?.endsWith?.('_org')) {
const data = info.row.original.refresh_status_map ?? {};
const statuses = Object.keys(data).map((current) => {
return (
<div className="flex gap-x-1.5 items-center" key={current}>
<span className="text-text-input-value font-medium">
{data[current]}
</span>
<ScanStatusBadge
status={current}
errorMessage={info.row.original.refresh_message}
/>
</div>
);
});
return <div className="space-y-1.5 py-1">{statuses}</div>;
} else {
<ScanStatusBadge
status={info.getValue() ?? ''}
errorMessage={info.row.original.refresh_message}
/>;
}
return <TruncatedText text={startCase(info.getValue()?.toLowerCase())} />;
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
ModelCloudComplianceStatusEnum,
ModelCloudNodeAccountInfoRefreshStatusEnum,
ModelCloudNodeAccountsListReqCloudProviderEnum,
ModelComplianceStatusEnum,
ModelScanInfoStatusEnum,
} from '@/api/generated';

export const isCloudNonOrgNode = (nodeType?: string) => {
Expand Down Expand Up @@ -122,7 +122,7 @@ export function getDeleteConfirmationDisplayName(
}

export const isRefreshAccountFailed = (status: string): boolean => {
if (status?.length && ModelCloudNodeAccountInfoRefreshStatusEnum.Error === status) {
if (status?.length && ModelScanInfoStatusEnum.Error === status) {
return true;
}
return false;
Expand Down
Loading
Loading