Skip to content

Commit f112e57

Browse files
committed
LinkField: add example
1 parent 4234bc7 commit f112e57

5 files changed

Lines changed: 184 additions & 1 deletion

File tree

admin/pages/general.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EditPage, TextField } from '@contember/admin'
2+
import { LinkField } from '../../src'
23
import { CollapsibleBox } from '../../src/collapsibleBox/admin'
34
import { ImageField, ImageListField } from '../../src/image/admin'
45
import { YoutubeVideoField, YoutubeVideoListField } from '../../src/youtube/admin'
@@ -12,6 +13,7 @@ export default () => (
1213
}}
1314
>
1415
<TextField field="text" label="Text" />
16+
<LinkField field="privacyPolicyPage" label="Link to another" />
1517

1618
<CollapsibleBox heading="Images">
1719
<ImageField field="singleImage" label="Single image" />
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"formatVersion": 3,
3+
"modifications": [
4+
{
5+
"modification": "createEnum",
6+
"enumName": "LinkType",
7+
"values": [
8+
"internal",
9+
"external"
10+
]
11+
},
12+
{
13+
"modification": "createEntity",
14+
"entity": {
15+
"name": "Link",
16+
"primary": "id",
17+
"primaryColumn": "id",
18+
"tableName": "link",
19+
"fields": {
20+
"id": {
21+
"name": "id",
22+
"columnName": "id",
23+
"columnType": "uuid",
24+
"nullable": false,
25+
"type": "Uuid"
26+
}
27+
},
28+
"unique": {},
29+
"indexes": {},
30+
"eventLog": {
31+
"enabled": true
32+
}
33+
}
34+
},
35+
{
36+
"modification": "createColumn",
37+
"entityName": "Link",
38+
"field": {
39+
"name": "type",
40+
"columnName": "type",
41+
"columnType": "LinkType",
42+
"nullable": false,
43+
"type": "Enum"
44+
}
45+
},
46+
{
47+
"modification": "createColumn",
48+
"entityName": "Link",
49+
"field": {
50+
"name": "title",
51+
"columnName": "title",
52+
"columnType": "text",
53+
"nullable": true,
54+
"type": "String"
55+
}
56+
},
57+
{
58+
"modification": "createColumn",
59+
"entityName": "Link",
60+
"field": {
61+
"name": "isTargetBlank",
62+
"columnName": "is_target_blank",
63+
"columnType": "boolean",
64+
"nullable": false,
65+
"type": "Bool",
66+
"default": false
67+
},
68+
"fillValue": false
69+
},
70+
{
71+
"modification": "createColumn",
72+
"entityName": "Link",
73+
"field": {
74+
"name": "externalLink",
75+
"columnName": "external_link",
76+
"columnType": "text",
77+
"nullable": true,
78+
"type": "String"
79+
}
80+
},
81+
{
82+
"modification": "createRelation",
83+
"entityName": "General",
84+
"owningSide": {
85+
"type": "OneHasOne",
86+
"name": "privacyPolicyPage",
87+
"target": "Link",
88+
"joiningColumn": {
89+
"columnName": "privacy_policy_page_id",
90+
"onDelete": "set null"
91+
},
92+
"nullable": true
93+
}
94+
},
95+
{
96+
"modification": "createRelation",
97+
"entityName": "Link",
98+
"owningSide": {
99+
"type": "ManyHasOne",
100+
"name": "internalLink",
101+
"target": "Linkable",
102+
"joiningColumn": {
103+
"columnName": "internal_link_id",
104+
"onDelete": "set null"
105+
},
106+
"nullable": true
107+
}
108+
},
109+
{
110+
"modification": "patchAclSchema",
111+
"patch": [
112+
{
113+
"op": "add",
114+
"path": "/roles/admin/entities/Link",
115+
"value": {
116+
"predicates": {},
117+
"operations": {
118+
"read": {
119+
"id": true,
120+
"type": true,
121+
"title": true,
122+
"isTargetBlank": true,
123+
"externalLink": true,
124+
"internalLink": true
125+
},
126+
"create": {
127+
"id": true,
128+
"type": true,
129+
"title": true,
130+
"isTargetBlank": true,
131+
"externalLink": true,
132+
"internalLink": true
133+
},
134+
"update": {
135+
"id": true,
136+
"type": true,
137+
"title": true,
138+
"isTargetBlank": true,
139+
"externalLink": true,
140+
"internalLink": true
141+
},
142+
"delete": true,
143+
"customPrimary": true
144+
}
145+
}
146+
},
147+
{
148+
"op": "add",
149+
"path": "/roles/admin/entities/General/operations/read/privacyPolicyPage",
150+
"value": true
151+
},
152+
{
153+
"op": "add",
154+
"path": "/roles/admin/entities/General/operations/create/privacyPolicyPage",
155+
"value": true
156+
},
157+
{
158+
"op": "add",
159+
"path": "/roles/admin/entities/General/operations/update/privacyPolicyPage",
160+
"value": true
161+
}
162+
]
163+
}
164+
]
165+
}

api/model/General.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SchemaDefinition as d } from '@contember/schema-definition'
22
import { Image, ImageList } from './Image'
3+
import { Link } from './Link'
34
import { One } from './One'
45
import { YoutubeVideo, YoutubeVideoList } from './Youtube'
56

@@ -11,6 +12,8 @@ export class General {
1112
singleImage = d.oneHasOne(Image).setNullOnDelete()
1213
imageList = d.oneHasOne(ImageList).setNullOnDelete()
1314

15+
privacyPolicyPage = d.oneHasOne(Link).setNullOnDelete()
16+
1417
singleYoutubeVideo = d.oneHasOne(YoutubeVideo).setNullOnDelete()
1518
youtubeVideoList = d.oneHasOne(YoutubeVideoList).setNullOnDelete()
1619
}

api/model/Link.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { SchemaDefinition as d } from '@contember/schema-definition'
2+
import { Linkable } from './Linkable'
3+
4+
export const LinkType = d.createEnum('internal', 'external')
5+
6+
export class Link {
7+
type = d.enumColumn(LinkType).notNull()
8+
title = d.stringColumn()
9+
isTargetBlank = d.boolColumn().notNull().default(false)
10+
externalLink = d.stringColumn()
11+
internalLink = d.manyHasOne(Linkable).setNullOnDelete()
12+
}

api/model/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
export * from './acl'
21
export * from './General'
32
export * from './GenericPage'
43
export * from './Image'
4+
export * from './Link'
55
export * from './Linkable'
66
export * from './One'
77
export * from './Seo'
88
export * from './Translation'
99
export * from './Youtube'
10+
export * from './acl'

0 commit comments

Comments
 (0)