Skip to content

Commit

Permalink
fix: corrige l'id culture invalide sur certains imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregoire Ducharme committed Sep 20, 2024
1 parent 466e396 commit 42af430
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/forms/fields/CultureSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ const props = defineProps({
const emit = defineEmits(['change'])
const uuidedCultures = computed(() => {
const uuidRegex = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
return props.cultures.map(culture => ({
...culture,
id: culture.id ?? crypto.randomUUID(),
id: culture.id && uuidRegex.test(culture.id) ? culture.id : crypto.randomUUID(),
// variete: '',
// date_semis: '',
// superficie: ''
Expand Down
17 changes: 16 additions & 1 deletion src/stores/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,26 @@ export const useRecordStore = defineStore('record', () => {
* @return {Promise<NormalizedRecord>}
*/
async function duplicate(id) {
const uuidRegex = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
const recordSummary = operatorStore.records.find(record => record.record_id === id)
const record = await getRecord(id)

const newRecord = await createOperatorRecord(operatorStore.operator.numeroBio, {
version_name: `Copie de ${record.version_name}`,
parcelles: record.parcelles,
parcelles: {
...record.parcelles,
features: record.parcelles.features.map((p) => ({
...p,
properties: {
...p.properties,
cultures: p.properties.cultures.map((c) => (
{
...c,
id: c.id && uuidRegex.test(c.id) ? c.id : crypto.randomUUID()
}))
}
})),
},
metadata: {
provenance: window.location.host,
source: 'Copie de version existante',
Expand Down

0 comments on commit 42af430

Please sign in to comment.