Skip to content

Commit

Permalink
fix delete group bug
Browse files Browse the repository at this point in the history
  • Loading branch information
narduin committed Dec 3, 2024
1 parent 033e0f5 commit 2339bee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/components/DisclosureWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const actions = computed(() => {
label-visible
:aria-invalid="inputErrors.length ? true : undefined"
:description-id="inputErrors.length ? 'errors-name' : undefined"
@keypress.prevent.enter="onValidateEdit"
/>
<div v-if="inputErrors.length" id="errors-name" class="error">
<p v-for="(error, index) in inputErrors" :key="index">
Expand Down
31 changes: 3 additions & 28 deletions src/components/bouquets/BouquetDatasetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import DatasetEditModal, {
type DatasetEditModalType
} from '@/components/forms/dataset/DatasetEditModal.vue'
import config from '@/config'
import { type DatasetProperties, type DatasetsGroups } from '@/model/topic'
import { type DatasetProperties } from '@/model/topic'
import { useDatasetStore } from '@/store/DatasetStore'
import { fromMarkdown } from '@/utils'
import { isAvailable } from '@/utils/bouquet'
import { useTopicsConf } from '@/utils/config'
import { toastHttpError } from '@/utils/error'
import { isNotFoundError } from '@/utils/http'
import { noGroup, useGroups } from '@/utils/bouquetGroups'
import { useGroups } from '@/utils/bouquetGroups'
import DisclosureWidget from '../DisclosureWidget.vue'
import BouquetDatasetCard from './BouquetDatasetCard.vue'
Expand Down Expand Up @@ -49,31 +49,6 @@ const {
deleteGroup
} = useGroups(datasetsProperties)
const sortedGroupedDatasets = computed(() => {
// get all entries within nogroup if any exists
const noGroupEntries: DatasetProperties[] | null = groupedDatasets.value.has(
noGroup
)
? groupedDatasets.value.get(noGroup)
: null
// create a new Map without nogroup
const filteredGroups: DatasetsGroups = new Map(
[...groupedDatasets.value].filter(([key]) => key !== noGroup)
)
// Alphabetically sort the keys with nogroup at the end
const entries = Array.from(filteredGroups.entries()).sort(
([keyA], [keyB]) => {
return keyA.toString().localeCompare(keyB.toString())
}
)
// Add the nogroup to the end of the sorted array
if (noGroupEntries) {
entries.push([noGroup, noGroupEntries])
}
// Convert back the sorted groups into a Map
return new Map(entries)
})
const handleRemoveDataset = (group: string, index: number) => {
removeDatasetFromGroup(group, index)
emits('updateDatasets')
Expand Down Expand Up @@ -159,7 +134,7 @@ onMounted(() => {
<template v-else>
<div v-if="datasetEditorialization" class="fr-mt-10v">
<ul role="list" class="groups fr-m-0 fr-p-0">
<li v-for="[group, datasets] in sortedGroupedDatasets" :key="group">
<li v-for="[group, datasets] in groupedDatasets" :key="group">
<DisclosureWidget
v-if="datasets.length"
:group-name="group"
Expand Down
31 changes: 28 additions & 3 deletions src/utils/bouquetGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,30 @@ export function useGroups(datasetsProperties: Ref<DatasetProperties[]>): {
}
})

return datasetsGroups.value
// get all entries within nogroup if any exists
const noGroupEntries: DatasetProperties[] | undefined =
datasetsGroups.value.has(noGroup)
? datasetsGroups.value.get(noGroup)
: undefined

// create a new Map without nogroup
const filteredGroups: DatasetsGroups = new Map(
[...datasetsGroups.value].filter(([key]) => key !== noGroup)
)

// Alphabetically sort the keys with nogroup at the end
const sortedEntries = Array.from(filteredGroups.entries()).sort(
([keyA], [keyB]) => {
return keyA.toString().localeCompare(keyB.toString())
}
)

// Add the nogroup to the end of the sorted array
if (noGroupEntries) {
sortedEntries.push([noGroup, noGroupEntries])
}

return new Map(sortedEntries)
})
const getDatasetIndex = (group: string, indexInGroup: number) => {
// get all datasets from group
Expand Down Expand Up @@ -76,7 +99,8 @@ export function useGroups(datasetsProperties: Ref<DatasetProperties[]>): {
const matchingDatasets = datasetsProperties.value.filter((dataset) => {
return oldGroupItems.some(
(groupItem) =>
groupItem.id === dataset.id && groupItem.group === dataset.group
groupItem.title === dataset.title &&
groupItem.group === dataset.group
)
})
if (matchingDatasets) {
Expand All @@ -97,7 +121,8 @@ export function useGroups(datasetsProperties: Ref<DatasetProperties[]>): {
(dataset) => {
return groupItems.find(
(groupItem) =>
groupItem.id !== dataset.id && groupItem.group !== dataset.group
groupItem.title !== dataset.title &&
groupItem.group !== dataset.group
)
}
)
Expand Down

0 comments on commit 2339bee

Please sign in to comment.