From 832362ba7c2120751a424af38214cd2bb9873172 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 11 Aug 2022 17:07:15 +0530 Subject: [PATCH 1/5] feat(gui-v2): add preview as option Signed-off-by: Pranav C --- packages/nc-gui-v2/components.d.ts | 1 + packages/nc-gui-v2/components/PreviewAs.vue | 93 +++++++++++++++++++ .../composables/useApi/interceptors.ts | 4 +- .../nc-gui-v2/composables/useGlobal/state.ts | 1 + .../nc-gui-v2/composables/useGlobal/types.ts | 1 + .../composables/useUIPermission/index.ts | 15 ++- .../nc-gui-v2/pages/nc/[projectId]/index.vue | 4 +- 7 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 packages/nc-gui-v2/components/PreviewAs.vue diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index 7fd5ee4556..5b5095a947 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -95,6 +95,7 @@ declare module '@vue/runtime-core' { MdiDrag: typeof import('~icons/mdi/drag')['default'] MdiDragVertical: typeof import('~icons/mdi/drag-vertical')['default'] MdiEmail: typeof import('~icons/mdi/email')['default'] + MdiExitToApp: typeof import('~icons/mdi/exit-to-app')['default'] MdiEyeOffOutline: typeof import('~icons/mdi/eye-off-outline')['default'] MdiFlag: typeof import('~icons/mdi/flag')['default'] MdiFolder: typeof import('~icons/mdi/folder')['default'] diff --git a/packages/nc-gui-v2/components/PreviewAs.vue b/packages/nc-gui-v2/components/PreviewAs.vue new file mode 100644 index 0000000000..d151bd948f --- /dev/null +++ b/packages/nc-gui-v2/components/PreviewAs.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/packages/nc-gui-v2/composables/useApi/interceptors.ts b/packages/nc-gui-v2/composables/useApi/interceptors.ts index e5a4882947..c8c6fd1fa6 100644 --- a/packages/nc-gui-v2/composables/useApi/interceptors.ts +++ b/packages/nc-gui-v2/composables/useApi/interceptors.ts @@ -13,8 +13,8 @@ export function addAxiosInterceptors(api: Api) { if (state.token.value) config.headers['xc-auth'] = state.token.value - if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles')) { - // config.headers['xc-preview'] = store.state.users.previewAs + if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles') && state.previewAs?.value) { + config.headers['xc-preview'] = state.previewAs.value } if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles')) { diff --git a/packages/nc-gui-v2/composables/useGlobal/state.ts b/packages/nc-gui-v2/composables/useGlobal/state.ts index fdc8c4da9a..c61b3829cf 100644 --- a/packages/nc-gui-v2/composables/useGlobal/state.ts +++ b/packages/nc-gui-v2/composables/useGlobal/state.ts @@ -57,6 +57,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State { isHidden: false, }, filterAutoSave: true, + previewAs: null, } /** saves a reactive state, any change to these values will write/delete to localStorage */ diff --git a/packages/nc-gui-v2/composables/useGlobal/types.ts b/packages/nc-gui-v2/composables/useGlobal/types.ts index 7f9e54f94e..82ab8b8ed5 100644 --- a/packages/nc-gui-v2/composables/useGlobal/types.ts +++ b/packages/nc-gui-v2/composables/useGlobal/types.ts @@ -22,6 +22,7 @@ export interface StoredState { darkMode: boolean feedbackForm: FeedbackForm filterAutoSave: boolean + previewAs: string | null } export type State = ToRefs> & { diff --git a/packages/nc-gui-v2/composables/useUIPermission/index.ts b/packages/nc-gui-v2/composables/useUIPermission/index.ts index 460664e998..62ff91f05e 100644 --- a/packages/nc-gui-v2/composables/useUIPermission/index.ts +++ b/packages/nc-gui-v2/composables/useUIPermission/index.ts @@ -7,7 +7,7 @@ export function useUIPermission() { const { $state } = useNuxtApp() const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) - const isUIAllowed = (permission: Permission, _skipPreviewAs = false) => { + const isUIAllowed = (permission: Permission, skipPreviewAs = false) => { const user = $state.user let userRoles = user?.value?.roles || {} // if string populate key-value paired object @@ -19,17 +19,16 @@ export function useUIPermission() { } // merge user role and project specific user roles - const roles = { + let roles = { ...userRoles, ...(projectRoles?.value || {}), } - // todo: handle preview as - // if (state.previewAs && !skipPreviewAs) { - // roles = { - // [state.previewAs]: true - // }; - // } + if ($state.previewAs.value && !skipPreviewAs) { + roles = { + [$state.previewAs.value]: true, + } + } return Object.entries(roles).some(([role, hasRole]) => { const rolePermission = rolePermissions[role as keyof typeof rolePermissions] as '*' | Record diff --git a/packages/nc-gui-v2/pages/nc/[projectId]/index.vue b/packages/nc-gui-v2/pages/nc/[projectId]/index.vue index aed18c85ed..a7104621fd 100644 --- a/packages/nc-gui-v2/pages/nc/[projectId]/index.vue +++ b/packages/nc-gui-v2/pages/nc/[projectId]/index.vue @@ -177,7 +177,7 @@ await loadTables() - Foo + @@ -212,6 +212,8 @@ await loadTables() + + From e6b5400b20e425a90a21f6f62e04dc7da93aea66 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 11 Aug 2022 17:24:09 +0530 Subject: [PATCH 2/5] feat(gui-v2): add reset option in preview as menu Signed-off-by: Pranav C --- packages/nc-gui-v2/components.d.ts | 1 + packages/nc-gui-v2/components/PreviewAs.vue | 42 ++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index 5b5095a947..30099a9572 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -84,6 +84,7 @@ declare module '@vue/runtime-core' { MdiChat: typeof import('~icons/mdi/chat')['default'] MdiCheck: typeof import('~icons/mdi/check')['default'] MdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] + MdiClose: typeof import('~icons/mdi/close')['default'] MdiCloseCircle: typeof import('~icons/mdi/close-circle')['default'] MdiCloseThick: typeof import('~icons/mdi/close-thick')['default'] MdiContentCopy: typeof import('~icons/mdi/content-copy')['default'] diff --git a/packages/nc-gui-v2/components/PreviewAs.vue b/packages/nc-gui-v2/components/PreviewAs.vue index d151bd948f..2fd51d7048 100644 --- a/packages/nc-gui-v2/components/PreviewAs.vue +++ b/packages/nc-gui-v2/components/PreviewAs.vue @@ -1,6 +1,7 @@ + + @@ -79,15 +95,15 @@ watch(previewAs, () => window.location.reload()) From f0a345a80739898632976c0c0a9a621be7cdbeb8 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 11 Aug 2022 17:28:29 +0530 Subject: [PATCH 3/5] fix(gui-v2): show preview as only if it is not-null Signed-off-by: Pranav C --- .../nc-gui-v2/components/{ => general}/PreviewAs.vue | 9 +++++++-- packages/nc-gui-v2/pages/nc/[projectId]/index.vue | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) rename packages/nc-gui-v2/components/{ => general}/PreviewAs.vue (93%) diff --git a/packages/nc-gui-v2/components/PreviewAs.vue b/packages/nc-gui-v2/components/general/PreviewAs.vue similarity index 93% rename from packages/nc-gui-v2/components/PreviewAs.vue rename to packages/nc-gui-v2/components/general/PreviewAs.vue index 2fd51d7048..9947902841 100644 --- a/packages/nc-gui-v2/components/PreviewAs.vue +++ b/packages/nc-gui-v2/components/general/PreviewAs.vue @@ -48,7 +48,12 @@ watch(previewAs, () => window.location.reload())