Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add insee multiselect and licence groups #347

Merged
merged 37 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6152fe7
feat: :sparkles: Add Insee codes to publishingform spatial coverage
Jorek57 Jan 24, 2024
87de072
add optgroups to Multiselect
Jorek57 Jan 30, 2024
9a89d86
feat: :sparkles: groups working with description and code
Jorek57 Jan 30, 2024
99c7a18
refactor: :art: improve code readability
Jorek57 Jan 31, 2024
d3d94e3
Revert "refactor: :art: improve code readability"
Jorek57 Jan 31, 2024
826e7e9
fix: revert error commit
Jorek57 Jan 31, 2024
c7029aa
fix: revert error commit
Jorek57 Jan 31, 2024
4c1f5e6
fix: correct minor syntax error
Jorek57 Jan 31, 2024
27443e8
fix: remove console.log
Jorek57 Jan 31, 2024
bcddd82
Merge branch 'master' into feat/add-insee-multiselect
Jorek57 Feb 2, 2024
dee9b95
refac: improve code organization
Jorek57 Feb 2, 2024
85ec3c8
refactor: :art: add types + pass spatialGranularities as a initialOpt…
Jorek57 Feb 5, 2024
3c7c0d1
fix: remove commented code and syntax changes
Jorek57 Feb 19, 2024
048483d
fix: put spatial granularities api call in an api file
Jorek57 Feb 26, 2024
8783f1d
fix: edit syntax
Jorek57 Feb 27, 2024
187251e
fix: corrected previous emrge error
Jorek57 Feb 27, 2024
6e81144
fix: various types fixes
Jorek57 Feb 27, 2024
3234817
fix: edit wrong types + fix granularities call
Jorek57 Feb 27, 2024
bd26e91
Merge branch 'fix/correct-multiselect' into feat/add-insee-multiselect
Jorek57 Feb 27, 2024
0aa2571
fix: remove double placeholder in Multiselect
Jorek57 Feb 27, 2024
10b9bb8
fix: remove duplicate types
Jorek57 Feb 29, 2024
a6954fa
fix: add LocalizedUrl to spatial granularities
Jorek57 Feb 29, 2024
b1a54a4
fix: make description in multiselect optionnal + fix granularitiesUrl
Jorek57 Feb 29, 2024
c3b5c0d
fix: remove console.log
Jorek57 Mar 6, 2024
d0badef
fix: handle LICENSE_GROUPS not defined + correct wrong type in Multis…
Jorek57 Mar 21, 2024
4aaeb8c
fix: another type corrected in Multiselect
Jorek57 Mar 21, 2024
3347537
feat: :lipstick: update optgroup style in Multiselect to match design
Jorek57 Mar 26, 2024
182580b
docs: :memo: add changelog
Jorek57 Mar 26, 2024
7a1cc08
Merge branch 'master' into feat/add-insee-multiselect
Jorek57 Apr 2, 2024
5431e23
fix: fix conflicts
Jorek57 Apr 2, 2024
1939da4
refactor: :art: various types of syntax corrections
Jorek57 Apr 3, 2024
f37a1f0
fix: display description in Spatial coverage
Jorek57 Apr 4, 2024
084c9a8
style: :art: fix indentation in types.ts
Jorek57 Apr 8, 2024
b4ff3c0
Merge branch 'master' into feat/add-insee-multiselect
Jorek57 Apr 8, 2024
fdfd237
fix: :lipstick: edit multiselect css to match design expectations
Jorek57 Apr 8, 2024
ad48f10
fix multiselect line-heights and align
Jorek57 Apr 8, 2024
04ba1d0
fix: correct line-heights in multiselect
Jorek57 Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
:data-description="option.description"
:data-show-icon="option.recommended"
>
{{ option.value }}
{{ option.label }}
</option>
</template>
</select>
Expand Down Expand Up @@ -174,6 +174,14 @@ export default defineComponent({
type: [String, Array],
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
default: null
},
helperDescriptions: {
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
type: [String, String],
default: null
},
onSuggest: {
type: Function,
default: null
}
},
setup(props, { emit }) {
const { t } = useI18n();
Expand Down Expand Up @@ -357,27 +365,51 @@ export default defineComponent({

currentRequest.value = generateCancelToken();
return api
.get(props.suggestUrl, {
.get(props.suggestUrl, {
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
params: { q, size: maxOptionsCount },
cancelToken: currentRequest.value.token,
})
.then((resp) => {
/** @type {Array<Suggestion>} */
const suggestions = resp.data;
})
.then((resp) => {
return props.onSuggest ? props.onSuggest(resp.data) : resp.data;
})
.then((suggestions) => {
const addQToSuggestion = props.addNewOption && !suggestions.some(suggestion => suggestion.text === q);
if(addQToSuggestion) {
suggestions.push({text: q});
if (addQToSuggestion) {
suggestions.push({ text: q });
}
return mapToOption(suggestions);
})
.catch((error) => {
})
.catch((error) => {
if (!axios.isCancel(error)) {
toast.error(t("Error getting {type}.", {type: props.placeholder}));
toast.error(t("Error getting {type}.", { type: props.placeholder }));
}
return /** @type {Array<import("../../types").MultiSelectOption>} */([]);
});
return /** @type {Array<import("../../types").MultiSelectOption>} */ ([]);
});
};

/*const onSuggest = (data) => {
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
const suggestions = data.map(item => {
if (props.helperDescriptions) {
const matchingHelperDescription = props.helperDescriptions.find(helperDescription => helperDescription.id === item.level);
if (matchingHelperDescription) {
return {
...item,
description: matchingHelperDescription.name,
};
} else {
return {
...item,
};
}
} else {
return {
...item
}
}
});
return suggestions;
};*/

const suggestAndMapToOption = (q = '') => suggest(q).then(addAllOptionAndMapToOption);
const suggestMapAndSetOption = (q = '') => suggestAndMapToOption(q).then(setOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
v-else-if="currentStep === 1"
:originalDataset="dataset"
:steps="steps"
:granularities="granularities"
@next="updateDatasetAndMoveToNextStep"
/>
<template v-else-if="currentStep === 2">
Expand Down Expand Up @@ -39,9 +40,10 @@
</div>
</template>
<script>
import { computed, defineComponent, ref, toValue } from 'vue';
import { computed, defineComponent, onMounted, ref, toValue } from 'vue';
import { useI18n } from 'vue-i18n';
import { templateRef, useEventListener } from '@vueuse/core';
import {api} from "../../plugins/api";
import Step1PublishingType from "./Step1PublishingType.vue";
import Step2DescribeDataset from './Step2DescribeDataset.vue';
import Step3AddFiles from './Step3AddFiles.vue';
Expand Down Expand Up @@ -72,6 +74,8 @@ export default defineComponent({

const { files, updateFiles, uploadFiles } = useFilesUpload();

const granularities = ref([]);
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved

const steps = [t("Publish data on {site}", {site: title}), t("Describe your dataset"), t("Add files"), t("Complete your publishing")];

const currentStep = ref(0);
Expand Down Expand Up @@ -167,6 +171,16 @@ export default defineComponent({
}
};

onMounted(() => {
api.get("/spatial/granularities/")
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
.then(resp => {
granularities.value = resp.data;
})
.catch(error => {
console.error("Error fetching granularities:", error);
});
});

/**
*
* @param {import("vue").MaybeRefOrGetter<import("../../types").NewDataset>} updatedDataset
Expand Down Expand Up @@ -282,6 +296,7 @@ export default defineComponent({
editedFile,
errors,
files,
granularities,
loading,
moveToStep,
publishing_form_feedback_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,60 @@ const originalDataset = {
const args = {
originalDataset,
steps: Stepper.StepperOnSecondStep.args.steps,
granularities: [
{
'id': 'country-group',
'name': 'Groupement de pays'
},
{
'id': 'country',
'name': 'Pays'
},
{
"id": "country-subset",
"name": "Sous-ensemble de pays"
},
{
"id": "fr:region",
"name": "Région française"
},
{
"id": "fr:departement",
"name": "Département français"
},
{
"id": "fr:arrondissement",
"name": "Arrondissement français"
},
{
"id": "fr:commune",
"name": "Commune française"
},
{
"id": "fr:iris",
"name": "Iris (quartiers INSEE)"
},
{
"id": "fr:canton",
"name": "Canton français"
},
{
"id": "fr:collectivite",
"name": "Collectivités d'outre-mer françaises"
},
{
"id": "fr:epci",
"name": "Intercommunalité française (EPCI)"
},
{
"id": "poi",
"name": "Point d'Intérêt"
},
{
"id": "other",
"name": "Autre"
}
]
};

export const Step2 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@
:addAllOption="false"
:multiple="true"
helperLabel="Insee : "
:onSuggest="formatSpatialZones"
/>
</div>
<div class="fr-col-12">
<MultiSelect
:placeholder="$t('Spatial granularity')"
:searchPlaceholder="$t('Search a granularity...')"
listUrl="/spatial/granularities/"
:initialOptions="granularities"
:values="dataset.spatial.granularity"
@change="(value) => dataset.spatial.granularity = value"
:hasWarning="fieldHasWarning('spatial_information')"
Expand Down Expand Up @@ -327,7 +328,7 @@ import Stepper from '../../components/Form/Stepper/Stepper.vue';
import Well from "../../components/Ui/Well/Well.vue";
import useUid from "../../composables/useUid";
import useFunctionalState from '../../composables/form/useFunctionalState';
import editIcon from "svg/illustrations/edit.svg";
import editIcon from "../../../../templates/svg/illustrations/edit.svg";
import { license_groups_options, quality_description_length, title } from "../../config";
import { useI18n } from 'vue-i18n';
import { getLicensesUrl } from '../../api/licenses';
Expand All @@ -345,6 +346,11 @@ export default defineComponent({
steps: {
type: Array,
required: true,
},
granularities: {
/** @type {import("vue").PropType<import("../../types").SpatialGranularities>} */
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
type: Object,
required: true
}
},
setup(props, { emit }) {
Expand All @@ -367,6 +373,23 @@ export default defineComponent({
values
}));

const formatSpatialZones = (data) => {
const suggestions = data.map(item => {
const matchingGranularity = props.granularities.find(granularity => granularity.id === item.level);
maudetes marked this conversation as resolved.
Show resolved Hide resolved
if (matchingGranularity) {
return {
...item,
description: matchingGranularity.name,
};
} else {
return {
...item,
};
}
});
return suggestions;
}

const notUnknown = not(t("The value must be different than unknown."), sameAs("unknown"));
const tagsRequired = requiredWithCustomMessage(t("Adding tags helps improve the SEO of your data."));
const temporalCoverageRequired = requiredWithCustomMessage(t("You did not provide the temporal coverage."));
Expand Down Expand Up @@ -446,6 +469,7 @@ export default defineComponent({
state,
fieldHasError,
fieldHasWarning,
formatSpatialZones,
getErrorText,
getWarningText,
submit,
Expand Down
13 changes: 13 additions & 0 deletions udata_front/theme/gouvfr/assets/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,17 @@ metrics: { discussions: number; followers: number; reuses: number; views: number

export type AxisAlignment = "start" | "center" | "end";

export type SpatialZones = {
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
code: string;
Jorek57 marked this conversation as resolved.
Show resolved Hide resolved
id: string;
level: string;
name: string;
uri: string;
};

export type SpatialGranularities = {
nicolaskempf57 marked this conversation as resolved.
Show resolved Hide resolved
id: string;
Jorek57 marked this conversation as resolved.
Show resolved Hide resolved
name: string
};

export default {};