Browse Source

fix: render group by label

pull/6987/head
Pranav C 1 year ago
parent
commit
e9923ffe13
  1. 46
      packages/nc-gui/components/smartsheet/grid/GroupBy.vue
  2. 28
      packages/nc-gui/components/smartsheet/grid/GroupByLabel.vue
  3. 6
      packages/nc-gui/composables/useViewGroupBy.ts
  4. 4
      packages/nocodb/src/db/BaseModelSqlv2.ts

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

@ -1,9 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import {isVirtualCol, UITypes} from 'nocodb-sdk' import { UITypes } 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'
import GroupByLabel from './GroupByLabel.vue'
import { GROUP_BY_VARS, computed, ref } from '#imports' import { GROUP_BY_VARS, computed, ref } from '#imports'
import type { Group, Row } from '#imports' import type { Group, Row } from '#imports'
@ -48,6 +49,8 @@ const fullPage = computed<boolean>(() => {
return props.fullPage ?? (tableHeader.value?.offsetWidth ?? 0) > (props.viewWidth ?? 0) return props.fullPage ?? (tableHeader.value?.offsetWidth ?? 0) > (props.viewWidth ?? 0)
}) })
const { isUIAllowed } = useRoles()
const _activeGroupKeys = ref<string[] | string>() const _activeGroupKeys = ref<string[] | string>()
const activeGroups = computed<string[]>(() => { const activeGroups = computed<string[]>(() => {
@ -137,17 +140,19 @@ const onScroll = (e: Event) => {
} }
const parseKey = (group) => { const parseKey = (group) => {
const key = group.key.toString()
// parse json array key if it's a lookup or link to another record // parse json array key if it's a lookup or link to another record
if ((group.key && group.column?.uidt === UITypes.Lookup) || group.column?.uidt === UITypes.LinkToAnotherRecord) { if ((key && group.column?.uidt === UITypes.Lookup) || group.column?.uidt === UITypes.LinkToAnotherRecord) {
try { try {
const parsedKey = JSON.parse(group.key) const parsedKey = JSON.parse(key)
return parsedKey.join(', ') return parsedKey
} catch { } catch {
// if parsing try to split it by `___` (for sqlite) // if parsing try to split it by `___` (for sqlite)
return group.key.split('___').join(', ') return key.split('___')
} }
} }
return group.key return [key]
} }
</script> </script>
@ -262,32 +267,13 @@ const parseKey = (group) => {
'font-weight': 500, 'font-weight': 500,
}" }"
> >
{{ grp.key in GROUP_BY_VARS.VAR_TITLES ? GROUP_BY_VARS.VAR_TITLES[grp.key] : parseKey(grp) }} <template v-if="grp.key in GROUP_BY_VARS.VAR_TITLES">{{
GROUP_BY_VARS.VAR_TITLES[grp.key]
}}</template>
<GroupByLabel v-for="(val, ind) of parseKey(grp)" v-else :key="ind" :model-value="val" :column="grp.column"/>
</span> </span>
</a-tag> </a-tag>
<div>
<LazySmartsheetVirtualCell
v-if="isVirtualCol(grp.column)"
v-model="grp.key"
class="!text-gray-600"
:column="grp.column"
:row="record"
/>
<LazySmartsheetCell
v-else
v-model="grp.key"
class="!text-gray-600"
:column="grp.column"
:edit-enabled="false"
:read-only="true"
/>
</div>
</div> </div>
</div> </div>
</div> </div>

28
packages/nc-gui/components/smartsheet/grid/GroupByLabel.vue

@ -0,0 +1,28 @@
<script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk'
import { isVirtualCol } from 'nocodb-sdk'
defineProps<{
column: ColumnType
modelValue: any
}>()
provide(ReadonlyInj, true)
</script>
<template>
<div class="pointer-events-none">
<LazySmartsheetRow v-show="!showSkeleton" :row="{ row: { [column.title]: modelValue }, rowMeta: {} }">
<LazySmartsheetVirtualCell v-if="isVirtualCol(column)" :model-value="modelValue" class="!text-gray-600" :column="column" />
<LazySmartsheetCell
v-else
:model-value="modelValue"
class="!text-gray-600"
:column="column"
:edit-enabled="false"
:read-only="true"
/>
</LazySmartsheetRow>
</div>
</template>

6
packages/nc-gui/composables/useViewGroupBy.ts

@ -89,6 +89,12 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
if (col.uidt === UITypes.Checkbox) { if (col.uidt === UITypes.Checkbox) {
return value ? GROUP_BY_VARS.TRUE : GROUP_BY_VARS.FALSE return value ? GROUP_BY_VARS.TRUE : GROUP_BY_VARS.FALSE
} }
// convert to JSON string if non-string value
if(value && typeof value === 'object') {
value = JSON.stringify(value)
}
return value ?? GROUP_BY_VARS.NULL return value ?? GROUP_BY_VARS.NULL
} }

4
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -388,10 +388,6 @@ class BaseModelSqlv2 {
}); });
} }
console.log('=======data');
console.log(qb.toQuery());
console.log('=======data');
return data?.map((d) => { return data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
return d; return d;

Loading…
Cancel
Save