Skip to content

Commit 16b025d

Browse files
authored
refactor: bloc components management and allow markdown inside accordion (#871)
1 parent 7afd3b8 commit 16b025d

File tree

4 files changed

+46
-97
lines changed

4 files changed

+46
-97
lines changed

components/Pages/AccordionBlocEditor.vue

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,9 @@
9797
/>
9898
</div>
9999

100-
<DatasetsListBloc
101-
v-if="contentBloc.class === 'DatasetsListBloc'"
102-
v-model="(item.content[contentIndex] as DatasetsListBlocType)"
103-
:edit
104-
/>
105-
<DataservicesListBloc
106-
v-if="contentBloc.class === 'DataservicesListBloc'"
107-
v-model="(item.content[contentIndex] as DataservicesListBlocType)"
108-
:edit
109-
/>
110-
<ReusesListBloc
111-
v-if="contentBloc.class === 'ReusesListBloc'"
112-
v-model="(item.content[contentIndex] as ReusesListBlocType)"
113-
:edit
114-
/>
115-
<LinksListBloc
116-
v-if="contentBloc.class === 'LinksListBloc'"
117-
v-model="(item.content[contentIndex] as LinksListBlocType)"
100+
<component
101+
:is="contentBlocsTypes[contentBloc.class].component"
102+
v-model="(item.content[contentIndex] as any)"
118103
:edit
119104
/>
120105
</div>
@@ -179,18 +164,9 @@ import { RiAddLine, RiArrowDownLine, RiArrowUpLine, RiDeleteBinLine } from '@rem
179164
import BlocWithTitleAndSubtitle from './BlocWithTitleAndSubtitle.vue'
180165
import EditableText from './EditableText.vue'
181166
import AddBlocDropdown from './AddBlocDropdown.vue'
182-
import DatasetsListBloc from './DatasetsListBloc.vue'
183-
import DataservicesListBloc from './DataservicesListBloc.vue'
184-
import ReusesListBloc from './ReusesListBloc.vue'
185-
import LinksListBloc from './LinksListBloc.vue'
186-
import type {
187-
AccordionListBloc,
188-
ContentBloc,
189-
DatasetsListBloc as DatasetsListBlocType,
190-
DataservicesListBloc as DataservicesListBlocType,
191-
ReusesListBloc as ReusesListBlocType,
192-
LinksListBloc as LinksListBlocType,
193-
} from '~/types/pages'
167+
import type { AccordionListBloc, ContentBloc } from '~/types/pages'
168+
169+
const contentBlocsTypes = useContentBlocsTypes()
194170
195171
const props = defineProps<{
196172
edit: boolean

components/Pages/PageShow.vue

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,54 +49,26 @@
4949
/>
5050
</div>
5151

52-
<!-- HeroBloc has its own full-width layout -->
53-
<HeroBloc
54-
v-if="bloc.class === 'HeroBloc'"
55-
v-model="(workingPage.blocs[index] as HeroBlocType)"
52+
<!-- Full-width blocs (like HeroBloc) -->
53+
<component
54+
:is="blocsTypes[bloc.class].component"
55+
v-if="'fullWidth' in blocsTypes[bloc.class]"
56+
v-model="(workingPage.blocs[index] as any)"
5657
:edit
58+
:main-color="mainColor"
5759
/>
5860

5961
<!-- Other blocs use container layout -->
6062
<div
6163
v-else
6264
class="container"
6365
>
64-
<DatasetsListBloc
65-
v-if="bloc.class === 'DatasetsListBloc'"
66-
v-model="(workingPage.blocs[index] as DatasetsListBlocType)"
67-
:edit
68-
/>
69-
70-
<DataservicesListBloc
71-
v-if="bloc.class === 'DataservicesListBloc'"
72-
v-model="(workingPage.blocs[index] as DataservicesListBlocType)"
73-
:edit
74-
/>
75-
76-
<ReusesListBloc
77-
v-if="bloc.class === 'ReusesListBloc'"
78-
v-model="(workingPage.blocs[index] as ReusesListBlocType)"
79-
:edit
80-
/>
81-
82-
<LinksListBloc
83-
v-if="bloc.class === 'LinksListBloc'"
84-
v-model="(workingPage.blocs[index] as LinksListBlocType)"
66+
<component
67+
:is="blocsTypes[bloc.class].component"
68+
v-model="(workingPage.blocs[index] as any)"
8569
:edit
8670
:main-color="mainColor"
8771
/>
88-
89-
<AccordionBlocEditor
90-
v-if="bloc.class === 'AccordionListBloc'"
91-
v-model="(workingPage.blocs[index] as AccordionListBlocType)"
92-
:edit
93-
/>
94-
95-
<MarkdownBloc
96-
v-if="bloc.class === 'MarkdownBloc'"
97-
v-model="(workingPage.blocs[index] as MarkdownBlocType)"
98-
:edit
99-
/>
10072
</div>
10173

10274
<!-- Add button below the last bloc -->
@@ -157,23 +129,9 @@ import type { ComponentProps } from 'vue-component-type-helpers'
157129
import { BrandedButton } from '@datagouv/components-next'
158130
import { RiAddLine, RiArrowDownLine, RiArrowUpLine, RiDeleteBinLine } from '@remixicon/vue'
159131
import AddBlocDropdown from './AddBlocDropdown.vue'
160-
import DatasetsListBloc from './DatasetsListBloc.vue'
161-
import DataservicesListBloc from './DataservicesListBloc.vue'
162-
import ReusesListBloc from './ReusesListBloc.vue'
163-
import LinksListBloc from './LinksListBloc.vue'
164-
import AccordionBlocEditor from './AccordionBlocEditor.vue'
165-
import MarkdownBloc from './MarkdownBloc.vue'
166-
import HeroBloc from './HeroBloc.vue'
167-
import type {
168-
Page,
169-
DatasetsListBloc as DatasetsListBlocType,
170-
DataservicesListBloc as DataservicesListBlocType,
171-
ReusesListBloc as ReusesListBlocType,
172-
LinksListBloc as LinksListBlocType,
173-
AccordionListBloc as AccordionListBlocType,
174-
MarkdownBloc as MarkdownBlocType,
175-
HeroBloc as HeroBlocType,
176-
} from '~/types/pages'
132+
import type { Page } from '~/types/pages'
133+
134+
const blocsTypes = useBlocsTypes()
177135
178136
const props = withDefaults(defineProps<{
179137
page: Page

types/pages.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ export type LinksListBloc = {
3737
links: Array<LinkInBloc>
3838
} & BlocWithTitle & { id: string }
3939

40-
export type ContentBloc = DatasetsListBloc | DataservicesListBloc | ReusesListBloc | LinksListBloc
40+
export type MarkdownBloc = {
41+
class: 'MarkdownBloc'
42+
content: string
43+
} & BlocWithTitle & { id: string }
44+
45+
export type ContentBloc = DatasetsListBloc | DataservicesListBloc | ReusesListBloc | LinksListBloc | MarkdownBloc
4146

4247
export type AccordionItemBloc = {
4348
title: string
@@ -51,16 +56,11 @@ export type AccordionListBloc = {
5156
items: Array<AccordionItemBloc>
5257
} & { id: string }
5358

54-
export type MarkdownBloc = {
55-
class: 'MarkdownBloc'
56-
content: string
57-
} & BlocWithTitle & { id: string }
58-
5959
export type HeroBloc = {
6060
class: 'HeroBloc'
6161
title: string
6262
description: string | null
6363
color: 'primary' | 'green' | 'purple'
6464
} & { id: string }
6565

66-
export type PageBloc = ContentBloc | AccordionListBloc | MarkdownBloc | HeroBloc
66+
export type PageBloc = ContentBloc | AccordionListBloc | HeroBloc

utils/pages.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { RiDatabase2Line, RiLineChartLine, RiLink, RiListCheck2, RiMarkdownLine, RiRobot2Line, RiWindow2Line } from '@remixicon/vue'
22
import type { AccordionListBloc, DataservicesListBloc, DatasetsListBloc, HeroBloc, LinksListBloc, MarkdownBloc, ReusesListBloc } from '~/types/pages'
3+
import DatasetsListBlocComponent from '~/components/Pages/DatasetsListBloc.vue'
4+
import DataservicesListBlocComponent from '~/components/Pages/DataservicesListBloc.vue'
5+
import ReusesListBlocComponent from '~/components/Pages/ReusesListBloc.vue'
6+
import LinksListBlocComponent from '~/components/Pages/LinksListBloc.vue'
7+
import MarkdownBlocComponent from '~/components/Pages/MarkdownBloc.vue'
8+
import AccordionBlocEditorComponent from '~/components/Pages/AccordionBlocEditor.vue'
9+
import HeroBlocComponent from '~/components/Pages/HeroBloc.vue'
310

411
export function useContentBlocsTypes() {
512
const { t } = useTranslation()
@@ -9,26 +16,37 @@ export function useContentBlocsTypes() {
916
icon: RiDatabase2Line,
1017
name: t('Données à la une'),
1118
description: t('Mettre en avant jusqu\'à 4 jeux de données'),
19+
component: DatasetsListBlocComponent,
1220
default: (): Omit<DatasetsListBloc, 'id'> => ({ class: 'DatasetsListBloc', title: t('Mes jeux de données'), subtitle: null, datasets: [] }),
1321
},
1422
DataservicesListBloc: {
1523
icon: RiRobot2Line,
1624
name: t('APIs à la une'),
1725
description: t('Mettre en avant jusqu\'à 4 APIs'),
26+
component: DataservicesListBlocComponent,
1827
default: (): Omit<DataservicesListBloc, 'id'> => ({ class: 'DataservicesListBloc', title: t('Mes APIs'), subtitle: null, dataservices: [] }),
1928
},
2029
ReusesListBloc: {
2130
icon: RiLineChartLine,
2231
name: t('Réutilisations à la une'),
2332
description: t('Mettre en avant jusqu\'à 4 réutilisations'),
33+
component: ReusesListBlocComponent,
2434
default: (): Omit<ReusesListBloc, 'id'> => ({ class: 'ReusesListBloc', title: t('Mes réutilisations'), subtitle: null, reuses: [] }),
2535
},
2636
LinksListBloc: {
2737
icon: RiLink,
2838
name: t('Liens à la une'),
2939
description: t('Mettre en avant jusqu\'à 4 liens'),
40+
component: LinksListBlocComponent,
3041
default: (): Omit<LinksListBloc, 'id'> => ({ class: 'LinksListBloc', title: t('Mes liens'), subtitle: null, paragraph: null, main_link_title: null, main_link_url: null, links: [] }),
3142
},
43+
MarkdownBloc: {
44+
icon: RiMarkdownLine,
45+
name: t('Bloc Markdown'),
46+
description: t('Ajouter du contenu texte riche'),
47+
component: MarkdownBlocComponent,
48+
default: (): Omit<MarkdownBloc, 'id'> => ({ class: 'MarkdownBloc', title: 'Titre', subtitle: null, content: '' }),
49+
},
3250
}
3351
}
3452

@@ -42,18 +60,15 @@ export function useBlocsTypes() {
4260
icon: RiListCheck2,
4361
name: t('Accordéon'),
4462
description: t('Liste dépliable de contenus (FAQ, etc.)'),
63+
component: AccordionBlocEditorComponent,
4564
default: (): Omit<AccordionListBloc, 'id'> => ({ class: 'AccordionListBloc', title: t('Mon accordéon'), description: null, items: [] }),
4665
},
47-
MarkdownBloc: {
48-
icon: RiMarkdownLine,
49-
name: t('Bloc Markdown'),
50-
description: t('Ajouter du contenu texte riche'),
51-
default: (): Omit<MarkdownBloc, 'id'> => ({ class: 'MarkdownBloc', title: 'Titre', subtitle: null, content: '' }),
52-
},
5366
HeroBloc: {
5467
icon: RiWindow2Line,
5568
name: t('Hero'),
5669
description: t('Bandeau d\'en-tête avec titre et description'),
70+
component: HeroBlocComponent,
71+
fullWidth: true,
5772
default: (): Omit<HeroBloc, 'id'> => ({ class: 'HeroBloc', title: 'Titre', description: null, color: 'primary' }),
5873
},
5974
}

0 commit comments

Comments
 (0)