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. 10
      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. 27
      packages/nocodb/src/lib/models/View.ts

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

@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import Draggable from 'vuedraggable' import Draggable from 'vuedraggable'
import { RelationTypes, UITypes, ViewTypes, getSystemColumns, isVirtualCol } from 'nocodb-sdk' import { RelationTypes, UITypes, ViewTypes, getSystemColumns, isVirtualCol } from 'nocodb-sdk'
import { Ref } from '@vue/reactivity'
import { import {
ActiveViewInj, ActiveViewInj,
IsFormInj, IsFormInj,
@ -239,13 +238,8 @@ async function removeAllColumns() {
for (const col of (localColumns as Record<string, any>)?.value) { for (const col of (localColumns as Record<string, any>)?.value) {
if (!shouldSkipColumn(col)) col.show = false 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( await hideAll(
localColumns?.value (localColumns as Record<string, any>)?.value
.filter((col: Record<string, any>) => shouldSkipColumn(col)) .filter((col: Record<string, any>) => shouldSkipColumn(col))
.map((col: Record<string, any>) => col.fk_column_id), .map((col: Record<string, any>) => col.fk_column_id),
) )
@ -833,7 +827,7 @@ watch(view, (nextView) => {
@apply px-4 min-h-[75px] w-full h-full; @apply px-4 min-h-[75px] w-full h-full;
.nc-attachment { .nc-attachment {
@apply md: (w-[50px] h-[50px]) lg:(w-[75px] h-[75px]) min-h-[50px] min-w-[50px]; @apply md:(w-[50px] h-[50px]) lg:(w-[75px] h-[75px]) min-h-[50px] min-w-[50px];
} }
.nc-attachment-cell-dropzone { .nc-attachment-cell-dropzone {

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

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

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

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

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

@ -52,45 +52,15 @@ const {
const { eventBus } = useSmartsheetStoreOrThrow() const { eventBus } = useSmartsheetStoreOrThrow()
eventBus.on((event) => { eventBus.on((event) => {
// alert('eventBus.on in FieldsMenu')
if (event === SmartsheetStoreEvents.FIELD_RELOAD) { if (event === SmartsheetStoreEvents.FIELD_RELOAD) {
// alert('SmartsheetStoreEvents.FIELD_RELOAD')
loadViewColumns() 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( watch(
sortedAndFilteredFields, sortedAndFilteredFields,
(v) => { (v) => {
// alert('watch(sortedAndFilteredFields, (v) => {')
if (rootFields) rootFields.value = v || [] if (rootFields) rootFields.value = v || []
}, },
{ immediate: true }, { 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 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( watch(
() => activeView.value?.id, () => activeView.value?.id,
async (newVal, oldVal) => { async (newVal, oldVal) => {
@ -76,8 +48,6 @@ const geoDataMappingFieldColumnId = computed({
await loadMapMeta() await loadMapMeta()
await loadMapData() await loadMapData()
;(activeView.value?.view as MapType).fk_geo_data_col_id = val ;(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 { isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, MapType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { IsPublicInj, computed, inject, ref, useNuxtApp, useProject, useUIPermission, watch } from '#imports' import { IsPublicInj, computed, inject, ref, useNuxtApp, useProject, useUIPermission, watch } from '#imports'
import type { Field } from '~/lib' import type { Field } from '~/lib'
@ -25,7 +25,6 @@ export function useViewColumns(
() => isPublic.value || !isUIAllowed('hideAllColumns') || !isUIAllowed('showAllColumns') || isSharedBase.value, () => isPublic.value || !isUIAllowed('hideAllColumns') || !isUIAllowed('showAllColumns') || isSharedBase.value,
) )
// const isColumnOrFieldViewEssential = (columnOrField: { id?: string }) => {
const isColumnViewEssential = (column: ColumnType) => { const isColumnViewEssential = (column: ColumnType) => {
// TODO: delegate this via a cleaner design pattern to map view specific check logic // 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) // (on the other hand, the logic complexity is still very low atm - might be overkill)
@ -71,7 +70,6 @@ export function useViewColumns(
...currentColumnField, ...currentColumnField,
order: currentColumnField.order || order++, order: currentColumnField.order || order++,
system: isSystemColumn(metaColumnById?.value?.[currentColumnField.fk_column_id!]), system: isSystemColumn(metaColumnById?.value?.[currentColumnField.fk_column_id!]),
// show: isColumnViewEssential(column) || !!currentColumnField.show,
isViewEssentialField: isColumnViewEssential(column), isViewEssentialField: isColumnViewEssential(column),
} }
}) })
@ -103,39 +101,27 @@ export function useViewColumns(
reloadData?.() reloadData?.()
$e('a:fields:show-all') $e('a:fields:show-all')
} }
const hideAll = async (ignoreIds?: any[]) => { 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)
if (isLocalMode.value) { if (isLocalMode.value) {
fields.value = fields.value?.map((field: Field) => ({ fields.value = fields.value?.map((field: Field) => ({
...field, ...field,
// show: false,
show: !!field.isViewEssentialField, show: !!field.isViewEssentialField,
})) }))
console.info('fields.value', fields.value)
reloadData?.() reloadData?.()
return return
} }
if (view?.value?.id) { if (view?.value?.id) {
if (mergedIgnoreIds) { if (ignoreIds) {
console.info('API call with ignoreIds', mergedIgnoreIds)
await $api.dbView.hideAllColumn(view.value.id, { await $api.dbView.hideAllColumn(view.value.id, {
ignoreIds: mergedIgnoreIds, ignoreIds,
}) })
} else { } else {
await $api.dbView.hideAllColumn(view.value.id) await $api.dbView.hideAllColumn(view.value.id)
} }
console.info('fields.value AFTER API CALL for hideAllColumn', fields.value)
} }
await loadViewColumns() await loadViewColumns()
console.info('fields.value AFTER loadViewColumns', fields.value)
reloadData?.() reloadData?.()
$e('a:fields:show-all') $e('a:fields:show-all')
} }

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

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

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

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

Loading…
Cancel
Save