Browse Source

refactor(nc-gui): rename grp_column_id to fk_grp_col_id

pull/4001/head
Wing-Kam Wong 2 years ago
parent
commit
e768f87cec
  1. 12
      packages/nc-gui/components/dlg/ViewCreate.vue
  2. 4
      packages/nc-gui/components/smartsheet/Kanban.vue
  3. 2
      packages/nc-gui/components/smartsheet/sidebar/RenameableMenuItem.vue
  4. 6
      packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue
  5. 32
      packages/nc-gui/composables/useKanbanViewStore.ts

12
packages/nc-gui/components/dlg/ViewCreate.vue

@ -38,7 +38,7 @@ interface Form {
type: ViewTypes
copy_from_id: string | null
// for kanban view only
grp_column_id: string | null
fk_grp_col_id: string | null
}
const props = defineProps<Props>()
@ -63,7 +63,7 @@ const form = reactive<Form>({
title: props.title || '',
type: props.type,
copy_from_id: null,
grp_column_id: null,
fk_grp_col_id: null,
})
const singleSelectFieldOptions = ref<SelectProps['options']>([])
@ -126,10 +126,10 @@ function init() {
})
if (props.groupingFieldColumnId) {
// take from the one from copy view
form.grp_column_id = props.groupingFieldColumnId
form.fk_grp_col_id = props.groupingFieldColumnId
} else {
// take the first option
form.grp_column_id = singleSelectFieldOptions.value?.[0]?.value as string
form.fk_grp_col_id = singleSelectFieldOptions.value?.[0]?.value as string
}
}
@ -196,11 +196,11 @@ async function onSubmit() {
<a-form-item
v-if="form.type === ViewTypes.KANBAN"
:label="$t('general.groupingField')"
name="grp_column_id"
name="fk_grp_col_id"
:rules="groupingFieldColumnRules"
>
<a-select
v-model:value="form.grp_column_id"
v-model:value="form.fk_grp_col_id"
class="w-full nc-kanban-grouping-field-select"
:options="singleSelectFieldOptions"
:disabled="props.groupingFieldColumnId"

4
packages/nc-gui/components/smartsheet/Kanban.vue

@ -175,11 +175,11 @@ function onMoveCallback(event: { draggedContext: { futureIndex: number } }) {
async function onMoveStack(event: any) {
if (event.moved) {
const { oldIndex, newIndex } = event.moved
const { grp_column_id, meta: stack_meta } = kanbanMetaData.value
const { fk_grp_col_id, meta: stack_meta } = kanbanMetaData.value
groupingFieldColOptions.value[oldIndex].order = newIndex
groupingFieldColOptions.value[newIndex].order = oldIndex
const stackMetaObj = JSON.parse(stack_meta as string) || {}
stackMetaObj[grp_column_id as string] = groupingFieldColOptions.value
stackMetaObj[fk_grp_col_id as string] = groupingFieldColOptions.value
await updateKanbanMeta({
meta: stackMetaObj,
})

2
packages/nc-gui/components/smartsheet/sidebar/RenameableMenuItem.vue

@ -105,7 +105,7 @@ function onDuplicate() {
type: vModel.value.type!,
title: vModel.value.title,
copyViewId: vModel.value.id,
groupingFieldColumnId: (vModel.value.view as KanbanType).grp_column_id!,
groupingFieldColumnId: (vModel.value.view as KanbanType).fk_grp_col_id!,
})
$e('c:view:copy', { view: vModel.value.type })

6
packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue

@ -43,15 +43,15 @@ watch(
)
const groupingFieldColumnId = computed({
get: () => kanbanMetaData.value.grp_column_id,
get: () => kanbanMetaData.value.fk_grp_col_id,
set: async (val) => {
if (val) {
await updateKanbanMeta({
grp_column_id: val,
fk_grp_col_id: val,
})
await loadKanbanMeta()
await loadKanbanData()
;(activeView.value?.view as KanbanType).grp_column_id = val
;(activeView.value?.view as KanbanType).fk_grp_col_id = val
}
},
})

32
packages/nc-gui/composables/useKanbanViewStore.ts

@ -139,27 +139,27 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
: await $api.dbView.kanbanRead(viewMeta.value.id)
// set groupingField
groupingFieldColumn.value =
(meta.value.columns as ColumnType[]).filter((f) => f.id === kanbanMetaData.value.grp_column_id)[0] || {}
(meta.value.columns as ColumnType[]).filter((f) => f.id === kanbanMetaData.value.fk_grp_col_id)[0] || {}
groupingField.value = groupingFieldColumn.value.title!
const { grp_column_id, meta: stack_meta } = kanbanMetaData.value
const { fk_grp_col_id, meta: stack_meta } = kanbanMetaData.value
stackMetaObj.value = stack_meta ? JSON.parse(stack_meta as string) : {}
if (stackMetaObj.value && grp_column_id && stackMetaObj.value[grp_column_id]) {
if (stackMetaObj.value && fk_grp_col_id && stackMetaObj.value[fk_grp_col_id]) {
// keep the existing order (index of the array) but update the values done outside kanban
let isChanged = false
let hasNewOptionsAdded = false
for (const option of (groupingFieldColumn.value.colOptions as SelectOptionsType)?.options ?? []) {
const idx = stackMetaObj.value[grp_column_id].findIndex((ele) => ele.id === option.id)
const idx = stackMetaObj.value[fk_grp_col_id].findIndex((ele) => ele.id === option.id)
if (idx !== -1) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { collapsed, ...rest } = stackMetaObj.value[grp_column_id][idx]
const { collapsed, ...rest } = stackMetaObj.value[fk_grp_col_id][idx]
if (!deepCompare(rest, option)) {
// update the option in stackMetaObj
stackMetaObj.value[grp_column_id][idx] = {
...stackMetaObj.value[grp_column_id][idx],
stackMetaObj.value[fk_grp_col_id][idx] = {
...stackMetaObj.value[fk_grp_col_id][idx],
...option,
}
// rename the key in formattedData & countByStack
@ -175,7 +175,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
}
} else {
// new option found - add to stackMetaObj
stackMetaObj.value[grp_column_id].push({
stackMetaObj.value[fk_grp_col_id].push({
...option,
collapsed: false,
})
@ -188,11 +188,11 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
// handle deleted options
const columnOptionIds = (groupingFieldColumn.value?.colOptions as SelectOptionsType)?.options.map(({ id }) => id)
const cols = stackMetaObj.value[grp_column_id].filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id))
const cols = stackMetaObj.value[fk_grp_col_id].filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id))
for (const col of cols) {
const idx = stackMetaObj.value[grp_column_id].map((ele: Record<string, any>) => ele.id).indexOf(col.id)
const idx = stackMetaObj.value[fk_grp_col_id].map((ele: Record<string, any>) => ele.id).indexOf(col.id)
if (idx !== -1) {
stackMetaObj.value[grp_column_id].splice(idx, 1)
stackMetaObj.value[fk_grp_col_id].splice(idx, 1)
// there are two cases
// 1. delete option from Add / Edit Stack in kanban view
// 2. delete option from grid view, then switch to kanban view
@ -210,7 +210,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
isChanged = true
}
}
groupingFieldColOptions.value = stackMetaObj.value[grp_column_id]
groupingFieldColOptions.value = stackMetaObj.value[fk_grp_col_id]
if (isChanged) {
await updateKanbanStackMeta()
@ -237,9 +237,9 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
}
async function updateKanbanStackMeta() {
const { grp_column_id } = kanbanMetaData.value
if (grp_column_id) {
stackMetaObj.value[grp_column_id] = groupingFieldColOptions.value
const { fk_grp_col_id } = kanbanMetaData.value
if (fk_grp_col_id) {
stackMetaObj.value[fk_grp_col_id] = groupingFieldColOptions.value
await updateKanbanMeta({
meta: stackMetaObj.value,
})
@ -391,7 +391,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
// update kanban stack meta
groupingFieldColOptions.value.splice(stackIdx, 1)
stackMetaObj.value[kanbanMetaData.value.grp_column_id!] = groupingFieldColOptions.value
stackMetaObj.value[kanbanMetaData.value.fk_grp_col_id!] = groupingFieldColOptions.value
await updateKanbanStackMeta()
$e('a:kanban:delete-stack')
} catch (e: any) {

Loading…
Cancel
Save