π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): nc list dropdown issues
Ramesh Manec0234a9d4bff
diff --git a/packages/nc-gui/components/dlg/Table/Duplicate.vue b/packages/nc-gui/components/dlg/Table/Duplicate.vueindex bc1fde4c7d..c4ca532e7d 100644--- a/packages/nc-gui/components/dlg/Table/Duplicate.vue+++ b/packages/nc-gui/components/dlg/Table/Duplicate.vue@@ -59,26 +59,30 @@ const targetTableMeta = computedAsync(async () => {return getMeta(props.table.id!)})-const canTargetOtherBase = computedAsync(async () => {+const canTargetOtherBase = computed(() => {if (!targetTableMeta.value || (targetTableMeta.value.columns?.length ?? 0) === 0) return falsereturn isEeUI && !targetTableMeta.value.columns?.some((col) => [UITypes.Links, UITypes.LinkToAnotherRecord].includes(col.uidt!))})-const isTargetOtherWsSufficientPlan = computedAsync(async () => {++const isTargetOtherWsSufficientPlan = computed(() => {return getFeature(PlanFeatureTypes.FEATURE_DUPLICATE_TABLE_TO_OTHER_WS)})const workspaceOptions = computed(() => {- if (!isEeUI) return []+ if (!isEeUI || !activeWorkspace) return []if (!isTargetOtherWsSufficientPlan.value) return [activeWorkspace]+return workspacesList.filter((ws) =>[WorkspaceUserRoles.CREATOR, WorkspaceUserRoles.OWNER].includes(ws.roles as WorkspaceUserRoles),)})-const isTargetOtherBaseSufficientPlan = computedAsync(async () => {+const isTargetOtherBaseSufficientPlan = computed(() => {return getFeature(PlanFeatureTypes.FEATURE_DUPLICATE_TABLE_TO_OTHER_BASE)})+const targetBases: Ref<BaseType[]> = ref([])+const refreshTargetBases = async () => {if (!isEeUI || !targetWorkspace.value) {targetBases.value = []@@ -98,6 +102,7 @@ const refreshTargetBases = async () => {) ?? []),)}+const selectWorkspace = async (option: WorkspaceType) => {if (option.id !== targetWorkspace.value?.id) {targetBase.value = null as any@@ -207,12 +212,15 @@ onKeyStroke('Enter', () => {_duplicate()}})+watch(isTargetOtherBaseSufficientPlan, (newValue) => {if (newValue) {refreshTargetBases()}})+const isEaster = ref(false)+onMounted(() => {refreshTargetBases()})@@ -239,28 +247,33 @@ onMounted(() => {</div><div class="mt-5 flex gap-3 flex-col">- <div- class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"- @click="options.includeData = !options.includeData"- >- <NcSwitch :checked="options.includeData" />- {{ $t('labels.includeRecords') }}+ <div class="flex">+ <div+ class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"+ @click="options.includeData = !options.includeData"+ >+ <NcSwitch :checked="options.includeData" />+ {{ $t('labels.includeRecords') }}+ </div></div>- <div- class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"- @click="options.includeViews = !options.includeViews"- >- <NcSwitch :checked="options.includeViews" />- {{ $t('labels.includeView') }}+ <div class="flex">+ <div+ class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"+ @click="options.includeViews = !options.includeViews"+ >+ <NcSwitch :checked="options.includeViews" />+ {{ $t('labels.includeView') }}+ </div></div>- <div- v-show="isEaster"- class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"- @click="options.includeHooks = !options.includeHooks"- >- <NcSwitch :checked="options.includeHooks" />- {{ $t('labels.includeWebhook') }}+ <div v-show="isEaster" class="flex">+ <div+ class="flex gap-3 cursor-pointer leading-5 text-nc-content-gray font-medium items-center"+ @click="options.includeHooks = !options.includeHooks"+ >+ <NcSwitch :checked="options.includeHooks" />+ {{ $t('labels.includeWebhook') }}+ </div></div></div>@@ -274,47 +287,41 @@ onMounted(() => {<template v-if="!canTargetOtherBase" #title><span> This table contains linked records that reference data in the current base. </span></template>- <NcDropdown v-model:visible="wsDropdownOpen" :disabled="!canTargetOtherBase">- <div- class="rounded-lg border-1 transition-all cursor-pointer flex items-center border-nc-border-gray-medium h-8 py-1 gap-2 px-3"- style="box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.08)"- :class="{- '!border-brand-500 !shadow-selected': wsDropdownOpen,- }"- >- <GeneralWorkspaceIcon size="small" :workspace="targetWorkspace!" />-- <div class="flex-1 capitalize truncate">- {{ targetWorkspace?.title }}- </div>+ <NcListDropdown v-model:is-open="wsDropdownOpen" :disabled="!canTargetOtherBase" default-slot-wrapper-class="gap-2">+ <GeneralWorkspaceIcon size="small" :workspace="targetWorkspace!" />- <div class="flex gap-2 items-center">- <div- v-if="activeWorkspace?.id === targetWorkspace?.id"- class="text-nc-content-gray-muted leading-4.5 text-xs"- >- {{ $t('labels.currentWorkspace') }}- </div>- <GeneralIcon- :class="{- 'transform rotate-180': wsDropdownOpen,- }"- class="text-nc-content-gray transition-all w-4 h-4"- icon="ncChevronDown"- />+ <div class="flex-1 capitalize truncate">+ {{ targetWorkspace?.title }}+ </div>++ <div class="flex gap-2 items-center">+ <div v-if="activeWorkspace?.id === targetWorkspace?.id" class="text-nc-content-gray-muted leading-4.5 text-xs">+ {{ $t('labels.currentWorkspace') }}</div>+ <GeneralIcon+ :class="{+ 'transform rotate-180': wsDropdownOpen,+ }"+ class="transition-all w-4 h-4 opacity-80"+ icon="ncChevronDown"+ /></div>- <template #overlay>+ <template #overlay="{ onEsc }"><NcList- :value="targetWorkspace!"- :item-height="28"+ v-model:open="wsDropdownOpen"+ :value="targetWorkspace?.id ?? ''"+ :item-height="32"close-on-selectclass="nc-base-workspace-selection w-full":min-items-for-search="6"container-class-name="w-full":list="workspaceOptions"option-label-key="title"+ option-value-key="id"+ stop-propagation-on-item-click+ @change="(option) => selectWorkspace(option as WorkspaceType)"+ @escape="onEsc"><template #listHeader><div class="text-nc-content-gray-muted text-[13px] px-3 pt-2.5 pb-1.5 font-medium leading-5">@@ -324,33 +331,20 @@ onMounted(() => {<NcDivider /></template>- <template #listItem="{ option: optionItem }">- <div class="flex gap-2 w-full items-center" @click="selectWorkspace(optionItem as WorkspaceType)">- <GeneralWorkspaceIcon :workspace="optionItem as WorkspaceType" size="small" />-- <div class="flex-1 text-[13px] truncate font-semibold leading-5 capitalize w-full">- {{ optionItem.title }}- <div class="flex items-center gap-2">- <div- v-if="activeWorkspace?.id === optionItem.id"- class="text-nc-content-gray-muted leading-4.5 text-xs"- >- {{ $t('labels.currentWorkspace') }}- </div>- <GeneralIcon- v-if="optionItem.id === targetWorkspace?.id"- class="text-brand-500 w-4 h-4"- icon="ncCheck"- />- </div>- </div>+ <template #listItemExtraLeft="{ option: optionItem }">+ <GeneralWorkspaceIcon :workspace="optionItem as WorkspaceType" size="small" />+ </template>+ <template #listItemExtraRight="{ option: optionItem }">+ <div v-if="activeWorkspace?.id === optionItem.id" class="text-nc-content-gray-muted leading-4.5 text-xs">+ {{ $t('labels.currentWorkspace') }}</div></template></NcList></template>- </NcDropdown>+ </NcListDropdown></NcTooltip><LazyPaymentUpgradeBadge+ class="mt-2":feature="PlanFeatureTypes.FEATURE_DUPLICATE_TABLE_TO_OTHER_WS":plan-title="PlanTitles.ENTERPRISE":content="$t('upgrade.upgradeToDuplicateTableToOtherWs')"@@ -376,47 +370,48 @@ onMounted(() => {{{ $t('upgrade.upgradeToDuplicateTableToOtherBase') }}</span></template>- <NcDropdown v-model:visible="baseDropdownOpen" :disabled="!canTargetOtherBase || !isTargetOtherBaseSufficientPlan">- <div- class="rounded-lg border-1 transition-all cursor-pointer flex items-center border-nc-border-gray-medium h-8 py-1 gap-2 px-3"- style="box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.08)"- :class="{- '!border-brand-500 !shadow-selected': baseDropdownOpen,- }"- >- <template v-if="!!targetBase">- <div class="flex-1 capitalize truncate flex gap-1">- <GeneralProjectIcon :color="parseProp(targetBase?.meta ?? {}).iconColor" size="small" />- {{ targetBase?.title }}- </div>- </template>- <template v-else>- <div class="flex-1 capitalize truncate flex gap-1"></div>- </template>- <div class="flex gap-2 items-center">- <div v-if="activeBase?.id === targetBase?.id" class="text-nc-content-gray-muted leading-4.5 text-xs">- {{ $t('labels.currentBase') }}- </div>- <GeneralIcon- :class="{- 'transform rotate-180': baseDropdownOpen,- }"- class="text-nc-content-gray transition-all w-4 h-4"- icon="ncChevronDown"- />+ <NcListDropdown+ v-model:is-open="baseDropdownOpen"+ :disabled="!canTargetOtherBase || !isTargetOtherBaseSufficientPlan"+ default-slot-wrapper-class="gap-2"+ >+ <template v-if="!!targetBase">+ <div class="flex-1 capitalize truncate flex gap-1">+ <GeneralProjectIcon :color="parseProp(targetBase?.meta ?? {}).iconColor" size="small" />+ {{ targetBase?.title }}</div>+ </template>+ <template v-else>+ <div class="flex-1 capitalize truncate flex gap-1"></div>+ </template>+ <div class="flex gap-2 items-center">+ <div v-if="activeBase?.id === targetBase?.id" class="text-nc-content-gray-muted leading-4.5 text-xs">+ {{ $t('labels.currentBase') }}+ </div>+ <GeneralIcon+ :class="{+ 'transform rotate-180': baseDropdownOpen,+ }"+ class="transition-all w-4 h-4 opacity-80"+ icon="ncChevronDown"+ /></div>- <template #overlay>+ <template #overlay="{ onEsc }"><NcList- :value="targetBase!"- :item-height="28"+ v-model:open="baseDropdownOpen"+ :value="targetBase?.id ?? ''"+ :item-height="32"close-on-selectclass="nc-base-workspace-selection":min-items-for-search="6"container-class-name="w-full":list="targetBases"option-label-key="title"+ option-value-key="id"+ stop-propagation-on-item-click+ @change="(option) => selectBase(option as BaseType)"+ @escape="onEsc"><template #listHeader><div class="text-nc-content-gray-muted text-[13px] px-3 pt-2.5 pb-1.5 font-medium leading-5">@@ -426,26 +421,20 @@ onMounted(() => {<NcDivider /></template>- <template #listItem="{ option: optionItem }">- <div class="flex gap-2 w-full items-center" @click="selectBase(optionItem as BaseType)">- <GeneralProjectIcon :color="parseProp(optionItem.meta).iconColor" size="small" />- <div class="flex-1 text-[13px] truncate font-semibold leading-5 capitalize w-full">- {{ optionItem.title }}- </div>-- <div class="flex items-center gap-2">- <div v-if="activeBase?.id === optionItem.id" class="text-nc-content-gray-muted leading-4.5 text-xs">- {{ $t('labels.currentBase') }}- </div>- <GeneralIcon v-if="optionItem.id === targetBase?.id" class="text-brand-500 w-4 h-4" icon="ncCheck" />- </div>+ <template #listItemExtraLeft="{ option: optionItem }">+ <GeneralProjectIcon :color="parseProp(optionItem.meta).iconColor" size="small" />+ </template>+ <template #listItemExtraRight="{ option: optionItem }">+ <div v-if="activeBase?.id === optionItem.id" class="text-nc-content-gray-muted leading-4.5 text-xs">+ {{ $t('labels.currentBase') }}</div></template></NcList></template>- </NcDropdown>+ </NcListDropdown></NcTooltip><LazyPaymentUpgradeBadge+ class="mt-2":feature="PlanFeatureTypes.FEATURE_DUPLICATE_TABLE_TO_OTHER_BASE":content="$t('upgrade.upgradeToDuplicateTableToOtherBase')":on-click-callback="diff --git a/packages/nc-gui/components/nc/List/Dropdown.vue b/packages/nc-gui/components/nc/List/Dropdown.vueindex 5e912c5300..276275ff4b 100644--- a/packages/nc-gui/components/nc/List/Dropdown.vue+++ b/packages/nc-gui/components/nc/List/Dropdown.vue@@ -25,6 +25,8 @@ const props = withDefaults(defineProps<Props>(), {const emits = defineEmits(['update:isOpen'])+const { disabled } = toRefs(props)+// Controlled or uncontrolled pattern:const isControlled = computed(() => props.isOpen !== undefined)@@ -50,20 +52,42 @@ const onEsc = (_e: KeyboardEvent) => {triggerRef.value?.focus()})}++const onEnter = (e: KeyboardEvent) => {+ if (disabled.value || vModelIsOpen.value) return++ e.preventDefault()+ e.stopPropagation()++ vModelIsOpen.value = true+}++/**+ * On close dropdown it's important to focus the trigger element so that tabbing works as expected+ */+watch(vModelIsOpen, (newVal) => {+ if (newVal) return++ nextTick(() => {+ triggerRef.value?.focus()+ })+})</script><template><NcDropdown v-model:visible="vModelIsOpen" :disabled="disabled"><div+ tabindex="0"v-if="defaultSlotWrapper"- class="border-1 rounded-lg h-8 px-3 py-1 flex items-center justify-between transition-all select-none"+ class="nc-list-dropdown-wrapper border-1 rounded-lg h-8 px-3 py-1 flex items-center justify-between transition-all select-none outline-none":class="[defaultSlotWrapperClass,{+ 'cursor-not-allowed bg-nc-bg-gray-extralight text-nc-content-gray-muted': disabled,'cursor-pointer': !disabled,'border-brand-500 shadow-selected': vModelIsOpen && !disabled && !hasError,'border-error shadow-error': vModelIsOpen && !disabled && hasError,- 'shadow-default hover:shadow-hover': !vModelIsOpen && !disabled && !borderOnHover,+ 'nc-list-dropdown-wrapper-default-state': !vModelIsOpen && !disabled && !borderOnHover,'hover:(border-brand-500 shadow-selected)': vModelIsOpen && !disabled && borderOnHover,'hover:(shadow-default hover:shadow-hover)': !vModelIsOpen && !disabled && borderOnHover,'border-transparent hover:(border-nc-gray-medium)': (borderOnHover || vModelIsOpen) && !disabled,@@ -71,6 +95,7 @@ const onEsc = (_e: KeyboardEvent) => {'border-error': !borderOnHover && hasError,},]"+ @keydown.enter.exact="onEnter"><buttonref="triggerRef"@@ -97,3 +122,21 @@ const onEsc = (_e: KeyboardEvent) => {</template></NcDropdown></template>++<style scoped lang="scss">+.nc-list-dropdown-wrapper {+ &.nc-list-dropdown-wrapper-default-state {+ @apply shadow-default;++ &:not(:focus-visible):not(:focus-within):not(:focus) {+ @apply hover:shadow-hover;+ }++ &:focus-visible,+ &:focus-within,+ &:focus {+ @apply border-brand-500 shadow-selected outline-none;+ }+ }+}+</style>diff --git a/packages/nc-gui/components/nc/List/index.vue b/packages/nc-gui/components/nc/List/index.vueindex 483957090d..0b9f1f12b6 100644--- a/packages/nc-gui/components/nc/List/index.vue+++ b/packages/nc-gui/components/nc/List/index.vue@@ -6,7 +6,7 @@ interface Emits {(e: 'update:value', value: RawValueType): void(e: 'update:open', open: boolean): void(e: 'change', option: NcListItemType): void- (e: 'escape', e: KeyboardEvent): void+ (e: 'escape', event: KeyboardEvent): void}const props = withDefaults(defineProps<NcListProps>(), {@@ -334,6 +334,10 @@ watch(searchQuery, () => {defineExpose({list,})++const handleEscape = (event: KeyboardEvent) => {+ emits('escape', event)+}</script><template>@@ -343,8 +347,8 @@ defineExpose({class="flex flex-col nc-list-root pt-2 w-64 !focus:(shadow-none outline-none)"@keydown.arrow-down.prevent="onArrowDown"@keydown.arrow-up.prevent="onArrowUp"- @keydown.enter.prevent="handleSelectOption(list[activeOptionIndex])"- @keydown.esc="emits('escape', $event)"+ @keydown.enter.prevent="handleSelectOption(list[activeOptionIndex], undefined, $event)"+ @keydown.esc="handleEscape($event)"><template v-if="isSearchEnabled"><div