Browse Source

refactor(gui): code cleanup

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4861/head
Pranav C 2 years ago
parent
commit
eadbdab289
  1. 6
      packages/nc-gui/components/smartsheet/Gallery.vue
  2. 5
      packages/nc-gui/components/smartsheet/Grid.vue
  3. 4
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  4. 7
      packages/nc-gui/composables/useViewData.ts
  5. 5
      packages/nc-gui/lib/enums.ts

6
packages/nc-gui/components/smartsheet/Gallery.vue

@ -8,12 +8,12 @@ import {
IsGalleryInj, IsGalleryInj,
IsGridInj, IsGridInj,
MetaInj, MetaInj,
NavigateDir,
OpenNewRecordFormHookInj, OpenNewRecordFormHookInj,
PaginationDataInj, PaginationDataInj,
ReloadRowDataHookInj, ReloadRowDataHookInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
ReloadViewMetaHookInj, ReloadViewMetaHookInj,
RowNavDir,
computed, computed,
createEventHook, createEventHook,
extractPkFromRow, extractPkFromRow,
@ -273,8 +273,8 @@ watch(view, async (nextView) => {
:row-id="route.query.rowId" :row-id="route.query.rowId"
:view="view" :view="view"
show-next-prev-icons show-next-prev-icons
@next="navigateToSiblingRow(RowNavDir.NEXT)" @next="navigateToSiblingRow(NavigateDir.NEXT)"
@prev="navigateToSiblingRow(RowNavDir.PREV)" @prev="navigateToSiblingRow(NavigateDir.PREV)"
/> />
</Suspense> </Suspense>
</div> </div>

5
packages/nc-gui/components/smartsheet/Grid.vue

@ -17,7 +17,6 @@ import {
ReadonlyInj, ReadonlyInj,
ReloadRowDataHookInj, ReloadRowDataHookInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
RowNavDir,
SmartsheetStoreEvents, SmartsheetStoreEvents,
computed, computed,
createEventHook, createEventHook,
@ -921,8 +920,8 @@ const closeAddColumnDropdown = () => {
:row-id="routeQuery.rowId" :row-id="routeQuery.rowId"
:view="view" :view="view"
show-next-prev-icons show-next-prev-icons
@next="navigateToSiblingRow(RowNavDir.NEXT)" @next="navigateToSiblingRow(NavigateDir.NEXT)"
@prev="navigateToSiblingRow(RowNavDir.PREV)" @prev="navigateToSiblingRow(NavigateDir.PREV)"
/> />
</Suspense> </Suspense>
</div> </div>

4
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -192,7 +192,7 @@ defineExpose({
@click.stop @click.stop
@change="filterUpdateCondition(filter, i)" @change="filterUpdateCondition(filter, i)"
> >
<a-select-option v-for="op in logicalOps" :key="op.value" :value="op.value"> <a-select-option v-for="op of logicalOps" :key="op.value" :value="op.value">
{{ op.text }} {{ op.text }}
</a-select-option> </a-select-option>
</a-select> </a-select>
@ -219,7 +219,7 @@ defineExpose({
dropdown-class-name="nc-dropdown-filter-comp-op" dropdown-class-name="nc-dropdown-filter-comp-op"
@change="filterUpdateCondition(filter, i)" @change="filterUpdateCondition(filter, i)"
> >
<template v-for="compOp in comparisonOpList" :key="compOp.value"> <template v-for="compOp of comparisonOpList" :key="compOp.value">
<a-select-option v-if="isComparisonOpAllowed(filter, compOp)" :value="compOp.value"> <a-select-option v-if="isComparisonOpAllowed(filter, compOp)" :value="compOp.value">
{{ compOp.text }} {{ compOp.text }}
</a-select-option> </a-select-option>

7
packages/nc-gui/composables/useViewData.ts

@ -4,7 +4,7 @@ import type { ComputedRef, Ref } from 'vue'
import { import {
IsPublicInj, IsPublicInj,
NOCO, NOCO,
RowNavDir, NavigateDir,
computed, computed,
extractPkFromRow, extractPkFromRow,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
@ -478,14 +478,14 @@ export function useViewData(
} }
} }
const navigateToSiblingRow = async (dir: RowNavDir) => { const navigateToSiblingRow = async (dir: NavigateDir) => {
// get current expanded row index // get current expanded row index
const expandedRowIndex = formattedData.value.findIndex( const expandedRowIndex = formattedData.value.findIndex(
(row: Row) => routeQuery.rowId === extractPkFromRow(row.row, meta.value?.columns as ColumnType[]), (row: Row) => routeQuery.rowId === extractPkFromRow(row.row, meta.value?.columns as ColumnType[]),
) )
// calculate next row index based on direction // calculate next row index based on direction
let siblingRowIndex = expandedRowIndex + (dir === RowNavDir.NEXT ? 1 : -1) let siblingRowIndex = expandedRowIndex + (dir === NavigateDir.NEXT ? 1 : -1)
const currentPage = paginationData?.value?.page || 1 const currentPage = paginationData?.value?.page || 1
@ -500,7 +500,6 @@ export function useViewData(
// if next row index is greater than total rows in current view // if next row index is greater than total rows in current view
// then load next page of formattedData and set next row index to 0 // then load next page of formattedData and set next row index to 0
} else if (siblingRowIndex >= formattedData.value.length) { } else if (siblingRowIndex >= formattedData.value.length) {
console.log(paginationData?.value)
if (paginationData?.value?.isLastPage) return message.info(t('msg.info.noMoreRecords')) if (paginationData?.value?.isLastPage) return message.info(t('msg.info.noMoreRecords'))
await changePage(currentPage + 1) await changePage(currentPage + 1)

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

@ -98,8 +98,3 @@ export enum DataSourcesSubTab {
Misc = 'Misc', Misc = 'Misc',
Edit = 'Edit', Edit = 'Edit',
} }
export enum RowNavDir {
NEXT,
PREV,
}

Loading…
Cancel
Save