多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.3 KiB

5 months ago
<script setup lang="ts">
import { type ColumnType, isVirtualCol } from 'nocodb-sdk'
interface Props {
column: ColumnType
value?: boolean
}
const props = defineProps<Props>()
5 months ago
const { $api } = useNuxtApp()
5 months ago
5 months ago
const { getMeta } = useMetas()
const { eventBus } = useSmartsheetStoreOrThrow()
const { fields } = useViewColumnsOrThrow()
5 months ago
const meta = inject(MetaInj, ref())
5 months ago
const searchField = ref('')
5 months ago
const column = toRef(props, 'column')
5 months ago
const value = useVModel(props, 'value')
const selectedField = ref()
const isLoading = ref(false)
const filteredColumns = computed(() => {
const columns = meta.value?.columnsById ?? {}
return (fields.value ?? [])
.filter((f) => !isVirtualCol(columns[f.fk_column_id]))
.filter((c) => c.title.toLowerCase().includes(searchField.value.toLowerCase()))
})
const changeDisplayField = async () => {
isLoading.value = true
try {
await $api.dbTableColumn.primaryColumnSet(selectedField?.value?.fk_column_id as string)
await getMeta(meta?.value?.id as string, true)
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD)
value.value = false
} catch (e) {
console.error(e)
} finally {
isLoading.value = false
}
}
5 months ago
const getIcon = (c: ColumnType) =>
h(isVirtualCol(c) ? resolveComponent('SmartsheetHeaderVirtualCellIcon') : resolveComponent('SmartsheetHeaderCellIcon'), {
columnMeta: c,
})
5 months ago
onMounted(() => {
searchField.value = ''
selectedField.value = fields.value?.find((f) => f.fk_column_id === column.value.id)
})
5 months ago
</script>
<template>
<NcModal v-model:visible="value" size="small">
<div class="flex flex-col gap-3">
5 months ago
<div>
<h1 class="text-base text-gray-800 font-semibold">{{ $t('labels.searchDisplayValue') }}</h1>
<div class="text-gray-600 flex items-center gap-1">
5 months ago
{{ $t('labels.selectYourNewTitleFor') }}
<span class="bg-gray-100 inline-flex items-center gap-1 px-1 rounded-md">
5 months ago
<component :is="iconMap.table" />
{{ meta?.title ?? meta?.table_name }}
</span>
</div>
5 months ago
</div>
<div class="flex w-full gap-2 justify-between items-center">
<a-input v-model:value="searchField" class="w-full h-8 flex-1" size="small" :placeholder="$t('placeholder.searchFields')">
<template #prefix>
<component :is="iconMap.search" class="w-4 text-gray-500 h-4" />
</template>
</a-input>
</div>
<div class="border-1 rounded-md h-[250px] nc-scrollbar-md border-gray-200">
5 months ago
<div
v-for="column in filteredColumns"
:key="column.fk_column_id"
:class="{
'bg-gray-100': selectedField === column,
}"
:data-testid="`nc-display-field-update-menu-${column.title}`"
class="px-3 py-1 flex flex-row items-center rounded-md hover:bg-gray-100"
@click.stop="selectedField = column"
>
<div class="flex flex-row items-center w-full cursor-pointer truncate ml-1 py-[5px] pr-2">
<component :is="getIcon(meta.columnsById[column.fk_column_id])" class="!w-3.5 !h-3.5 !text-gray-500" />
<NcTooltip class="flex-1 pl-1 pr-2 truncate" show-on-truncate-only>
<template #title>
{{ column.title }}
</template>
<template #default>{{ column.title }}</template>
</NcTooltip>
</div>
<div class="flex-1" />
<component :is="iconMap.check" v-if="selectedField === column" class="!w-4 !h-4 !text-brand-500" />
</div>
5 months ago
</div>
<div class="flex w-full gap-2 justify-end">
5 months ago
<NcButton type="secondary" size="small" @click="value = false">
5 months ago
{{ $t('general.cancel') }}
</NcButton>
<NcButton
5 months ago
:disabled="!selectedField || selectedField.fk_column_id === column.id"
5 months ago
:loading="isLoading"
size="small"
5 months ago
@click="changeDisplayField"
5 months ago
>
5 months ago
{{ $t('labels.changeDisplayValueField') }}
5 months ago
</NcButton>
</div>
</div>
</NcModal>
</template>
<style scoped lang="scss">
.ant-input::placeholder {
@apply text-gray-500;
}
.ant-input:placeholder-shown {
@apply text-gray-500 !text-md;
}
.ant-input-affix-wrapper {
@apply px-4 rounded-lg py-2 w-84 border-1 focus:border-brand-500 border-gray-200 !ring-0;
}
</style>