Browse Source

feat: save and restore last opened view (#4182)

refactor/ui-updates
Ekaterina Balakina 2 years ago committed by GitHub
parent
commit
48b8c1fc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      packages/nc-gui/components/smartsheet/sidebar/index.vue
  2. 3
      packages/nc-gui/composables/useProject.ts
  3. 5
      scripts/cypress/integration/common/4c_form_view_detailed.js

21
packages/nc-gui/components/smartsheet/sidebar/index.vue

@ -21,8 +21,18 @@ const meta = inject(MetaInj, ref())
const activeView = inject(ActiveViewInj, ref())
const { activeTab } = useTabs()
const { views, loadViews, isLoading } = useViews(meta)
const { lastOpenedViewMap } = useProject()
const setLastOpenedViewId = (viewId?: string) => {
if (viewId && activeTab.value?.id) {
lastOpenedViewMap.value[activeTab.value?.id] = viewId
}
}
const { isUIAllowed } = useUIPermission()
const router = useRouter()
@ -43,10 +53,14 @@ const sidebar = ref()
watch(
[views, () => route.params.viewTitle],
([nextViews, viewTitle]) => {
const lastOpenedViewId = activeTab.value?.id && lastOpenedViewMap.value[activeTab.value?.id]
const lastOpenedView = nextViews.find((v) => v.id === lastOpenedViewId)
if (viewTitle) {
let view = nextViews.find((v) => v.title === viewTitle)
if (view) {
activeView.value = view
setLastOpenedViewId(activeView.value?.id)
} else {
/** search with view id and if found replace with title */
view = nextViews.find((v) => v.id === viewTitle)
@ -58,6 +72,13 @@ watch(
})
}
}
} else if (lastOpenedView) {
/** if active view is not found, set it to last opened view */
router.replace({
params: {
viewTitle: lastOpenedView.title,
},
})
} else {
if (nextViews?.length && activeView.value !== nextViews[0]) {
activeView.value = nextViews[0]

3
packages/nc-gui/composables/useProject.ts

@ -39,6 +39,8 @@ const [setup, use] = useInjectionState(() => {
const projectMetaInfo = ref<ProjectMetaInfo | undefined>()
const lastOpenedViewMap = ref<Record<string, string>>({})
const projectId = computed(() => route.params.projectId as string)
// todo: refactor path param name and variable name
@ -165,6 +167,7 @@ const [setup, use] = useInjectionState(() => {
projectLoadedHook: projectLoadedHook.on,
reset,
isLoading,
lastOpenedViewMap,
}
}, 'useProject')

5
scripts/cypress/integration/common/4c_form_view_detailed.js

@ -321,9 +321,6 @@ export const genTest = (apiType, dbType) => {
settingsPage.openMenu(settingsPage.APPSTORE);
mainPage.configureSMTP("admin@ex.com", "smtp.ex.com", "8080", "TLS");
// open form view & enable "email me" option
cy.openTableTab("Country", 25);
cy.get(`.nc-view-item.nc-${viewType}-view-item`)
.contains("Form-1")
.click();
@ -335,8 +332,6 @@ export const genTest = (apiType, dbType) => {
settingsPage.openMenu(settingsPage.APPSTORE);
mainPage.resetSMTP();
cy.openTableTab("Country", 25);
});
it(`Validate ${viewType}: Add/ remove field verification"`, () => {

Loading…
Cancel
Save