diff --git a/src/displays/datetime/datetime.vue b/src/displays/datetime/datetime.vue new file mode 100644 index 0000000000..0257624be3 --- /dev/null +++ b/src/displays/datetime/datetime.vue @@ -0,0 +1,48 @@ + + + diff --git a/src/displays/datetime/index.ts b/src/displays/datetime/index.ts new file mode 100644 index 0000000000..aa47cf3a84 --- /dev/null +++ b/src/displays/datetime/index.ts @@ -0,0 +1,11 @@ +import { defineDisplay } from '@/displays/define'; +import DisplayDateTime from './datetime.vue'; + +export default defineDisplay(({ i18n }) => ({ + id: 'datetime', + name: i18n.t('datetime'), + icon: 'query_builder', + handler: DisplayDateTime, + options: [], + types: ['datetime', 'date', 'time'], +})); diff --git a/src/displays/format-title/format-title.story.ts b/src/displays/format-title/format-title.story.ts index b324f2a024..20dace4735 100644 --- a/src/displays/format-title/format-title.story.ts +++ b/src/displays/format-title/format-title.story.ts @@ -18,7 +18,9 @@ export const basic = () => }, }, setup(props) { - const value = computed(() => handler(props.val, null)); + const value = computed(() => + handler(props.val, null, { type: 'string' }) + ); return { value }; }, template: ` diff --git a/src/displays/format-title/format-title.test.ts b/src/displays/format-title/format-title.test.ts index afff48d111..c14a3c795f 100644 --- a/src/displays/format-title/format-title.test.ts +++ b/src/displays/format-title/format-title.test.ts @@ -5,12 +5,12 @@ jest.mock('@directus/format-title'); describe('Displays / Format Title', () => { it('Runs the value through the title formatter', () => { - handler('test', null); + handler('test', null, { type: 'string' }); expect(formatTitle).toHaveBeenCalledWith('test'); }); it('Does not pass the value if the value is falsy', () => { - handler(null, null); + handler(null, null, { type: 'string' }); expect(formatTitle).not.toHaveBeenCalledWith(null); }); }); diff --git a/src/displays/index.ts b/src/displays/index.ts index 821e6ac474..ab9c32f036 100644 --- a/src/displays/index.ts +++ b/src/displays/index.ts @@ -7,6 +7,7 @@ import DisplayFormattedText from './formatted-text'; import DisplayImage from './image'; import DisplayUser from './user'; import DisplayRating from './rating'; +import DisplayDateTime from './datetime'; export const displays = [ DisplayIcon, @@ -18,5 +19,6 @@ export const displays = [ DisplayImage, DisplayUser, DisplayRating, + DisplayDateTime, ]; export default displays; diff --git a/src/displays/types.ts b/src/displays/types.ts index f0f5301ba5..6006076175 100644 --- a/src/displays/types.ts +++ b/src/displays/types.ts @@ -2,7 +2,15 @@ import VueI18n from 'vue-i18n'; import { Component } from 'vue'; import { Field } from '@/stores/fields/types'; -export type DisplayHandlerFunction = (value: any, options: any) => string | null; +export type DisplayHandlerFunctionContext = { + type: string; +}; + +export type DisplayHandlerFunction = ( + value: any, + options: any, + context: DisplayHandlerFunctionContext +) => string | null; export type DisplayConfig = { id: string; diff --git a/src/interfaces/one-to-many/one-to-many.vue b/src/interfaces/one-to-many/one-to-many.vue index 6e538e1fad..d30aeb3e65 100644 --- a/src/interfaces/one-to-many/one-to-many.vue +++ b/src/interfaces/one-to-many/one-to-many.vue @@ -19,6 +19,7 @@ :options="header.field.displayOptions" :interface="header.field.interface" :interface-options="header.field.interfaceOptions" + :type="header.field.type" /> @@ -334,6 +335,7 @@ export default defineComponent({ displayOptions: field.display_options, interface: field.interface, interfaceOptions: field.options, + type: field.type, }, }; diff --git a/src/layouts/tabular/tabular.vue b/src/layouts/tabular/tabular.vue index ddc877b3c1..27bdd66215 100644 --- a/src/layouts/tabular/tabular.vue +++ b/src/layouts/tabular/tabular.vue @@ -93,6 +93,7 @@ :options="header.field.displayOptions" :interface="header.field.interface" :interface-options="header.field.interfaceOptions" + :type="header.field.type" /> @@ -427,6 +428,7 @@ export default defineComponent({ displayOptions: field.display_options, interface: field.interface, interfaceOptions: field.options, + type: field.type, }, })); }, diff --git a/src/views/private/components/layout-drawer-detail/layout-drawer-detail.vue b/src/views/private/components/layout-drawer-detail/layout-drawer-detail.vue index 1adb874f75..659557a625 100644 --- a/src/views/private/components/layout-drawer-detail/layout-drawer-detail.vue +++ b/src/views/private/components/layout-drawer-detail/layout-drawer-detail.vue @@ -12,7 +12,7 @@ export default defineComponent({ props: { value: { type: String, - required: true, + default: 'tabular', }, }, setup(props, { emit }) { diff --git a/src/views/private/components/render-display/render-display.vue b/src/views/private/components/render-display/render-display.vue index 18fbb9ebc2..98cab44bde 100644 --- a/src/views/private/components/render-display/render-display.vue +++ b/src/views/private/components/render-display/render-display.vue @@ -2,7 +2,7 @@ {{ value }} - {{ display.handler(value, options) }} + {{ display.handler(value, options, { type }) }} @@ -42,6 +43,10 @@ export default defineComponent({ type: [String, Number, Object, Array], default: null, }, + type: { + type: String, + required: true, + }, }, setup(props) { const displayInfo = computed( diff --git a/src/views/private/components/render-template/render-template.vue b/src/views/private/components/render-template/render-template.vue index 0acc26de08..a2f8e319f6 100644 --- a/src/views/private/components/render-template/render-template.vue +++ b/src/views/private/components/render-template/render-template.vue @@ -9,6 +9,7 @@ :value="part.value" :interface="part.interface" :interface-options="part.interfaceOptions" + :type="part.type" v-bind="part.options" /> @@ -80,6 +81,7 @@ export default defineComponent({ value: value, interface: field.interface, interfaceOptions: field.options, + type: field.type, }; }) );