From 90bfa2dec2223e6c2a8dad7b38b7ca8c17bc282f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 19 Jan 2023 11:44:18 +0530 Subject: [PATCH] feat(gui): improve row navigation option in expanded form - Add tooltip - Show warning if out of bound - Hide option from nested - Implement it in Gallery view Signed-off-by: Pranav C --- .../nc-gui/components/smartsheet/Gallery.vue | 5 ++ .../nc-gui/components/smartsheet/Grid.vue | 51 ++---------------- .../smartsheet/expanded-form/index.vue | 19 +++++-- packages/nc-gui/composables/useSharedView.ts | 12 +---- packages/nc-gui/composables/useViewData.ts | 52 +++++++++++++++++++ packages/nc-gui/lang/en.json | 7 ++- packages/nc-gui/lib/enums.ts | 5 ++ 7 files changed, 89 insertions(+), 62 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vue index cc00c0b43c..dfa2899f6b 100644 --- a/packages/nc-gui/components/smartsheet/Gallery.vue +++ b/packages/nc-gui/components/smartsheet/Gallery.vue @@ -13,6 +13,7 @@ import { ReloadRowDataHookInj, ReloadViewDataHookInj, ReloadViewMetaHookInj, + RowNavDir, computed, createEventHook, extractPkFromRow, @@ -48,6 +49,7 @@ const { galleryData, changePage, addEmptyRow, + navigateToSiblingRow, } = useViewData(meta, view) provide(IsFormInj, ref(false)) @@ -270,6 +272,9 @@ watch(view, async (nextView) => { :meta="meta" :row-id="route.query.rowId" :view="view" + show-next-prev-icons + @next="navigateToSiblingRow(RowNavDir.NEXT)" + @prev="navigateToSiblingRow(RowNavDir.PREV)" /> diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 45bd864ecd..66b33fd6d1 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -17,6 +17,7 @@ import { ReadonlyInj, ReloadRowDataHookInj, ReloadViewDataHookInj, + RowNavDir, SmartsheetStoreEvents, computed, createEventHook, @@ -117,6 +118,7 @@ const { deleteSelectedRows, selectedAllRecords, removeRowIfNew, + navigateToSiblingRow, } = useViewData(meta, view, xWhere) const { getMeta } = useMetas() @@ -638,50 +640,6 @@ const closeAddColumnDropdown = () => { columnOrder.value = null addColumnDropdown.value = false } - -enum NavDir { - NEXT, - PREV, -} - -const navigateToSiblingRow = async (dir: NavDir) => { - // get current expanded row index - const expandedRowIndex = data.value.findIndex( - (row) => routeQuery.rowId === extractPkFromRow(row.row, meta.value?.columns as ColumnType[]), - ) - - // calculate next row index based on direction - let siblingRowIndex = expandedRowIndex + (dir === NavDir.NEXT ? 1 : -1) - - const currentPage = paginationData?.value?.page || 1 - - // if next row index is less than 0, go to previous page and point to last element - if (siblingRowIndex < 0) { - // if first page, do nothing - if (currentPage === 1) return - - await changePage(currentPage - 1) - siblingRowIndex = data.value.length - 1 - - // if next row index is greater than total rows in current view - // then load next page of data and set next row index to 0 - } else if (siblingRowIndex >= data.value.length) { - siblingRowIndex = 0 - await changePage(currentPage + 1) - } - - // extract the row id of the sibling row - const rowId = extractPkFromRow(data.value[siblingRowIndex].row, meta.value?.columns as ColumnType[]) - - if (rowId) { - router.push({ - query: { - ...routeQuery, - rowId, - }, - }) - } -}