-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitialValueTemplates.ts
More file actions
108 lines (101 loc) · 3.07 KB
/
Copy pathinitialValueTemplates.ts
File metadata and controls
108 lines (101 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import type { Template } from 'sanity'
import { defaultLanguage, isoToSchemaName, languages } from './languages'
import textSnippets from './schemas/textSnippets'
import { Flags } from './src/lib/datasetHelpers'
const ParentRoutesTemplates: Template<any, any>[] = languages.map(
({ iso, title }) => ({
id: `parent-route-${iso}`,
title: `Parent route - ${title}`,
schemaType: `route_${isoToSchemaName(iso)}`,
parameters: [{ name: 'parentId', type: 'string' }],
value: (params: Record<string, unknown>) => ({
parent: { _type: 'reference', _ref: params.parentId },
}),
}),
)
const TextSnippetsTemplates: Template<any, any>[] = Object.keys(
textSnippets,
).map(key => ({
id: `text-snippet-${key}`,
title: `Text Snippet - ${textSnippets[key].title}`,
schemaType: `textSnippet`,
parameters: [{ name: 'defaultValue', type: 'string' }],
value: (params: Record<string, unknown>) => {
const fields = languages.map(({ iso }) => ({
[isoToSchemaName(iso)]: params.defaultValue,
}))
return Object.assign({}, ...fields)
},
}))
const MenuTemplates: Template<any, any>[] = Flags.HAS_FANCY_MENU
? [
{
id: 'menu-with-locale',
title: 'Site menu',
schemaType: 'siteMenu',
parameters: [{ name: 'isoCode', type: 'string' }],
value: (params: Record<string, unknown>) => ({
lang: params.isoCode,
}),
},
{
id: 'submenu-with-locale',
title: 'Sub menu',
schemaType: 'siteMenu',
parameters: [{ name: 'isoCode', type: 'string' }],
value: (params: Record<string, unknown>) => ({
lang: params.isoCode,
}),
},
]
: [
{
id: 'simple-menu-with-locale',
title: 'Site menu (simple)',
schemaType: 'simpleMenu',
parameters: [{ name: 'isoCode', type: 'string' }],
value: (params: Record<string, unknown>) => ({
lang: params.isoCode,
}),
},
]
const footerWithLocaleTemplate: Template<any, any> = {
id: 'footer-with-locale',
title: 'Footer',
schemaType: 'footer',
parameters: [{ name: 'isoCode', type: 'string' }],
value: (params: Record<string, unknown>) => ({
lang: params.isoCode,
}),
}
const redirectWithLocaleTemplate: Template<any, any> = {
id: 'redirect-with-locale',
title: 'Redirect',
schemaType: 'redirect',
parameters: [{ name: 'isoCode', type: 'string' }],
value: (params: Record<string, unknown>) => ({
lang: params.isoCode,
}),
}
const localNewsWithTagTemplate: Template<any, any> = {
id: 'localnews-with-tag',
title: 'Local news',
schemaType: 'localNews',
parameters: [
{ name: 'localNewsTag', type: 'reference' },
{ name: 'lang', type: 'string' },
],
value: (params: Record<string, unknown>) => ({
localNewsTag: params.localNewsTag,
lang: params.lang || defaultLanguage.iso,
}),
}
export const initialValueTemplates = [
//promotedMagazineTagTemplate,
localNewsWithTagTemplate,
redirectWithLocaleTemplate,
footerWithLocaleTemplate,
...MenuTemplates,
...TextSnippetsTemplates,
...ParentRoutesTemplates,
]