Skip to content

Commit

Permalink
remove extra utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
austenem committed Oct 10, 2024
1 parent aee97b4 commit fdfcb48
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 152 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
import { DonorIcon } from 'js/shared-styles/icons';
import { getDescription, buildTableData, sortEntities, TableEntity } from './utils';

/**
* =============================================================================
* getDescription
* =============================================================================
*/

test('should handle plain fields', () => {
// Wouldn't actually expect to see age_value anywhere except for donor,
// but shouldn't make a difference... and if it does, we want to know.
expect(getDescription('age_value', { age_value: 'The time elapsed since birth.' })).toEqual(
'The time elapsed since birth.',
);
});

test('should handle donor fields', () => {
expect(getDescription('donor.age_value', { age_value: 'The time elapsed since birth.' })).toEqual(
'For the original donor: The time elapsed since birth.',
);
});

test('should handle sample fields', () => {
expect(getDescription('sample.age_value', { age_value: 'The time elapsed since birth.' })).toEqual(
'For the original sample: The time elapsed since birth.',
);
});

test('should return undefined if there is not a definition', () => {
expect(getDescription('sample.no_such_stem', {})).toEqual(undefined);
});

test('should error if stem is known, but prefix is not', () => {
expect(() => getDescription('no_such_prefix.age_value', { age_value: 'The time elapsed since birth.' })).toThrow();
});
import { buildTableData, sortEntities, TableEntity } from './utils';

/**
* =============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@ import { getMetadata } from 'js/helpers/metadata';
import { ProcessedDatasetInfo } from 'js/pages/Dataset/hooks';
import { MUIIcon, entityIconMap } from 'js/shared-styles/icons/entityIconMap';

function getDescription(field: string, metadataFieldDescriptions: Record<string, string> | Record<string, never>) {
const [prefix, stem] = field.split('.');
if (!stem) {
return metadataFieldDescriptions?.[field];
}
const description = metadataFieldDescriptions?.[stem];
if (!description) {
return undefined;
}
if (prefix === 'donor') {
return `For the original donor: ${metadataFieldDescriptions?.[stem]}`;
}
if (prefix === 'sample') {
return `For the original sample: ${metadataFieldDescriptions?.[stem]}`;
}
throw new Error(`Unrecognized metadata field prefix: ${prefix}`);
}

function buildTableData(
tableData: Record<string, string | object | unknown[]>,
metadataFieldDescriptions: Record<string, string> | Record<string, never>,
Expand All @@ -40,7 +22,7 @@ function buildTableData(
key: entry[0],
// eslint-disable-next-line @typescript-eslint/no-base-to-string
value: Array.isArray(entry[1]) ? entry[1].join(', ') : entry[1].toString(),
description: getDescription(entry[0], metadataFieldDescriptions),
description: metadataFieldDescriptions?.[entry[0]],
}))
);
}
Expand Down Expand Up @@ -73,7 +55,7 @@ interface sortEntitiesProps {
}

function sortEntities({ tableEntities, uuid }: sortEntitiesProps) {
return tableEntities.sort((a, b) => {
return [...tableEntities].sort((a, b) => {
// Current entity at the front
if (a.uuid === uuid) return -1;
if (b.uuid === uuid) return 1;
Expand Down Expand Up @@ -149,4 +131,4 @@ function getTableEntities({ entities, uuid, fieldDescriptions }: getTableEntitie
return sortEntities({ tableEntities, uuid });
}

export { getTableEntities, getDescription, buildTableData, sortEntities };
export { getTableEntities, buildTableData, sortEntities };
63 changes: 0 additions & 63 deletions context/app/static/js/pages/utils/entity-utils.spec.ts

This file was deleted.

33 changes: 0 additions & 33 deletions context/app/static/js/pages/utils/entity-utils.ts

This file was deleted.

0 comments on commit fdfcb48

Please sign in to comment.