Commit 7720c805 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '336499-corpus-management-date-formats' into 'master'

Change date time formatting for corpus managment

See merge request gitlab-org/gitlab!66947
parents 31cc97a1 8b897aca
<script> <script>
import { formatDate } from '~/lib/utils/datetime_utility'; import { formatDate } from '~/lib/utils/datetime_utility';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { SHORT_DATE_FORMAT } from '../constants'; import { SHORT_DATE_FORMAT, DATE_FORMATS } from '../constants';
export default { export default {
props: { props: {
...@@ -10,6 +10,12 @@ export default { ...@@ -10,6 +10,12 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
dateFormat: {
type: String,
required: false,
default: SHORT_DATE_FORMAT,
validator: (dateFormat) => DATE_FORMATS.includes(dateFormat),
},
}, },
computed: { computed: {
formattedDate() { formattedDate() {
...@@ -17,7 +23,7 @@ export default { ...@@ -17,7 +23,7 @@ export default {
if (date === null) { if (date === null) {
return __('Never'); return __('Never');
} }
return formatDate(new Date(date), SHORT_DATE_FORMAT); return formatDate(new Date(date), this.dateFormat);
}, },
}, },
}; };
......
...@@ -10,6 +10,10 @@ export const FILE_SYMLINK_MODE = '120000'; ...@@ -10,6 +10,10 @@ export const FILE_SYMLINK_MODE = '120000';
export const SHORT_DATE_FORMAT = 'd mmm, yyyy'; export const SHORT_DATE_FORMAT = 'd mmm, yyyy';
export const ISO_SHORT_FORMAT = 'yyyy-mm-dd';
export const DATE_FORMATS = [SHORT_DATE_FORMAT, ISO_SHORT_FORMAT];
export const timeRanges = [ export const timeRanges = [
{ {
label: __('30 minutes'), label: __('30 minutes'),
......
...@@ -5,6 +5,7 @@ import Name from 'ee/security_configuration/corpus_management/components/columns ...@@ -5,6 +5,7 @@ import Name from 'ee/security_configuration/corpus_management/components/columns
import Target from 'ee/security_configuration/corpus_management/components/columns/target.vue'; import Target from 'ee/security_configuration/corpus_management/components/columns/target.vue';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import UserDate from '~/vue_shared/components/user_date.vue'; import UserDate from '~/vue_shared/components/user_date.vue';
import { ISO_SHORT_FORMAT } from '~/vue_shared/constants';
import deleteCorpusMutation from '../graphql/mutations/delete_corpus.mutation.graphql'; import deleteCorpusMutation from '../graphql/mutations/delete_corpus.mutation.graphql';
const thClass = 'gl-bg-transparent! gl-border-gray-100! gl-border-b-solid! gl-border-b-1!'; const thClass = 'gl-bg-transparent! gl-border-gray-100! gl-border-b-solid! gl-border-b-1!';
...@@ -59,6 +60,7 @@ export default { ...@@ -59,6 +60,7 @@ export default {
}); });
}, },
}, },
dateFormat: ISO_SHORT_FORMAT,
}; };
</script> </script>
<template> <template>
...@@ -72,11 +74,11 @@ export default { ...@@ -72,11 +74,11 @@ export default {
</template> </template>
<template #cell(lastUpdated)="{ item }"> <template #cell(lastUpdated)="{ item }">
<user-date :date="item.lastUpdated" /> <user-date :date="item.lastUpdated" :date-format="$options.dateFormat" />
</template> </template>
<template #cell(lastUsed)="{ item }"> <template #cell(lastUsed)="{ item }">
<user-date :date="item.lastUsed" /> <user-date :date="item.lastUsed" :date-format="$options.dateFormat" />
</template> </template>
<template #cell(actions)="{ item }"> <template #cell(actions)="{ item }">
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import UserDate from '~/vue_shared/components/user_date.vue'; import UserDate from '~/vue_shared/components/user_date.vue';
import { ISO_SHORT_FORMAT } from '~/vue_shared/constants';
import { users } from '../mock_data'; import { users } from '../mock_data';
const mockDate = users[0].createdAt; const mockDate = users[0].createdAt;
...@@ -22,12 +23,15 @@ describe('FormatDate component', () => { ...@@ -22,12 +23,15 @@ describe('FormatDate component', () => {
}); });
it.each` it.each`
date | output date | dateFormat | output
${mockDate} | ${'13 Nov, 2020'} ${mockDate} | ${undefined} | ${'13 Nov, 2020'}
${null} | ${'Never'} ${null} | ${undefined} | ${'Never'}
${undefined} | ${'Never'} ${undefined} | ${undefined} | ${'Never'}
`('renders $date as $output', ({ date, output }) => { ${mockDate} | ${ISO_SHORT_FORMAT} | ${'2020-11-13'}
initComponent({ date }); ${null} | ${ISO_SHORT_FORMAT} | ${'Never'}
${undefined} | ${ISO_SHORT_FORMAT} | ${'Never'}
`('renders $date as $output', ({ date, dateFormat, output }) => {
initComponent({ date, dateFormat });
expect(wrapper.text()).toBe(output); expect(wrapper.text()).toBe(output);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment