From 396c9ef48024bfcaf4ac46ceecb195f08bd1b39c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 20 Jun 2023 18:09:50 +0530 Subject: [PATCH 1/4] fix: decide editable state based on both editEnabled and active Signed-off-by: Pranav C --- packages/nc-gui/components/cell/MultiSelect.vue | 7 ++++++- packages/nc-gui/components/cell/SingleSelect.vue | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 6c00425d9f..03491ab4e7 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -27,6 +27,7 @@ import { useRoles, useSelectedCellKeyupListener, watch, + EditModeInj } from '#imports' import MdiCloseCircle from '~icons/mdi/close-circle' @@ -92,9 +93,13 @@ const isOptionMissing = computed(() => { return (options.value ?? []).every((op) => op.title !== searchVal.value) }) +const isEditable = inject(EditModeInj, ref(false)) + const hasEditRoles = computed(() => hasRole('owner', true) || hasRole('creator', true) || hasRole('editor', true)) -const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && active.value) +// use both active or edit mode to determine if edit is allowed +// since active will be false in case of form view +const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value || isEditable.value)) const vModel = computed({ get: () => { diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index 9ff6ed341e..6b599e3903 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -23,6 +23,7 @@ import { useRoles, useSelectedCellKeyupListener, watch, + EditModeInj } from '#imports' interface Props { @@ -51,6 +52,8 @@ const isPublic = inject(IsPublicInj, ref(false)) const isForm = inject(IsFormInj, ref(false)) +const isEditable = inject(EditModeInj, ref(false)) + const { $api } = useNuxtApp() const searchVal = ref() @@ -89,7 +92,9 @@ const isOptionMissing = computed(() => { const hasEditRoles = computed(() => hasRole('owner', true) || hasRole('creator', true) || hasRole('editor', true)) -const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && active.value) +// use both active or edit mode to determine if edit is allowed +// since active will be false in case of form view +const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value || isEditable.value)) const vModel = computed({ get: () => tempSelectedOptState.value ?? modelValue, From c269218857fa7da897da6413f03e627760eed569 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 20 Jun 2023 18:21:35 +0530 Subject: [PATCH 2/4] fix: decide active state based on both editEnabled and active Signed-off-by: Pranav C --- packages/nc-gui/components/cell/MultiSelect.vue | 14 ++++++++------ packages/nc-gui/components/cell/SingleSelect.vue | 16 +++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 03491ab4e7..e6f8570d68 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -46,7 +46,13 @@ const column = inject(ColumnInj)! const readOnly = inject(ReadonlyInj)! -const active = inject(ActiveCellInj, ref(false)) +const isEditable = inject(EditModeInj, ref(false)) + +const _active = inject(ActiveCellInj, ref(false)) + +// use both ActiveCellInj or EditModeInj to determine the active state +// since active will be false in case of form view +const active = computed(() => _active.value || isEditable.value) const isPublic = inject(IsPublicInj, ref(false)) @@ -93,13 +99,9 @@ const isOptionMissing = computed(() => { return (options.value ?? []).every((op) => op.title !== searchVal.value) }) -const isEditable = inject(EditModeInj, ref(false)) - const hasEditRoles = computed(() => hasRole('owner', true) || hasRole('creator', true) || hasRole('editor', true)) -// use both active or edit mode to determine if edit is allowed -// since active will be false in case of form view -const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value || isEditable.value)) +const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value)) const vModel = computed({ get: () => { diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index 6b599e3903..1086ba0993 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -40,7 +40,13 @@ const column = inject(ColumnInj)! const readOnly = inject(ReadonlyInj)! -const active = inject(ActiveCellInj, ref(false)) +const isEditable = inject(EditModeInj, ref(false)) + +const _active = inject(ActiveCellInj, ref(false)) + +// use both ActiveCellInj or EditModeInj to determine the active state +// since active will be false in case of form view +const active = computed(() => _active.value || isEditable.value) const aselect = ref() @@ -52,8 +58,6 @@ const isPublic = inject(IsPublicInj, ref(false)) const isForm = inject(IsFormInj, ref(false)) -const isEditable = inject(EditModeInj, ref(false)) - const { $api } = useNuxtApp() const searchVal = ref() @@ -92,9 +96,7 @@ const isOptionMissing = computed(() => { const hasEditRoles = computed(() => hasRole('owner', true) || hasRole('creator', true) || hasRole('editor', true)) -// use both active or edit mode to determine if edit is allowed -// since active will be false in case of form view -const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value || isEditable.value)) +const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && (active.value)) const vModel = computed({ get: () => tempSelectedOptState.value ?? modelValue, @@ -255,7 +257,7 @@ const selectedOpt = computed(() => {