Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions components/Datasets/DescribeDataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
:warning-text="getFirstWarning('tags')"
/>
<div class="flex items-center gap-4 mt-2 mb-3">
<Tooltip v-if="!canGenerateTags && form.tags.length >= MAX_TAGS_NB">
<Tooltip v-if="tagsSuggestionDisabledMessage">
<BrandedButton
type="button"
color="primary"
Expand All @@ -384,7 +384,7 @@
{{ $t('Suggérer des mots clés') }}
</BrandedButton>
<template #tooltip>
{{ $t('Vous avez déjà {count} mots-clés. Le maximum recommandé est de {max}.', { count: form.tags.length, max: MAX_TAGS_NB }) }}
{{ tagsSuggestionDisabledMessage }}
</template>
</Tooltip>
<BrandedButton
Expand All @@ -393,7 +393,6 @@
color="primary"
:icon="RiSparklingLine"
:loading="isGeneratingTags"
:disabled="!canGenerateTags"
@click="handleAutoCompleteTags(MAX_TAGS_NB)"
>
<template v-if="isGeneratingTags">
Expand Down Expand Up @@ -760,6 +759,7 @@ import AccordionGroup from '~/components/Accordion/AccordionGroup.global.vue'
import ToggleSwitch from '~/components/Form/ToggleSwitch.vue'
import ProducerSelect from '~/components/ProducerSelect.vue'
import SearchableSelect from '~/components/SearchableSelect.vue'
import { humanJoin } from '~/utils/helpers'
import type { DatasetForm, EnrichedLicense, SpatialGranularity, SpatialZone, Tag } from '~/types/types'

const datasetForm = defineModel<DatasetForm>({ required: true })
Expand Down Expand Up @@ -882,17 +882,30 @@ const accordionState = (key: keyof typeof form.value) => {
return 'default'
}

const hasTitle = computed(() => form.value.title && form.value.title.trim().length > 0)
const hasDescription = computed(() => form.value.description && form.value.description.trim().length > 0)
const hasEnoughDescription = computed(() => form.value.description && form.value.description.length >= DESCRIPTION_MIN_LENGTH)
const hasLessThanMaxTags = computed(() => form.value.tags.length < MAX_TAGS_NB)

const canGenerateDescriptionShort = computed(() => {
const hasTitle = form.value.title && form.value.title.trim().length > 0
const hasEnoughDescription = form.value.description && form.value.description.length >= DESCRIPTION_MIN_LENGTH
return hasTitle && hasEnoughDescription
return hasTitle.value && hasEnoughDescription.value
})

const canGenerateTags = computed(() => {
const hasTitle = form.value.title && form.value.title.trim().length > 0
const hasDescription = form.value.description && form.value.description.trim().length > 0
const hasLessThanMaxTags = form.value.tags.length < MAX_TAGS_NB
return hasTitle && hasDescription && hasLessThanMaxTags
const tagsSuggestionDisabledMessage = computed(() => {
if (!hasLessThanMaxTags.value) {
return t('Vous avez déjà {count} mots-clés. Le maximum recommandé est de {max}.', { count: form.value.tags.length, max: MAX_TAGS_NB })
}
const missing = []
if (!hasTitle.value) {
missing.push(t('le titre'))
}
if (!hasDescription.value) {
missing.push(t('la description'))
}
if (missing.length > 0) {
return t('Remplissez {fields} pour utiliser cette fonctionnalité.', { fields: humanJoin(missing) })
}
return ''
})

async function handleAutoCompleteDescriptionShort() {
Expand Down
Loading