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

fix(api-headless-cms): wrong references order #3761

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContentModelGroup } from "./contentModelGroup";
import { CmsModel } from "~/types";
import { CmsModelInput, createCmsGroup, createCmsModel } from "~/plugins";

const { version: webinyVersion } = require("@webiny/cli/package.json");

Expand Down Expand Up @@ -84,7 +85,10 @@ const ids = {
field701: "title",
field702: "body",
field703: "categories",
field704: "category"
field704: "category",
// wrapper
field_wrap_1: "title",
field_wrap_2: "references"
};

const models: CmsModel[] = [
Expand Down Expand Up @@ -1573,6 +1577,7 @@ const models: CmsModel[] = [
tenant: "root",
webinyVersion
},
// article
{
createdOn: new Date().toISOString(),
savedOn: new Date().toISOString(),
Expand Down Expand Up @@ -1675,6 +1680,70 @@ const models: CmsModel[] = [
],
tenant: "root",
webinyVersion
},
// Wrap
/**
* Used to test the ref field with multiple models.
*/
{
name: "Wrap",
modelId: "wrap",
singularApiName: "Wrap",
pluralApiName: "Wraps",
group: {
id: contentModelGroup.id,
name: contentModelGroup.name
},
fields: [
{
id: ids.field_wrap_1,
label: "Title",
fieldId: "title",
type: "text",
storageId: "text@titleStorageId",
predefinedValues: {
enabled: false,
values: []
},
renderer: {
name: "renderer"
}
},
{
id: ids.field_wrap_2,
label: "References",
fieldId: "references",
type: "ref",
storageId: "ref@references",
multipleValues: true,
settings: {
models: [
{
modelId: "product"
},
{
modelId: "category"
},
{
modelId: "author"
}
]
},
predefinedValues: {
enabled: false,
values: []
},
renderer: {
name: "renderer"
}
}
],
layout: [],
tenant: "root",
locale: "en-US",
titleFieldId: "title",
description: "Wrapper model for ref field with multiple models",
webinyVersion
}
];

Expand All @@ -1689,3 +1758,22 @@ export const getCmsModel = (modelId: string) => {
}
return model;
};

export const createModelPlugins = (targets: string[]) => {
return [
createCmsGroup({
...contentModelGroup
}),
...targets.map(modelId => {
const model = models.find(m => m.modelId === modelId);
if (!model) {
throw new Error(`There is no model ${modelId}.`);
}
const newModel: CmsModelInput = {
...(model as Omit<CmsModel, "isPrivate">),
noValidate: true
};
return createCmsModel(newModel);
})
];
};
Loading