Browse Source

fix: expanded links add record list items display value is not rendered as cell display format

pull/7361/head
Ramesh Mane 11 months ago
parent
commit
291e05481b
  1. 24
      packages/nc-gui/components/smartsheet/grid/GroupBy.vue
  2. 2
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  3. 20
      packages/nc-gui/components/virtual-cell/components/ListItem.vue
  4. 2
      packages/nc-gui/components/virtual-cell/components/ListItems.vue
  5. 40
      packages/nc-gui/composables/useLTARStore.ts
  6. 9
      packages/nocodb-sdk/src/lib/dateTimeHelper.ts

24
packages/nc-gui/components/smartsheet/grid/GroupBy.vue

@ -1,7 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import dayjs from 'dayjs' import { UITypes, dateFormats, parseStringDateTime, timeFormats } from 'nocodb-sdk'
import { UITypes, dateFormats, timeFormats } from 'nocodb-sdk'
import Table from './Table.vue' import Table from './Table.vue'
import GroupBy from './GroupBy.vue' import GroupBy from './GroupBy.vue'
import GroupByTable from './GroupByTable.vue' import GroupByTable from './GroupByTable.vue'
@ -154,18 +153,21 @@ const parseKey = (group: Group) => {
} }
// show the groupBy dateTime field title format as like cell format // show the groupBy dateTime field title format as like cell format
if (key && group.column?.uidt === UITypes.DateTime && dayjs(key).isValid()) { if (key && group.column?.uidt === UITypes.DateTime) {
const dateFormat = parseProp(group.column?.meta)?.date_format ?? dateFormats[0] const dateTime = parseStringDateTime(
const timeFormat = parseProp(group.column?.meta)?.time_format ?? timeFormats[0] key,
`${parseProp(group.column?.meta)?.date_format ?? dateFormats[0]} ${
const dateTimeFormat = `${dateFormat} ${timeFormat}` parseProp(group.column?.meta)?.time_format ?? timeFormats[0]
}`,
return [dayjs(key).utc().local().format(dateTimeFormat)] )
return [dateTime]
} }
// show the groupBy time field title format as like cell format // show the groupBy time field title format as like cell format
if (key && group.column?.uidt === UITypes.Time && dayjs(key).isValid()) { if (key && group.column?.uidt === UITypes.Time) {
return [dayjs(key).format(timeFormats[0])] const time = parseStringDateTime(key, timeFormats[0], false)
return [time]
} }
if (key && group.column?.uidt === UITypes.User) { if (key && group.column?.uidt === UITypes.User) {

2
packages/nc-gui/components/virtual-cell/components/ListChildItems.vue

@ -49,6 +49,7 @@ const {
loadChildrenList, loadChildrenList,
childrenListPagination, childrenListPagination,
relatedTableDisplayValueProp, relatedTableDisplayValueProp,
relatedTableDisplayValueTypeAndFormatProp,
unlink, unlink,
isChildrenListLoading, isChildrenListLoading,
isChildrenListLinked, isChildrenListLinked,
@ -260,6 +261,7 @@ const linkOrUnLink = (rowRef: Record<string, string>, id: string) => {
data-testid="nc-child-list-item" data-testid="nc-child-list-item"
:attachment="attachmentCol" :attachment="attachmentCol"
:related-table-display-value-prop="relatedTableDisplayValueProp" :related-table-display-value-prop="relatedTableDisplayValueProp"
:related-table-display-value-type-and-format-prop="relatedTableDisplayValueTypeAndFormatProp"
:is-linked="childrenList?.list ? isChildrenListLinked[Number.parseInt(id)] : true" :is-linked="childrenList?.list ? isChildrenListLinked[Number.parseInt(id)] : true"
:is-loading="isChildrenListLoading[Number.parseInt(id)]" :is-loading="isChildrenListLoading[Number.parseInt(id)]"
@expand="onClick(refRow)" @expand="onClick(refRow)"

20
packages/nc-gui/components/virtual-cell/components/ListItem.vue

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { isVirtualCol } from 'nocodb-sdk' import { UITypes, isVirtualCol, parseStringDateTime } from 'nocodb-sdk'
import { import {
type ComputedRef, type ComputedRef,
IsExpandedFormOpenInj, IsExpandedFormOpenInj,
@ -22,6 +22,7 @@ const props = defineProps<{
fields: any[] fields: any[]
attachment: any attachment: any
relatedTableDisplayValueProp: string relatedTableDisplayValueProp: string
relatedTableDisplayValueTypeAndFormatProp: { type: string; format: string }
isLoading: boolean isLoading: boolean
isLinked: boolean isLinked: boolean
}>() }>()
@ -68,6 +69,21 @@ const attachments: ComputedRef<Attachment[]> = computed(() => {
return [] return []
} }
}) })
const displayValue = computed(() => {
if (
row.value[props.relatedTableDisplayValueProp] &&
props.relatedTableDisplayValueTypeAndFormatProp.type &&
props.relatedTableDisplayValueTypeAndFormatProp.format
) {
return parseStringDateTime(
row.value[props.relatedTableDisplayValueProp],
props.relatedTableDisplayValueTypeAndFormatProp.format,
!(props.relatedTableDisplayValueTypeAndFormatProp.format === UITypes.Time),
)
}
return row.value[props.relatedTableDisplayValueProp]
})
</script> </script>
<template> <template>
@ -104,7 +120,7 @@ const attachments: ComputedRef<Attachment[]> = computed(() => {
<div class="flex flex-col m-[.75rem] gap-1 flex-grow justify-center overflow-hidden"> <div class="flex flex-col m-[.75rem] gap-1 flex-grow justify-center overflow-hidden">
<div class="flex justify-between xs:gap-x-2"> <div class="flex justify-between xs:gap-x-2">
<span class="font-semibold text-brand-500 nc-display-value xs:(truncate)"> <span class="font-semibold text-brand-500 nc-display-value xs:(truncate)">
{{ row[relatedTableDisplayValueProp] }} {{ displayValue }}
</span> </span>
<div <div
v-if="isLinked && !isLoading" v-if="isLinked && !isLoading"

2
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -44,6 +44,7 @@ const {
loadChildrenList, loadChildrenList,
childrenExcludedListPagination, childrenExcludedListPagination,
relatedTableDisplayValueProp, relatedTableDisplayValueProp,
relatedTableDisplayValueTypeAndFormatProp,
link, link,
relatedTableMeta, relatedTableMeta,
meta, meta,
@ -315,6 +316,7 @@ const onCreatedRecord = (record: any) => {
:fields="fields" :fields="fields"
:attachment="attachmentCol" :attachment="attachmentCol"
:related-table-display-value-prop="relatedTableDisplayValueProp" :related-table-display-value-prop="relatedTableDisplayValueProp"
:related-table-display-value-type-and-format-prop="relatedTableDisplayValueTypeAndFormatProp"
:is-loading="isChildrenExcludedListLoading[Number.parseInt(id)]" :is-loading="isChildrenExcludedListLoading[Number.parseInt(id)]"
:is-linked="isChildrenExcludedListLinked[Number.parseInt(id)]" :is-linked="isChildrenExcludedListLinked[Number.parseInt(id)]"
@expand=" @expand="

40
packages/nc-gui/composables/useLTARStore.ts

@ -1,4 +1,13 @@
import type { ColumnType, LinkToAnotherRecordType, PaginatedType, RequestParams, TableType } from 'nocodb-sdk' import {
UITypes,
type ColumnType,
type LinkToAnotherRecordType,
type PaginatedType,
type RequestParams,
type TableType,
dateFormats,
timeFormats,
} from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { import {
IsPublicInj, IsPublicInj,
@ -20,6 +29,7 @@ import {
useRouter, useRouter,
useSharedView, useSharedView,
watch, watch,
parseProp,
} from '#imports' } from '#imports'
import type { Row } from '#imports' import type { Row } from '#imports'
@ -121,9 +131,36 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
return (relatedTableMeta.value?.columns?.find((c) => c.pv) || relatedTableMeta?.value?.columns?.[0])?.title || '' return (relatedTableMeta.value?.columns?.find((c) => c.pv) || relatedTableMeta?.value?.columns?.[0])?.title || ''
}) })
const relatedTableDisplayValueTypeAndFormatProp = computed(() => {
let dateOrDateTimeFieldTypeAndFormat = {
type: '',
format: '',
}
let currentColumn = relatedTableMeta.value?.columns?.find((c) => c.pv) || relatedTableMeta?.value?.columns?.[0]
if (currentColumn) {
if (currentColumn?.uidt === UITypes.DateTime) {
dateOrDateTimeFieldTypeAndFormat = {
type: currentColumn?.uidt,
format: `${parseProp(currentColumn?.meta)?.date_format ?? dateFormats[0]} ${
parseProp(currentColumn?.meta)?.time_format ?? timeFormats[0]
}`,
}
}
if (currentColumn?.uidt === UITypes.Time) {
dateOrDateTimeFieldTypeAndFormat = {
type: currentColumn?.uidt,
format: `${timeFormats[0]}`,
}
}
}
return dateOrDateTimeFieldTypeAndFormat
})
const relatedTablePrimaryKeyProps = computed(() => { const relatedTablePrimaryKeyProps = computed(() => {
return relatedTableMeta.value?.columns?.filter((c) => c.pk)?.map((c) => c.title) ?? [] return relatedTableMeta.value?.columns?.filter((c) => c.pk)?.map((c) => c.title) ?? []
}) })
const displayValueProp = computed(() => { const displayValueProp = computed(() => {
return (meta.value?.columns?.find((c: Required<ColumnType>) => c.pv) || relatedTableMeta?.value?.columns?.[0])?.title return (meta.value?.columns?.find((c: Required<ColumnType>) => c.pv) || relatedTableMeta?.value?.columns?.[0])?.title
}) })
@ -470,6 +507,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
relatedTableMeta, relatedTableMeta,
loadRelatedTableMeta, loadRelatedTableMeta,
relatedTableDisplayValueProp, relatedTableDisplayValueProp,
relatedTableDisplayValueTypeAndFormatProp,
childrenExcludedList, childrenExcludedList,
childrenList, childrenList,
childrenListCount, childrenListCount,

9
packages/nocodb-sdk/src/lib/dateTimeHelper.ts

@ -79,14 +79,17 @@ export function parseStringDate(v: string, dateFormat: string) {
export function parseStringDateTime( export function parseStringDateTime(
v: string, v: string,
dateTimeFormat: string = `${dateFormats[0]} ${timeFormats[0]}` dateTimeFormat: string = `${dateFormats[0]} ${timeFormats[0]}`,
toLocal: boolean = true
) { ) {
const dayjsObj = dayjs(v).local(); const dayjsObj = toLocal ? dayjs(v).local() : dayjs(v);
if (dayjsObj.isValid()) { if (dayjsObj.isValid()) {
v = dayjsObj.format(dateTimeFormat); v = dayjsObj.format(dateTimeFormat);
} else { } else {
v = dayjs(v, dateTimeFormat).local().format(dateTimeFormat); v = toLocal
? dayjs(v, dateTimeFormat).local().format(dateTimeFormat)
: dayjs(v, dateTimeFormat).format(dateTimeFormat);
} }
return v; return v;

Loading…
Cancel
Save