Browse Source

MapView: 'Mapped by' column values should always be delivered - new approach - WIP

pull/4749/head
Daniel Spaude 2 years ago
parent
commit
e8b375fd5b
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 8
      packages/nc-gui/components/smartsheet/Form.vue
  2. 2
      packages/nc-gui/components/smartsheet/Kanban.vue
  3. 2
      packages/nc-gui/components/smartsheet/Map.vue
  4. 30
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  5. 30
      packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue
  6. 26
      packages/nc-gui/composables/useViewColumns.ts
  7. 1
      packages/nc-gui/lib/enums.ts
  8. 25
      packages/nocodb/src/lib/models/View.ts

8
packages/nc-gui/components/smartsheet/Form.vue

@ -1,7 +1,6 @@
<script setup lang="ts">
import Draggable from 'vuedraggable'
import { RelationTypes, UITypes, ViewTypes, getSystemColumns, isVirtualCol } from 'nocodb-sdk'
import { Ref } from '@vue/reactivity'
import {
ActiveViewInj,
IsFormInj,
@ -239,13 +238,8 @@ async function removeAllColumns() {
for (const col of (localColumns as Record<string, any>)?.value) {
if (!shouldSkipColumn(col)) col.show = false
}
// // const FOO = (localColumns as Ref<Record<string, any>[]>)?.value
// const FOO = localColumns?.value
// .filter((col: Record<string, any>) => shouldSkipColumn(col))
// .map((col: Record<string, any>) => col.fk_column_id)
await hideAll(
localColumns?.value
(localColumns as Record<string, any>)?.value
.filter((col: Record<string, any>) => shouldSkipColumn(col))
.map((col: Record<string, any>) => col.fk_column_id),
)

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

@ -111,7 +111,6 @@ const isRowEmpty = (record: any, col: any) => {
}
reloadViewDataHook?.on(async () => {
// alert('reloadViewDataHook')
await loadKanbanMeta()
await loadKanbanData()
})
@ -132,7 +131,6 @@ const attachments = (record: any): Attachment[] => {
const reloadAttachments = ref(false)
reloadViewMetaHook?.on(async () => {
// alert('reloadViewMetaHook')
await loadKanbanMeta()
reloadAttachments.value = true

2
packages/nc-gui/components/smartsheet/Map.vue

@ -155,12 +155,10 @@ onMounted(async () => {
})
reloadViewMetaHook?.on(async () => {
// alert('reloadViewMetaHook')
await loadMapMeta()
})
reloadViewDataHook?.on(async () => {
// alert('reloadViewDataHook')
await loadMapData()
})

30
packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue

@ -52,45 +52,15 @@ const {
const { eventBus } = useSmartsheetStoreOrThrow()
eventBus.on((event) => {
// alert('eventBus.on in FieldsMenu')
if (event === SmartsheetStoreEvents.FIELD_RELOAD) {
// alert('SmartsheetStoreEvents.FIELD_RELOAD')
loadViewColumns()
}
else if (event === SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE) {
alert('SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE')
// loadViewColumns()
}
})
// watch(
// () => meta.value,
// (v) => {
// alert('watch(meta.value, (v) => {')
// if (v) {
// loadViewColumns()
// }
// },
// )
// watch(
// () => activeView.value,
// async (newVal, oldVal) => {
// if (newVal !== oldVal && meta.value) {
// alert('FOO')
// await loadViewColumns()
// }
// },
// { immediate: true },
// )
watch(
sortedAndFilteredFields,
(v) => {
// alert('watch(sortedAndFilteredFields, (v) => {')
if (rootFields) rootFields.value = v || []
},
{ immediate: true },

30
packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue

@ -28,34 +28,6 @@ const { loadMapData, loadMapMeta, updateMapMeta, mapMetaData, geoDataFieldColumn
const mappedByDropdown = ref(false)
const { eventBus } = useSmartsheetStoreOrThrow()
// const reloadDataHook = inject(ReloadViewDataHookInj)!
// const reloadViewMetaHook = inject(ReloadViewMetaHookInj, undefined)!
// const rootFields = inject(FieldsInj)
// const isLocked = inject(IsLockedInj, ref(false))
// const isPublic = inject(IsPublicInj, ref(false))
// const { $api, $e } = useNuxtApp()
// const {
// showSystemFields,
// sortedAndFilteredFields,
// fields,
// filteredFieldList,
// filterQuery,
// showAll,
// hideAll,
// saveOrUpdate,
// metaColumnById,
// loadViewColumns,
// } = useViewColumns(activeView, meta, () => reloadDataHook.trigger())
watch(
() => activeView.value?.id,
async (newVal, oldVal) => {
@ -76,8 +48,6 @@ const geoDataMappingFieldColumnId = computed({
await loadMapMeta()
await loadMapData()
;(activeView.value?.view as MapType).fk_geo_data_col_id = val
await loadViewColumns()
eventBus.emit(SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE)
}
},
})

26
packages/nc-gui/composables/useViewColumns.ts

@ -1,5 +1,5 @@
import { ViewTypes, isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, MapType, TableType, ViewType } from 'nocodb-sdk'
import { isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue'
import { IsPublicInj, computed, inject, ref, useNuxtApp, useProject, useUIPermission, watch } from '#imports'
import type { Field } from '~/lib'
@ -25,7 +25,6 @@ export function useViewColumns(
() => isPublic.value || !isUIAllowed('hideAllColumns') || !isUIAllowed('showAllColumns') || isSharedBase.value,
)
// const isColumnOrFieldViewEssential = (columnOrField: { id?: string }) => {
const isColumnViewEssential = (column: ColumnType) => {
// TODO: delegate this via a cleaner design pattern to map view specific check logic
// (on the other hand, the logic complexity is still very low atm - might be overkill)
@ -71,7 +70,6 @@ export function useViewColumns(
...currentColumnField,
order: currentColumnField.order || order++,
system: isSystemColumn(metaColumnById?.value?.[currentColumnField.fk_column_id!]),
// show: isColumnViewEssential(column) || !!currentColumnField.show,
isViewEssentialField: isColumnViewEssential(column),
}
})
@ -103,39 +101,27 @@ export function useViewColumns(
reloadData?.()
$e('a:fields:show-all')
}
const hideAll = async (ignoreIds?: any[]) => {
console.info('isLocalMode.value', isLocalMode.value)
const viewEssentialColumnIds = fields.value
?.filter((field: Field) => field.isViewEssentialField)
?.map((field: Field) => field.fk_column_id)
console.info('viewEssentialColumnIds', viewEssentialColumnIds)
const mergedIgnoreIds = [...(viewEssentialColumnIds || []), ...(ignoreIds || [])]
console.info('mergedIgnoreIds', mergedIgnoreIds)
const hideAll = async (ignoreIds?: any) => {
if (isLocalMode.value) {
fields.value = fields.value?.map((field: Field) => ({
...field,
// show: false,
show: !!field.isViewEssentialField,
}))
console.info('fields.value', fields.value)
reloadData?.()
return
}
if (view?.value?.id) {
if (mergedIgnoreIds) {
console.info('API call with ignoreIds', mergedIgnoreIds)
if (ignoreIds) {
await $api.dbView.hideAllColumn(view.value.id, {
ignoreIds: mergedIgnoreIds,
ignoreIds,
})
} else {
await $api.dbView.hideAllColumn(view.value.id)
}
console.info('fields.value AFTER API CALL for hideAllColumn', fields.value)
}
await loadViewColumns()
console.info('fields.value AFTER loadViewColumns', fields.value)
reloadData?.()
$e('a:fields:show-all')
}

1
packages/nc-gui/lib/enums.ts

@ -87,7 +87,6 @@ export enum SmartsheetStoreEvents {
FILTER_RELOAD = 'filter-reload',
DATA_RELOAD = 'data-reload',
FIELD_RELOAD = 'field-reload',
MAPPED_BY_COLUMN_CHANGE = 'mapped-by-column-change',
FIELD_ADD = 'field-add',
}

25
packages/nocodb/src/lib/models/View.ts

@ -17,6 +17,7 @@ import Filter from './Filter';
import {
ColumnReqType,
isSystemColumn,
MapType,
UITypes,
ViewType,
ViewTypes,
@ -433,9 +434,7 @@ export default class View implements ViewType {
} else {
show = false;
}
}
else if (view.type === ViewTypes.KANBAN && !copyFromView) {
} else if (view.type === ViewTypes.KANBAN && !copyFromView) {
const kanbanView = await KanbanView.get(view_id, ncMeta);
if (vCol.id === kanbanView?.fk_grp_col_id) {
// include grouping field if it exists
@ -452,9 +451,7 @@ export default class View implements ViewType {
// other columns will be hidden
show = false;
}
}
else if (view.type === ViewTypes.MAP && !copyFromView) {
} else if (view.type === ViewTypes.MAP && !copyFromView) {
const mapView = await MapView.get(view_id, ncMeta);
if (vCol.id === mapView?.fk_geo_data_col_id) {
show = true;
@ -1167,9 +1164,21 @@ export default class View implements ViewType {
const scope = this.extractViewColumnsTableNameScope(view);
// get existing cache
const dataList = await NocoCache.getList(scope, [viewId]);
// (view.type !== ViewTypes.MAP || (view as MapType).fk_geo_data_col_id === o
const mergedIgnoreColdIds = [
...ignoreColdIds,
...(view.type === ViewTypes.MAP
? [(view as MapType).fk_geo_data_col_id]
: []),
];
if (dataList?.length) {
for (const o of dataList) {
if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) {
if (
!mergedIgnoreColdIds?.length ||
!mergedIgnoreColdIds.includes(o.fk_column_id)
) {
// set data
o.show = false;
// set cache
@ -1186,7 +1195,7 @@ export default class View implements ViewType {
{
fk_view_id: viewId,
},
ignoreColdIds?.length
mergedIgnoreColdIds?.length
? {
_not: {
fk_column_id: {

Loading…
Cancel
Save