Skip to content

Commit

Permalink
use short uuid
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <[email protected]>
  • Loading branch information
loneil committed Mar 27, 2023
1 parent 11da6d6 commit 3af3dbb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
8 changes: 2 additions & 6 deletions frontend/src/components/object/ObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button, Column, DataTable, Dialog, InputSwitch } from '@/lib/primevue';
import { useAuthStore, useAppStore, useMetadataStore, useObjectStore, usePermissionStore } from '@/store';
import { Permissions } from '@/utils/constants';
import { ButtonMode } from '@/utils/enums';
import { formatDateLong } from '@/utils/formatters';
import { formatDateLong, formatShortUuid } from '@/utils/formatters';
import type { Ref } from 'vue';
import type { COMSObject } from '@/types';
Expand Down Expand Up @@ -137,13 +137,9 @@ watch( selectedObjects, () => {
>
<template #body="{ data }">
<div
v-if="data.id?.length > 15"
v-tooltip.bottom="{ value: data.id }"
>
{{ data.id }}
</div>
<div v-else>
{{ data.id }}
{{ formatShortUuid(data.id) }}
</div>
</template>
</Column>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/utils/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ export function toKebabCase(str: string | null) {
const strs = str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);
return strs ? strs.join('-').toLocaleLowerCase() : '';
}

/**
* @function formatShortUuid
* Converts a UUID identifier to just show the first 8 characters
* @param {String} value A typical UUID used from COMS
* @returns {String} The first 8 chars
*/
export function formatShortUuid(uuid: string) {
return uuid ? uuid.slice(0,8) : uuid;
}
23 changes: 23 additions & 0 deletions frontend/tests/unit/utils/formatters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { toKebabCase, formatShortUuid } from '@/utils/formatters';

describe.skip('formatters.ts toKebabCase', () => {
it('returns the expected UUID values', () => {
expect(toKebabCase('descriptive variable name')).toEqual('descriptive-variable-name');
expect(toKebabCase('INTERESTING FILE')).toEqual('INTERESTING-FILE');
expect(toKebabCase('abc')).toEqual('abc');
});

it('returns blanks if blank provided', () => {
expect(toKebabCase('')).toEqual('');
expect(toKebabCase(null)).toEqual(null);
});
});

describe.skip('formatters.ts formatShortUuid', () => {
it('returns the expected UUID values', () => {
expect(formatShortUuid('f1fc407d-d6b4-4506-ae6b-9cdd52fbb1c5')).toEqual('f1fc407d');
expect(formatShortUuid('f1fc407d')).toEqual('f1fc407d');
expect(formatShortUuid('abc')).toEqual('abc');
expect(formatShortUuid('')).toEqual('');
});
});

0 comments on commit 3af3dbb

Please sign in to comment.