diff --git a/src/components/app-list/index.tsx b/src/components/app-list/index.tsx index ecd726b52..6e6e1f4b0 100644 --- a/src/components/app-list/index.tsx +++ b/src/components/app-list/index.tsx @@ -16,7 +16,7 @@ import { toggleFavouriteApp, } from '../../state/applications-favourite'; import { RequestState } from '../../state/state-utils/request-states'; -import { sortCompareString } from '../../utils/sort-utils'; +import { dataSorter, sortCompareString } from '../../utils/sort-utils'; import './style.css'; @@ -115,22 +115,21 @@ export const AppList: FunctionComponent = ({ pollApplicationsByNames(pollAppsInterval, true, favourites, includeFields) ); - const apps = allApps.data - .sort((x, y) => sortCompareString(x.name, y.name)) - .map((app) => ({ - app: app, - isFavourite: favourites.includes(app.name), - })); - const favouriteApps = allFavouriteApps.data - .filter(({ name }) => favourites.includes(name)) - .map((app) => ({ app: app, isFavourite: true })); - favouriteApps.push( - ...apps.filter( - (x) => - x.isFavourite && !favouriteApps.some((y) => y.app.name === x.app.name) - ) + const apps = dataSorter(allApps.data, [ + (x, y) => sortCompareString(x.name, y.name), + ]).map((app) => ({ app, isFavourite: favourites.includes(app.name) })); + const favouriteApps = dataSorter( + [ + ...(allFavouriteApps.data ?? []) + .filter(({ name }) => favourites.includes(name)) + .map((app) => ({ app, isFavourite: true })), + ...apps, + ].filter( + ({ app, isFavourite }, i, arr) => + isFavourite && arr.findIndex((x) => x.app.name === app.name) === i // remove non-favourites and duplicates + ), + [(x, y) => sortCompareString(x.app.name, y.app.name)] ); - favouriteApps.sort((x, y) => sortCompareString(x.app.name, y.app.name)); const favStatus: AsyncState = { data: null, diff --git a/src/components/component/scheduled-job/scheduled-batch-list.tsx b/src/components/component/scheduled-job/scheduled-batch-list.tsx index cd8e3aa6c..482b7481b 100644 --- a/src/components/component/scheduled-job/scheduled-batch-list.tsx +++ b/src/components/component/scheduled-job/scheduled-batch-list.tsx @@ -42,16 +42,13 @@ import { refreshEnvironmentScheduledBatches } from '../../../state/subscriptions import { promiseHandler } from '../../../utils/promise-handler'; import { getScheduledBatchUrl } from '../../../utils/routing'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../../utils/sort-utils'; import { smallScheduledBatchName } from '../../../utils/string'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../../utils/table-sort-utils'; import './style.css'; @@ -111,7 +108,7 @@ export const ScheduledBatchList: FunctionComponent = ({ useEffect(() => { setSortedData( - tableDataSorter(scheduledBatchList, [ + dataSorter(scheduledBatchList, [ (x, y) => sortCompareDate(x.created, y.created, dateSort, () => !!dateSort), (x, y) => diff --git a/src/components/component/scheduled-job/scheduled-job-list.tsx b/src/components/component/scheduled-job/scheduled-job-list.tsx index ae6ff1e72..0dd1d9e83 100644 --- a/src/components/component/scheduled-job/scheduled-job-list.tsx +++ b/src/components/component/scheduled-job/scheduled-job-list.tsx @@ -46,16 +46,13 @@ import { refreshEnvironmentScheduledJobs } from '../../../state/subscriptions/ac import { promiseHandler } from '../../../utils/promise-handler'; import { getScheduledJobUrl } from '../../../utils/routing'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../../utils/sort-utils'; import { smallScheduledJobName } from '../../../utils/string'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../../utils/table-sort-utils'; import '../style.css'; @@ -140,7 +137,7 @@ export const ScheduledJobList: FunctionComponent = ({ useEffect(() => { setSortedData( - tableDataSorter(scheduledJobList, [ + dataSorter(scheduledJobList, [ (x, y) => sortCompareDate(x.created, y.created, dateSort, () => !!dateSort), (x, y) => diff --git a/src/components/component/secrets/secret-tables.tsx b/src/components/component/secrets/secret-tables.tsx index fd8407d62..ee0e84c00 100644 --- a/src/components/component/secrets/secret-tables.tsx +++ b/src/components/component/secrets/secret-tables.tsx @@ -25,8 +25,11 @@ import { } from '../../../models/radix-api/secrets/secret'; import { SecretStatus } from '../../../models/radix-api/secrets/secret-status'; import { SecretType } from '../../../models/radix-api/secrets/secret-type'; -import { sortCompareString, sortDirection } from '../../../utils/sort-utils'; -import { tableDataSorter } from '../../../utils/table-sort-utils'; +import { + dataSorter, + sortCompareString, + sortDirection, +} from '../../../utils/sort-utils'; import './style.css'; @@ -101,7 +104,7 @@ function useGetSortedSecrets( useEffect(() => { setSortedData( - tableDataSorter(secrets, [ + dataSorter(secrets, [ (x, y) => sortCompareString( getDisplayName(x), diff --git a/src/components/data-chart/index.tsx b/src/components/data-chart/index.tsx index e961891eb..651be83c0 100644 --- a/src/components/data-chart/index.tsx +++ b/src/components/data-chart/index.tsx @@ -17,7 +17,11 @@ import { createDynatraceApiUrl } from '../../api/api-config'; import { getJson, RadixRequestInit } from '../../api/api-helpers'; import { configVariables } from '../../utils/config'; import { differenceInWords, formatDateMonthTime } from '../../utils/datetime'; -import { sortCompareNumber, sortCompareString } from '../../utils/sort-utils'; +import { + dataSorter, + sortCompareNumber, + sortCompareString, +} from '../../utils/sort-utils'; import './style.css'; @@ -322,10 +326,10 @@ export const AvailabilityCharts: FunctionComponent = () => { ) / 100; const timelineData = generateTimelineData( - [...statusCodes].sort( + dataSorter(statusCodes, [ ({ statusCode: s1, timestamp: t1 }, { statusCode: s2, timestamp: t2 }) => - sortCompareNumber(t1, t2) || sortCompareString(s1, s2) - ) + sortCompareNumber(t1, t2) || sortCompareString(s1, s2), + ]) ); // adjust charts to match start and end diff --git a/src/components/deployments-list/index.tsx b/src/components/deployments-list/index.tsx index c6c085afe..d1c010de7 100644 --- a/src/components/deployments-list/index.tsx +++ b/src/components/deployments-list/index.tsx @@ -11,15 +11,12 @@ import { DeploymentSummaryModelValidationMap, } from '../../models/radix-api/deployments/deployment-summary'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../utils/sort-utils'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -46,7 +43,7 @@ export const DeploymentsList: FunctionComponent = ({ useEffect(() => { setSortedData( - tableDataSorter(deployments?.slice(0, limit || deployments.length), [ + dataSorter(deployments?.slice(0, limit || deployments.length), [ (x, y) => sortCompareDate(x.activeFrom, y.activeFrom, dateSort), (x, y) => sortCompareString( diff --git a/src/components/jobs-list/index.tsx b/src/components/jobs-list/index.tsx index 705b72199..e0e3e4def 100644 --- a/src/components/jobs-list/index.tsx +++ b/src/components/jobs-list/index.tsx @@ -9,15 +9,12 @@ import { JobSummaryModelValidationMap, } from '../../models/radix-api/jobs/job-summary'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../utils/sort-utils'; -import { - getNewSortDir, - tableDataSorter, - TableSortIcon, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -39,7 +36,7 @@ export const JobsList: FunctionComponent = ({ const [pipelineSort, setPipelineSort] = useState(); useEffect(() => { setSortedData( - tableDataSorter(jobs?.slice(0, limit || jobs.length), [ + dataSorter(jobs?.slice(0, limit || jobs.length), [ (x, y) => sortCompareDate(x.created, y.created, dateSort), (x, y) => sortCompareString( diff --git a/src/components/page-active-component/component-replica-log-accordion.tsx b/src/components/page-active-component/component-replica-log-accordion.tsx index 3ae6b1213..e9e19a018 100644 --- a/src/components/page-active-component/component-replica-log-accordion.tsx +++ b/src/components/page-active-component/component-replica-log-accordion.tsx @@ -29,17 +29,17 @@ import { } from '../../store/log-api'; import { FetchQueryResult } from '../../store/types'; import { getFetchErrorData } from '../../store/utils'; -import { sortCompareDate, sortDirection } from '../../utils/sort-utils'; +import { + dataSorter, + sortCompareDate, + sortDirection, +} from '../../utils/sort-utils'; import { copyToTextFile, smallGithubCommitHash, smallReplicaName, } from '../../utils/string'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; interface ComponentNameProps { appName: string; @@ -100,7 +100,7 @@ export const ComponentReplicaLogAccordion: FunctionComponent< useEffect(() => { if (inventory.isSuccess) { setSortedData( - tableDataSorter(inventory.data?.replicas, [ + dataSorter(inventory.data?.replicas, [ (x, y) => sortCompareDate(x.creationTimestamp, y.creationTimestamp, dateSort), ]) @@ -151,25 +151,24 @@ export const ComponentReplicaLogAccordion: FunctionComponent< /> {!!expandedRows[replica.name] && - replica.containers - ?.sort((a, b) => + dataSorter(replica.containers, [ + (a, b) => sortCompareDate( a.creationTimestamp, b.creationTimestamp, 'descending' - ) - ) - .map((container, i, { length }) => ( - i, - })} - container={container} - replicaName={replica.name} - {...{ appName, envName, componentName }} - /> - ))} + ), + ]).map((container, i, { length }) => ( + i, + })} + container={container} + replicaName={replica.name} + {...{ appName, envName, componentName }} + /> + ))} ))} diff --git a/src/components/page-configuration/build-secrets-accordion.tsx b/src/components/page-configuration/build-secrets-accordion.tsx index 6234a14a1..11bdb584e 100644 --- a/src/components/page-configuration/build-secrets-accordion.tsx +++ b/src/components/page-configuration/build-secrets-accordion.tsx @@ -10,7 +10,7 @@ import { ScrimPopup } from '../scrim-popup'; import { SecretForm } from '../secret-form'; import { BuildSecretStatusBadge } from '../status-badges/build-secret-status-badge'; import { BuildSecretModel } from '../../models/radix-api/buildsecrets/build-secret'; -import { sortCompareString } from '../../utils/sort-utils'; +import { dataSorter, sortCompareString } from '../../utils/sort-utils'; import './style.css'; @@ -88,22 +88,22 @@ export const BuildSecretsAccordion: FunctionComponent<{ appName: string }> = ({ {buildSecretsState.data?.length > 0 ? ( - {buildSecretsState.data - .sort((a, b) => sortCompareString(a.name, b.name)) - .map((buildSecret) => ( - -
- + {dataSorter(buildSecretsState.data, [ + (a, b) => sortCompareString(a.name, b.name), + ]).map((buildSecret) => ( + +
+ - -
-
- ))} + +
+
+ ))}
) : ( This app has no build secrets diff --git a/src/components/page-configuration/image-hubs-accordion.tsx b/src/components/page-configuration/image-hubs-accordion.tsx index 6c361754f..aa3f3614e 100644 --- a/src/components/page-configuration/image-hubs-accordion.tsx +++ b/src/components/page-configuration/image-hubs-accordion.tsx @@ -10,7 +10,7 @@ import { ScrimPopup } from '../scrim-popup'; import { SecretForm } from '../secret-form'; import { ImageHubSecretStatusBadge } from '../status-badges/image-hub-secret-status-badge'; import { ImageHubSecretModel } from '../../models/radix-api/privateimagehubs/image-hub-secret'; -import { sortCompareString } from '../../utils/sort-utils'; +import { dataSorter, sortCompareString } from '../../utils/sort-utils'; import './style.css'; @@ -98,23 +98,23 @@ export const ImageHubsAccordion: FunctionComponent<{ appName: string }> = ({ {imageHubState.data?.length > 0 ? ( - {imageHubState.data - .sort((a, b) => sortCompareString(a.server, b.server)) - .map((imageHub) => ( - -
- + {dataSorter(imageHubState.data, [ + (a, b) => sortCompareString(a.server, b.server), + ]).map((imageHub) => ( + +
+ - -
-
- ))} + +
+
+ ))}
) : ( This app has no private image hubs diff --git a/src/components/page-configuration/overview.tsx b/src/components/page-configuration/overview.tsx index c3e61fcbc..991fa2303 100644 --- a/src/components/page-configuration/overview.tsx +++ b/src/components/page-configuration/overview.tsx @@ -16,7 +16,7 @@ import { adGroupModel } from '../graph/adGroupModel'; import { getGroup } from '../graph/graphService'; import { AsyncState } from '../../effects/effect-types'; import { RequestState } from '../../state/state-utils/request-states'; -import { sortCompareString } from '../../utils/sort-utils'; +import { dataSorter, sortCompareString } from '../../utils/sort-utils'; export interface OverviewProps { adGroups?: Array; @@ -52,9 +52,9 @@ export const Overview: FunctionComponent = ({ .then(() => { if (mountedRef.current) { setResult({ - data: data.sort((x, y) => - sortCompareString(x.displayName, y.displayName) - ), + data: dataSorter(data, [ + (x, y) => sortCompareString(x.displayName, y.displayName), + ]), status: RequestState.SUCCESS, }); } diff --git a/src/components/page-environment/environment-overview.tsx b/src/components/page-environment/environment-overview.tsx index ff50bf6d9..a41c6a58f 100644 --- a/src/components/page-environment/environment-overview.tsx +++ b/src/components/page-environment/environment-overview.tsx @@ -53,7 +53,7 @@ import { getAppUrl, getEnvsUrl, } from '../../utils/routing'; -import { sortCompareDate } from '../../utils/sort-utils'; +import { dataSorter, sortCompareDate } from '../../utils/sort-utils'; import { linkToGitHubBranch, linkToGitHubCommit, @@ -317,13 +317,10 @@ export class EnvironmentOverview extends Component { {events && ( - sortCompareDate( - x.lastTimestamp, - y.lastTimestamp, - 'descending' - ) - )} + events={dataSorter(events, [ + ({ lastTimestamp: x }, { lastTimestamp: y }) => + sortCompareDate(x, y, 'descending'), + ])} /> )} diff --git a/src/components/page-scheduled-job/index.tsx b/src/components/page-scheduled-job/index.tsx index e5c360130..cff87174e 100644 --- a/src/components/page-scheduled-job/index.tsx +++ b/src/components/page-scheduled-job/index.tsx @@ -25,7 +25,11 @@ import { RequestState } from '../../state/state-utils/request-states'; import { isNullOrUndefined } from '../../utils/object'; import { connectRouteParams, routeParamLoader } from '../../utils/router'; import { getEnvsUrl } from '../../utils/routing'; -import { sortCompareDate, sortDirection } from '../../utils/sort-utils'; +import { + dataSorter, + sortCompareDate, + sortDirection, +} from '../../utils/sort-utils'; import { pluraliser, routeWithParams, @@ -91,9 +95,9 @@ function useSortReplicasByCreated( const [list, setList] = useState>([]); useEffect(() => { setList( - [...(source || [])].sort((a, b) => - sortCompareDate(a.created, b.created, direction) - ) + dataSorter(source, [ + (a, b) => sortCompareDate(a.created, b.created, direction), + ]) ); }, [direction, source]); diff --git a/src/components/page-scheduled-job/replica-log-accordion.tsx b/src/components/page-scheduled-job/replica-log-accordion.tsx index 2d2b4d09f..a6ad66f3b 100644 --- a/src/components/page-scheduled-job/replica-log-accordion.tsx +++ b/src/components/page-scheduled-job/replica-log-accordion.tsx @@ -30,17 +30,17 @@ import { } from '../../store/log-api'; import { FetchQueryResult } from '../../store/types'; import { getFetchErrorData } from '../../store/utils'; -import { sortCompareDate, sortDirection } from '../../utils/sort-utils'; +import { + dataSorter, + sortCompareDate, + sortDirection, +} from '../../utils/sort-utils'; import { copyToTextFile, smallGithubCommitHash, smallReplicaName, } from '../../utils/string'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; interface JobNameProps { appName: string; @@ -122,7 +122,7 @@ export const JobReplicaLogAccordion: FunctionComponent< useEffect(() => { if (jobInventory.isSuccess) { setSortedData( - tableDataSorter(jobInventory.data?.replicas, [ + dataSorter(jobInventory.data?.replicas, [ (x, y) => sortCompareDate(x.creationTimestamp, y.creationTimestamp, dateSort), ]) @@ -173,30 +173,29 @@ export const JobReplicaLogAccordion: FunctionComponent< /> {!!expandedRows[replica.name] && - replica.containers - ?.sort((a, b) => + dataSorter(replica.containers, [ + (a, b) => sortCompareDate( a.creationTimestamp, b.creationTimestamp, 'descending' - ) - ) - .map((container, i, { length }) => ( - i, - })} - container={container} - replicaName={replica.name} - {...{ - appName, - envName, - jobComponentName, - jobName, - }} - /> - ))} + ), + ]).map((container, i, { length }) => ( + i, + })} + container={container} + replicaName={replica.name} + {...{ + appName, + envName, + jobComponentName, + jobName, + }} + /> + ))} ))} diff --git a/src/components/pipeline-run-task-steps/index.tsx b/src/components/pipeline-run-task-steps/index.tsx index 19c2c1bde..d4dcfd84b 100644 --- a/src/components/pipeline-run-task-steps/index.tsx +++ b/src/components/pipeline-run-task-steps/index.tsx @@ -8,12 +8,12 @@ import { PipelineRunTaskStepModel, PipelineRunTaskStepModelValidationMap, } from '../../models/radix-api/jobs/pipeline-run-task-step'; -import { sortCompareDate, sortDirection } from '../../utils/sort-utils'; import { - getNewSortDir, - tableDataSorter, - TableSortIcon, -} from '../../utils/table-sort-utils'; + dataSorter, + sortCompareDate, + sortDirection, +} from '../../utils/sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -30,7 +30,7 @@ export const PipelineRunTaskSteps: FunctionComponent< const [dateSort, setDateSort] = useState('descending'); useEffect(() => { setSortedData( - tableDataSorter(steps?.slice(0, limit || steps.length), [ + dataSorter(steps?.slice(0, limit || steps.length), [ (x, y) => sortCompareDate(x.started, y.started, dateSort), ]) ); diff --git a/src/components/pipeline-run-tasks/index.tsx b/src/components/pipeline-run-tasks/index.tsx index 6d1ec1428..4249cd886 100644 --- a/src/components/pipeline-run-tasks/index.tsx +++ b/src/components/pipeline-run-tasks/index.tsx @@ -12,12 +12,12 @@ import { PipelineRunTaskModel, PipelineRunTaskModelValidationMap, } from '../../models/radix-api/jobs/pipeline-run-task'; -import { sortCompareDate, sortDirection } from '../../utils/sort-utils'; import { - getNewSortDir, - tableDataSorter, - TableSortIcon, -} from '../../utils/table-sort-utils'; + dataSorter, + sortCompareDate, + sortDirection, +} from '../../utils/sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -41,7 +41,7 @@ export const PipelineRunTasks: FunctionComponent = ({ const [dateSort, setDateSort] = useState('descending'); useEffect(() => { setSortedData( - tableDataSorter(tasks?.slice(0, limit || tasks.length), [ + dataSorter(tasks?.slice(0, limit || tasks.length), [ (x, y) => sortCompareDate(x.started, y.started, dateSort), ]) ); diff --git a/src/components/pipeline-runs/index.tsx b/src/components/pipeline-runs/index.tsx index 44d3522c3..40e1bfac5 100644 --- a/src/components/pipeline-runs/index.tsx +++ b/src/components/pipeline-runs/index.tsx @@ -9,15 +9,12 @@ import { PipelineRunModelValidationMap, } from '../../models/radix-api/jobs/pipeline-run'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../utils/sort-utils'; -import { - getNewSortDir, - tableDataSorter, - TableSortIcon, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -40,7 +37,7 @@ export const PipelineRuns: FunctionComponent = ({ const [envSort, setEnvSort] = useState(); useEffect(() => { setSortedData( - tableDataSorter(pipelineRuns?.slice(0, limit || pipelineRuns.length), [ + dataSorter(pipelineRuns?.slice(0, limit || pipelineRuns.length), [ (x, y) => sortCompareDate(x.started, y.started, dateSort), (x, y) => sortCompareString(x.env, y.env, envSort, false, () => !!envSort), diff --git a/src/components/replica-list/index.tsx b/src/components/replica-list/index.tsx index aa57d04bc..3e2f53022 100644 --- a/src/components/replica-list/index.tsx +++ b/src/components/replica-list/index.tsx @@ -20,16 +20,13 @@ import { ReplicaSummaryNormalizedModelValidationMap, } from '../../models/radix-api/deployments/replica-summary'; import { + dataSorter, sortCompareDate, sortCompareString, sortDirection, } from '../../utils/sort-utils'; import { smallReplicaName } from '../../utils/string'; -import { - TableSortIcon, - getNewSortDir, - tableDataSorter, -} from '../../utils/table-sort-utils'; +import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils'; import './style.css'; @@ -59,7 +56,7 @@ export const ReplicaList: FunctionComponent = ({ useEffect(() => { setSortedData( - tableDataSorter(replicaList, [ + dataSorter(replicaList, [ (x, y) => sortCompareDate(x.created, y.created, dateSort, () => !!dateSort), (x, y) => diff --git a/src/components/vulnerability-details/index.tsx b/src/components/vulnerability-details/index.tsx index ae35efe00..e2629e5a5 100644 --- a/src/components/vulnerability-details/index.tsx +++ b/src/components/vulnerability-details/index.tsx @@ -5,7 +5,11 @@ import { FunctionComponent, useEffect, useState } from 'react'; import { Alert } from '../alert'; import { VulnerabilityList } from '../vulnerability-list'; import { Vulnerability } from '../../store/scan-api'; -import { sortCompareNumber, sortDirection } from '../../utils/sort-utils'; +import { + dataSorter, + sortCompareNumber, + sortDirection, +} from '../../utils/sort-utils'; export interface VulnerabilityDetailsProps { vulnerabilities?: Array; @@ -27,13 +31,13 @@ function useGroupVulnerabilities( >({}); useEffect(() => { - const list = [...(vulnerabilities ?? [])] - .sort((a, b) => sortCompareNumber(a.cvss, b.cvss, 'descending')) - .reduce>>((obj, x) => { - const key = x.severity.toLowerCase(); - (obj[key] = obj[key] ?? []).push(x); - return obj; - }, {}); + const list = dataSorter(vulnerabilities, [ + (a, b) => sortCompareNumber(a.cvss, b.cvss, 'descending'), + ]).reduce>>((obj, x) => { + const key = x.severity.toLowerCase(); + (obj[key] = obj[key] ?? []).push(x); + return obj; + }, {}); setGroupedList(list); }, [vulnerabilities]); diff --git a/src/utils/sort-utils.ts b/src/utils/sort-utils.ts index a14c8defb..ae0e0731c 100644 --- a/src/utils/sort-utils.ts +++ b/src/utils/sort-utils.ts @@ -1,5 +1,21 @@ export type sortDirection = 'ascending' | 'descending'; +/** + * Creates a copy of the array and performs multiple sort operations + * + * @param {Array} array array to sort + * @param {Array} sorters list of sort methods + * @returns sorted copy of array + */ +export function dataSorter( + array: Readonly>, + sorters: Array['sort']>[0]> +): Array { + const data = [...(array ?? [])]; + sorters.map((x) => data.sort(x)); + return data; +} + function sorter(direction: sortDirection): 1 | -1 { return direction === 'ascending' ? 1 : -1; } diff --git a/src/utils/table-sort-utils.tsx b/src/utils/table-sort-utils.tsx index ffd508e64..a0e8ae949 100644 --- a/src/utils/table-sort-utils.tsx +++ b/src/utils/table-sort-utils.tsx @@ -1,8 +1,8 @@ import { Icon, IconProps } from '@equinor/eds-core-react'; import { + IconData, chevron_down, chevron_up, - IconData, unfold_more, } from '@equinor/eds-icons'; import { FunctionComponent } from 'react'; @@ -35,15 +35,6 @@ export function getNewSortDir( return nullable ? null : 'ascending'; } -export function tableDataSorter( - array: Readonly>, - sorters: Array['sort']>[0]> -): Array { - const data = [...(array || [])]; - sorters.map((x) => data.sort(x)); - return data; -} - export const TableSortIcon: FunctionComponent<{ direction: sortDirection; size?: IconProps['size'];