Files
Alan Guo Xiang TanandGitHub cd3a3f21ee UX: Allow a default value to be specified for enum properties (#26529)
Why this change?

For a `typed: objects` theme setting with an enum property, we are
adding a `default` key for `type: enum` fields which will be used
as the default value on the client side.

```
some_objects_setting:
  type: objects
  schema:
    name: field
    properties:
      enum_field:
        type: enum
        default: awesome
        choices:
          - nice
          - cool
          - awesome
```
2024-04-05 11:44:39 +08:00

215 lines
4.3 KiB
JavaScript

import ThemeSettings from "admin/models/theme-settings";
export default function schemaAndData(version = 1) {
let schema, data;
if (version === 1) {
schema = {
name: "level1",
identifier: "name",
properties: {
name: {
type: "string",
},
children: {
type: "objects",
schema: {
name: "level2",
identifier: "name",
properties: {
name: {
type: "string",
},
grandchildren: {
type: "objects",
schema: {
name: "level3",
identifier: "name",
properties: {
name: {
type: "string",
},
},
},
},
},
},
},
},
};
data = [
{
name: "item 1",
children: [
{
name: "child 1-1",
grandchildren: [
{
name: "grandchild 1-1-1",
},
{
name: "grandchild 1-1-2",
},
],
},
{
name: "child 1-2",
grandchildren: [
{
name: "grandchild 1-2-1",
},
],
},
],
},
{
name: "item 2",
children: [
{
name: "child 2-1",
grandchildren: [
{
name: "grandchild 2-1-1",
},
{
name: "grandchild 2-1-2",
},
],
},
{
name: "child 2-2",
grandchildren: [
{
name: "grandchild 2-2-1",
},
{
name: "grandchild 2-2-2",
},
{
name: "grandchild 2-2-3",
},
{
name: "grandchild 2-2-4",
},
],
},
{
name: "child 2-3",
grandchildren: [],
},
],
},
];
} else if (version === 2) {
schema = {
name: "section",
identifier: "name",
properties: {
name: {
type: "string",
},
icon: {
type: "string",
},
links: {
type: "objects",
schema: {
name: "link",
identifier: "text",
properties: {
text: {
type: "string",
},
url: {
type: "string",
},
icon: {
type: "string",
},
},
},
},
},
};
data = [
{
name: "nice section",
icon: "arrow",
links: [
{
text: "Privacy",
url: "https://example.com",
icon: "link",
},
],
},
{
name: "cool section",
icon: "bell",
links: [
{
text: "About",
url: "https://example.com/about",
icon: "asterisk",
},
{
text: "Contact",
url: "https://example.com/contact",
icon: "phone",
},
],
},
];
} else if (version === 3) {
schema = {
name: "something",
identifier: "name",
properties: {
name: {
type: "string",
},
integer_field: {
type: "integer",
},
float_field: {
type: "float",
},
boolean_field: {
type: "boolean",
},
category_field: {
type: "categories",
},
group_field: {
type: "groups",
},
tags_field: {
type: "tags",
}
},
};
data = [
{
name: "lamb",
integer_field: 92,
boolean_field: true,
},
{
name: "cow",
integer_field: 820,
boolean_field: false,
},
];
} else {
throw new Error("unknown fixture version");
}
return ThemeSettings.create({
objects_schema: schema,
value: data,
setting: "objects_setting"
});
}