Browse Source

feat(nc-gui): persist add new record mode (grid/form) in local storage (#8992)

pull/8995/head
Ramesh Mane 4 months ago committed by GitHub
parent
commit
b1cf9a5456
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      packages/nc-gui/components/smartsheet/grid/Table.vue
  2. 5
      packages/nc-gui/composables/useGlobal/actions.ts
  3. 1
      packages/nc-gui/composables/useGlobal/state.ts
  4. 2
      packages/nc-gui/composables/useGlobal/types.ts

8
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -109,7 +109,7 @@ const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook())
const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook()) const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook())
const { isMobileMode } = useGlobal() const { isMobileMode, isAddNewRecordGridMode, setAddNewRecordGridMode } = useGlobal()
const scrollParent = inject(ScrollParentInj, ref<undefined>()) const scrollParent = inject(ScrollParentInj, ref<undefined>())
@ -196,8 +196,6 @@ const preloadColumn = ref<any>()
const scrolling = ref(false) const scrolling = ref(false)
const isAddNewRecordGridMode = ref(true)
const switchingTab = ref(false) const switchingTab = ref(false)
const isView = false const isView = false
@ -493,12 +491,12 @@ const onDraftRecordClick = () => {
} }
const onNewRecordToGridClick = () => { const onNewRecordToGridClick = () => {
isAddNewRecordGridMode.value = true setAddNewRecordGridMode(true)
addEmptyRow() addEmptyRow()
} }
const onNewRecordToFormClick = () => { const onNewRecordToFormClick = () => {
isAddNewRecordGridMode.value = false setAddNewRecordGridMode(false)
onDraftRecordClick() onDraftRecordClick()
} }

5
packages/nc-gui/composables/useGlobal/actions.ts

@ -167,6 +167,10 @@ export function useGlobalActions(state: State): Actions {
} }
} }
const setAddNewRecordGridMode = (isGridMode: boolean) => {
state.isAddNewRecordGridMode.value = isGridMode
}
return { return {
signIn, signIn,
signOut, signOut,
@ -179,5 +183,6 @@ export function useGlobalActions(state: State): Actions {
getMainUrl, getMainUrl,
setGridViewPageSize, setGridViewPageSize,
setLeftSidebarSize, setLeftSidebarSize,
setAddNewRecordGridMode,
} }
} }

1
packages/nc-gui/composables/useGlobal/state.ts

@ -62,6 +62,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
old: INITIAL_LEFT_SIDEBAR_WIDTH, old: INITIAL_LEFT_SIDEBAR_WIDTH,
current: INITIAL_LEFT_SIDEBAR_WIDTH, current: INITIAL_LEFT_SIDEBAR_WIDTH,
}, },
isAddNewRecordGridMode: true,
} }
/** saves a reactive state, any change to these values will write/delete to localStorage */ /** saves a reactive state, any change to these values will write/delete to localStorage */

2
packages/nc-gui/composables/useGlobal/types.ts

@ -57,6 +57,7 @@ export interface StoredState {
old: number old: number
current: number current: number
} }
isAddNewRecordGridMode: boolean
} }
export type State = ToRefs<Omit<StoredState, 'token'>> & { export type State = ToRefs<Omit<StoredState, 'token'>> & {
@ -94,6 +95,7 @@ export interface Actions {
getMainUrl: (workspaceId: string) => string | undefined getMainUrl: (workspaceId: string) => string | undefined
setGridViewPageSize: (pageSize: number) => void setGridViewPageSize: (pageSize: number) => void
setLeftSidebarSize: (params: { old?: number; current?: number }) => void setLeftSidebarSize: (params: { old?: number; current?: number }) => void
setAddNewRecordGridMode: (isGridMode: boolean) => void
} }
export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'> export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'>

Loading…
Cancel
Save