From 9315abd33c4b5e00df3fac135c65fb4aea488a27 Mon Sep 17 00:00:00 2001 From: gitdallas <5322142+gitdallas@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:36:58 -0500 Subject: [PATCH] chore(dw): workloadtable factor out columns Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> --- .../workloadStatus/DWWorkloadsTable.tsx | 44 ++----------------- .../workloadStatus/DWWorkloadsTableRow.tsx | 41 ++++++++--------- .../global/workloadStatus/columns.ts | 33 ++++++++++++++ 3 files changed, 56 insertions(+), 62 deletions(-) create mode 100644 frontend/src/pages/distributedWorkloads/global/workloadStatus/columns.ts diff --git a/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTable.tsx b/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTable.tsx index 91edff5e1a..ab7ce95454 100644 --- a/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTable.tsx +++ b/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTable.tsx @@ -1,15 +1,12 @@ import * as React from 'react'; -import { Timestamp } from '@patternfly/react-core'; -import { Td, Tr } from '@patternfly/react-table'; import EmptyStateErrorMessage from '~/components/EmptyStateErrorMessage'; import { DistributedWorkloadsContext } from '~/concepts/distributedWorkloads/DistributedWorkloadsContext'; -import { SortableData, Table } from '~/components/table'; -import { WorkloadKind } from '~/k8sTypes'; +import { Table } from '~/components/table'; import { getStatusInfo } from '~/concepts/distributedWorkloads/utils'; -import { WorkloadStatusLabel } from '~/pages/distributedWorkloads/components/WorkloadStatusLabel'; import { NoWorkloadState } from '~/pages/distributedWorkloads/components/NoWorkloadState'; import { LoadingState } from '~/pages/distributedWorkloads/components/LoadingState'; import DWWorkloadsTableRow from './DWWorkloadsTableRow'; +import { DWWorkloadsTableColumns } from './columns'; export const DWWorkloadsTable: React.FC = () => { const { workloads } = React.useContext(DistributedWorkloadsContext); @@ -27,36 +24,6 @@ export const DWWorkloadsTable: React.FC = () => { return ; } - const columns: SortableData[] = [ - { - field: 'name', - label: 'Name', - sortable: (a, b) => - (a.metadata?.name || 'Unnamed').localeCompare(b.metadata?.name || 'Unnamed'), - }, - { - field: 'priority', - label: 'Priority', - sortable: (a, b) => (a.spec.priority || 0) - (b.spec.priority || 0), - }, - { - field: 'status', - label: 'Status', - sortable: (a, b) => getStatusInfo(a).status.localeCompare(getStatusInfo(b).status), - }, - { - field: 'created', - label: 'Created', - sortable: (a, b) => - (a.metadata?.creationTimestamp || '').localeCompare(b.metadata?.creationTimestamp || ''), - }, - { - field: 'latest-message', - label: 'Latest Message', - sortable: false, - }, - ]; - if (!workloads.data.length) { return ( @@ -66,13 +33,10 @@ export const DWWorkloadsTable: React.FC = () => { ( - + )} /> ); diff --git a/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTableRow.tsx b/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTableRow.tsx index b370e452e6..628fb15365 100644 --- a/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTableRow.tsx +++ b/frontend/src/pages/distributedWorkloads/global/workloadStatus/DWWorkloadsTableRow.tsx @@ -1,33 +1,30 @@ import * as React from 'react'; import { Td, Tr } from '@patternfly/react-table'; +import { Timestamp } from '@patternfly/react-core'; import { WorkloadKind } from '~/k8sTypes'; import { WorkloadStatusInfo } from '~/concepts/distributedWorkloads/utils'; import { WorkloadStatusLabel } from '~/pages/distributedWorkloads/components/WorkloadStatusLabel'; -import { Timestamp } from '@patternfly/react-core'; type DWWorkloadsTableRowProps = { - workload: WorkloadKind; - statusInfo: WorkloadStatusInfo; + workload: WorkloadKind; + statusInfo: WorkloadStatusInfo; }; -const DWWorkloadsTableRow: React.FC = ({ - workload, - statusInfo, -}) => ( - - - - - - - +const DWWorkloadsTableRow: React.FC = ({ workload, statusInfo }) => ( + + + + + + + ); export default DWWorkloadsTableRow; diff --git a/frontend/src/pages/distributedWorkloads/global/workloadStatus/columns.ts b/frontend/src/pages/distributedWorkloads/global/workloadStatus/columns.ts new file mode 100644 index 0000000000..6eaaf8f449 --- /dev/null +++ b/frontend/src/pages/distributedWorkloads/global/workloadStatus/columns.ts @@ -0,0 +1,33 @@ +import { SortableData } from '~/components/table'; +import { getStatusInfo } from '~/concepts/distributedWorkloads/utils'; +import { WorkloadKind } from '~/k8sTypes'; + +export const DWWorkloadsTableColumns: SortableData[] = [ + { + field: 'name', + label: 'Name', + sortable: (a, b) => + (a.metadata?.name || 'Unnamed').localeCompare(b.metadata?.name || 'Unnamed'), + }, + { + field: 'priority', + label: 'Priority', + sortable: (a, b) => (a.spec.priority || 0) - (b.spec.priority || 0), + }, + { + field: 'status', + label: 'Status', + sortable: (a, b) => getStatusInfo(a).status.localeCompare(getStatusInfo(b).status), + }, + { + field: 'created', + label: 'Created', + sortable: (a, b) => + (a.metadata?.creationTimestamp || '').localeCompare(b.metadata?.creationTimestamp || ''), + }, + { + field: 'latest-message', + label: 'Latest Message', + sortable: false, + }, +];
{workload.metadata?.name || 'Unnamed'}{workload.spec.priority} - - - {workload.metadata?.creationTimestamp ? ( - - ) : ( - 'Unknown' - )} - {statusInfo.message}
{workload.metadata?.name || 'Unnamed'}{workload.spec.priority} + + + {workload.metadata?.creationTimestamp ? ( + + ) : ( + 'Unknown' + )} + {statusInfo.message}