Skip to content

Commit

Permalink
Refactor process column mapping to use a dedicated function for impro…
Browse files Browse the repository at this point in the history
…ved readability and maintainability
  • Loading branch information
guidomodarelli committed Oct 23, 2024
1 parent 5fb561b commit c7be1ec
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { KeyEquivalence } from "../../../../../common/csv-key-equivalence";
import { KeyEquivalence } from '../../../../../common/csv-key-equivalence';

const mapFieldName = ({
field,
...rest
}: {
field: string;
name?: string;
}) => ({
...rest,
field,
name: rest.name || KeyEquivalence[field] || field,
});

const windowsColumns = [
{ field: 'name', searchable: true, sortable: true, width: '10%' },
Expand All @@ -8,7 +20,8 @@ const windowsColumns = [
{ field: 'priority', searchable: true, sortable: true },
{ field: 'nlwp', searchable: true, sortable: true },
{ field: 'cmd', searchable: true, sortable: true, width: '30%' },
].map(({field, ...rest}) => ({...rest, field, name: rest.name || KeyEquivalence[field] || field}));
].map(mapFieldName);

const linuxColumns = [
{ field: 'name', searchable: true, sortable: true, width: '10%' },
{ field: 'euser', searchable: true, sortable: true },
Expand All @@ -22,16 +35,16 @@ const linuxColumns = [
{ field: 'session', searchable: true, sortable: true },
{ field: 'nice', searchable: true, sortable: true },
{ field: 'state', searchable: true, sortable: true, width: '15%' },
].map(({field, ...rest}) => ({...rest, field, name: rest.name || KeyEquivalence[field] || field}));
].map(mapFieldName);

const macColumns = [
{ field: 'name', searchable: true, sortable: true, width: '10%' },
{ field: 'euser', searchable: true, sortable: true },
{ field: 'pid', searchable: true, sortable: true },
{ field: 'ppid', searchable: true, sortable: true },
{ field: 'vm_size', searchable: true, sortable: true },
{ field: 'nice', searchable: true, sortable: true },
{ field: 'state', searchable: true, sortable: true, width: '15%' },
].map(({field, ...rest}) => ({...rest, field, name: rest.name || KeyEquivalence[field] || field}));
].map(mapFieldName);

export const processColumns = {
windows: windowsColumns,
Expand Down

0 comments on commit c7be1ec

Please sign in to comment.