Support for parent pages on folders
This commit is contained in:
parent
8557df4753
commit
5fe9844341
|
@ -1,4 +1,5 @@
|
||||||
import { CollectionGroups, Collections } from "../../constants";
|
import { CollectionGroups, Collections } from "../../constants";
|
||||||
|
import { backPropagationField } from "../../fields/backPropagationField/backPropagationField";
|
||||||
import { iconField } from "../../fields/iconField/iconField";
|
import { iconField } from "../../fields/iconField/iconField";
|
||||||
import { rowField } from "../../fields/rowField/rowField";
|
import { rowField } from "../../fields/rowField/rowField";
|
||||||
import { slugField } from "../../fields/slugField/slugField";
|
import { slugField } from "../../fields/slugField/slugField";
|
||||||
|
@ -19,6 +20,7 @@ const fields = {
|
||||||
sectionsTranslationsName: "name",
|
sectionsTranslationsName: "name",
|
||||||
files: "files",
|
files: "files",
|
||||||
icon: "icon",
|
icon: "icon",
|
||||||
|
parentFolders: "parentFolders",
|
||||||
} as const satisfies Record<string, string>;
|
} as const satisfies Record<string, string>;
|
||||||
|
|
||||||
export const Folders = buildCollectionConfig({
|
export const Folders = buildCollectionConfig({
|
||||||
|
@ -27,14 +29,23 @@ export const Folders = buildCollectionConfig({
|
||||||
admin: {
|
admin: {
|
||||||
useAsTitle: fields.slug,
|
useAsTitle: fields.slug,
|
||||||
group: CollectionGroups.Collections,
|
group: CollectionGroups.Collections,
|
||||||
defaultColumns: [fields.slug, fields.translations, fields.sections, fields.files, fields.icon],
|
defaultColumns: [fields.slug, fields.translations, fields.parentFolders, fields.sections, fields.files, fields.icon],
|
||||||
description:
|
description:
|
||||||
"Folders provide a way to structure our content. A folder can contain subfolders and/or files.",
|
"Folders provide a way to structure our content. A folder can contain subfolders and/or files.",
|
||||||
preview: ({ slug }) => `https://v3.accords-library.com/en/folders/${slug}`,
|
preview: ({ slug }) => `https://v3.accords-library.com/en/folders/${slug}`,
|
||||||
},
|
},
|
||||||
endpoints: [getRootFoldersEndpoint, getBySlugEndpoint],
|
endpoints: [getRootFoldersEndpoint, getBySlugEndpoint],
|
||||||
fields: [
|
fields: [
|
||||||
rowField([slugField({ name: fields.slug }), iconField({ name: fields.icon })]),
|
rowField([
|
||||||
|
slugField({ name: fields.slug }),
|
||||||
|
iconField({ name: fields.icon }),
|
||||||
|
backPropagationField({
|
||||||
|
name: fields.parentFolders,
|
||||||
|
relationTo: Collections.Folders,
|
||||||
|
hasMany: true,
|
||||||
|
where: ({ id }) => ({ "sections.subfolders": { equals: id } }),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
translatedFields({
|
translatedFields({
|
||||||
name: fields.translations,
|
name: fields.translations,
|
||||||
admin: { useAsTitle: fields.translationsName },
|
admin: { useAsTitle: fields.translationsName },
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||||
import { EndpointFolder, EndpointFolderPreview } from "../../../sdk";
|
import { EndpointFolder, EndpointFolderPreview } from "../../../sdk";
|
||||||
import { Folder, Language } from "../../../types/collections";
|
import { Folder, Language } from "../../../types/collections";
|
||||||
import { isDefined, isPayloadType } from "../../../utils/asserts";
|
import { isDefined, isPayloadType } from "../../../utils/asserts";
|
||||||
|
import { handleParentPages } from "../../../utils/endpoints";
|
||||||
import { convertCollectibleToPreview } from "../../Collectibles/endpoints/getBySlugEndpoint";
|
import { convertCollectibleToPreview } from "../../Collectibles/endpoints/getBySlugEndpoint";
|
||||||
import { convertPageToPreview } from "../../Pages/endpoints/getBySlugEndpoint";
|
import { convertPageToPreview } from "../../Pages/endpoints/getBySlugEndpoint";
|
||||||
|
|
||||||
|
@ -10,20 +11,21 @@ export const getBySlugEndpoint = createGetByEndpoint(
|
||||||
Collections.Folders,
|
Collections.Folders,
|
||||||
"slug",
|
"slug",
|
||||||
(folder: Folder): EndpointFolder => {
|
(folder: Folder): EndpointFolder => {
|
||||||
|
const { sections, files, parentFolders } = folder;
|
||||||
return {
|
return {
|
||||||
...convertFolderToPreview(folder),
|
...convertFolderToPreview(folder),
|
||||||
sections:
|
sections:
|
||||||
folder.sections?.length === 1
|
sections?.length === 1
|
||||||
? {
|
? {
|
||||||
type: "single",
|
type: "single",
|
||||||
subfolders:
|
subfolders:
|
||||||
folder.sections[0]?.subfolders?.filter(isPayloadType).map(convertFolderToPreview) ??
|
sections[0]?.subfolders?.filter(isPayloadType).map(convertFolderToPreview) ??
|
||||||
[],
|
[],
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
type: "multiple",
|
type: "multiple",
|
||||||
sections:
|
sections:
|
||||||
folder.sections?.filter(isValidSection).map(({ translations, subfolders }) => ({
|
sections?.filter(isValidSection).map(({ translations, subfolders }) => ({
|
||||||
translations: translations.map(({ language, name }) => ({
|
translations: translations.map(({ language, name }) => ({
|
||||||
language: getLanguageId(language),
|
language: getLanguageId(language),
|
||||||
name,
|
name,
|
||||||
|
@ -32,7 +34,7 @@ export const getBySlugEndpoint = createGetByEndpoint(
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
},
|
},
|
||||||
files:
|
files:
|
||||||
folder.files?.flatMap<EndpointFolder["files"][number]>(({ relationTo, value }) => {
|
files?.flatMap<EndpointFolder["files"][number]>(({ relationTo, value }) => {
|
||||||
if (!isPayloadType(value)) {
|
if (!isPayloadType(value)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -43,6 +45,7 @@ export const getBySlugEndpoint = createGetByEndpoint(
|
||||||
return [{ relationTo, value: convertPageToPreview(value) }];
|
return [{ relationTo, value: convertPageToPreview(value) }];
|
||||||
}
|
}
|
||||||
}) ?? [],
|
}) ?? [],
|
||||||
|
parentPages: handleParentPages({ folders: parentFolders }),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
3
|
3
|
||||||
|
|
|
@ -156,6 +156,7 @@ export type EndpointFolder = EndpointFolderPreview & {
|
||||||
value: EndpointPagePreview;
|
value: EndpointPagePreview;
|
||||||
}
|
}
|
||||||
)[];
|
)[];
|
||||||
|
parentPages: ParentPage[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EndpointHomeFolder = EndpointFolderPreview & {
|
export type EndpointHomeFolder = EndpointFolderPreview & {
|
||||||
|
@ -233,7 +234,6 @@ export type ParentPage = {
|
||||||
slug: string;
|
slug: string;
|
||||||
collection: Collections;
|
collection: Collections;
|
||||||
translations: { language: string; name: string }[];
|
translations: { language: string; name: string }[];
|
||||||
tag: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EndpointCollectiblePreview = {
|
export type EndpointCollectiblePreview = {
|
||||||
|
|
|
@ -290,6 +290,7 @@ export interface Folder {
|
||||||
id: string;
|
id: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
icon?: string | null;
|
icon?: string | null;
|
||||||
|
parentFolders?: (string | Folder)[] | null;
|
||||||
translations: {
|
translations: {
|
||||||
language: string | Language;
|
language: string | Language;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -61,7 +61,6 @@ export const handleParentPages = ({
|
||||||
language: isPayloadType(language) ? language.id : language,
|
language: isPayloadType(language) ? language.id : language,
|
||||||
name: title, // TODO: Use the entire pretitle + title + subtitle
|
name: title, // TODO: Use the entire pretitle + title + subtitle
|
||||||
})),
|
})),
|
||||||
tag: "collectible",
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -76,7 +75,6 @@ export const handleParentPages = ({
|
||||||
language: isPayloadType(language) ? language.id : language,
|
language: isPayloadType(language) ? language.id : language,
|
||||||
name,
|
name,
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
tag: "folders",
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue