From 27649e904b11c720c0010caa2f4f5b498c41b9d1 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 28 Sep 2022 12:04:04 +0800 Subject: [PATCH] feat(nc-gui): add scrolling logic when new options are added --- .../nc-gui/components/smartsheet/Kanban.vue | 30 ++++++++++++++++++- .../nc-gui/composables/useKanbanViewData.ts | 8 +++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vue index 10543e1569..032a63a11c 100644 --- a/packages/nc-gui/components/smartsheet/Kanban.vue +++ b/packages/nc-gui/components/smartsheet/Kanban.vue @@ -65,6 +65,7 @@ const { countByStack, deleteStack, removeRowFromUncategorizedStack, + shouldScrollToRight, } = useKanbanViewData(meta, view) const { isUIAllowed } = useUIPermission() @@ -72,13 +73,21 @@ const { isUIAllowed } = useUIPermission() const { appInfo } = $(useGlobal()) provide(IsFormInj, ref(false)) + provide(IsGalleryInj, ref(false)) + provide(IsGridInj, ref(false)) + provide(IsKanbanInj, ref(true)) + provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable')) const fields = inject(FieldsInj, ref([])) +const kanbanContainerRef = ref() + +let isMounted = false + const isRowEmpty = (record: any, col: any) => { const val = record.row[col.title] if (!val) return true @@ -221,12 +230,31 @@ onMounted(async () => { await loadKanbanMeta() // load kanban data await loadKanbanData() + // update isMounted for below watcher + isMounted = true }) + +watch( + () => shouldScrollToRight.value, + () => { + // use `isMounted` to avoid scrolling from switching from other views + // i.e. scroll only when a new option is added within kanban view + if (isMounted && shouldScrollToRight.value) { + // horizontally scroll to the end of the kanban container + kanbanContainerRef.value.scrollTo({ + left: kanbanContainerRef.value.scrollWidth, + behavior: 'smooth', + }) + // reset shouldScrollToRight + shouldScrollToRight.value = false + } + }, +)