Skip to content

Commit 123b1c6

Browse files
authored
Merge pull request #76 from devforth/next
Next
2 parents cea2eba + 4002e05 commit 123b1c6

File tree

24 files changed

+304
-104
lines changed

24 files changed

+304
-104
lines changed

adminforth/commands/createApp/templates/users.ts.hbs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export default {
2323
primaryKey: true,
2424
type: AdminForthDataTypes.STRING,
2525
fillOnCreate: ({ initialRecord, adminUser }) => Math.random().toString(36).substring(7),
26-
showIn: ['list', 'filter', 'show'],
26+
showIn: {
27+
edit: false,
28+
create: false,
29+
},
2730
},
2831
{
2932
name: 'email',
@@ -41,7 +44,10 @@ export default {
4144
{
4245
name: 'created_at',
4346
type: AdminForthDataTypes.DATETIME,
44-
showIn: ['list', 'filter', 'show'],
47+
showIn: [{
48+
edit: false,
49+
create: false,
50+
},
4551
fillOnCreate: ({ initialRecord, adminUser }) => (new Date()).toISOString(),
4652
},
4753
{
@@ -58,7 +64,11 @@ export default {
5864
required: { create: true }, // make required only on create page
5965
editingNote: { edit: 'Leave empty to keep password unchanged' },
6066
type: AdminForthDataTypes.STRING,
61-
showIn: ['create', 'edit'], // to show field only on create and edit pages
67+
showIn: { // to show field only on create and edit pages
68+
show: false,
69+
list: false,
70+
filter: false,
71+
},
6272
masked: true, // to show stars in input field
6373

6474
minLength: 8,
@@ -71,7 +81,7 @@ export default {
7181
name: 'password_hash',
7282
type: AdminForthDataTypes.STRING,
7383
backendOnly: true,
74-
showIn: []
84+
showIn: { all: false }
7585
}
7686
],
7787
hooks: {

adminforth/dataConnectors/baseConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
133133
for (const field of Object.keys(newValues)) {
134134
const col = resource.dataSourceColumns.find((col) => col.name == field);
135135
// todo instead of throwing error, we can just not use setFieldValue here, and pass original value to updateRecordOriginalValues
136-
// we might consider this because some users might not want to define all columns in resource with showIn:[], but still want to use them in hooks
136+
// we might consider this because some users might not want to define all columns in resource with showIn:{}, but still want to use them in hooks
137137
if (!col) {
138138
const similar = suggestIfTypo(resource.dataSourceColumns.map((col) => col.name), field);
139139
throw new Error(`

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ export default {
342342
name: 'id',
343343
primaryKey: true,
344344
fillOnCreate: () => randomUUID(),
345-
showIn: ['list', 'filter', 'show'],
345+
showIn: {
346+
edit: false,
347+
create: false,
348+
},
346349
},
347350
{
348351
name: 'email',
@@ -357,7 +360,10 @@ export default {
357360
{
358361
name: 'createdAt',
359362
type: AdminForthDataTypes.DATETIME,
360-
showIn: ['list', 'filter', 'show'],
363+
showIn: {
364+
edit: false,
365+
create: false,
366+
},
361367
fillOnCreate: () => (new Date()).toISOString(),
362368
},
363369
{
@@ -367,14 +373,18 @@ export default {
367373
editingNote: { edit: 'Leave empty to keep password unchanged' },
368374
minLength: 8,
369375
type: AdminForthDataTypes.STRING,
370-
showIn: ['create', 'edit'],
376+
showIn: {
377+
show: false,
378+
list: false,
379+
filter: false,
380+
},
371381
masked: true,
372382
validation: [
373383
// request to have at least 1 digit, 1 upper case, 1 lower case
374384
AdminForth.Utils.PASSWORD_VALIDATORS.UP_LOW_NUM,
375385
],
376386
},
377-
{ name: 'passwordHash', backendOnly: true, showIn: [] },
387+
{ name: 'passwordHash', backendOnly: true, showIn: { all: false } },
378388
{
379389
name: 'publicName',
380390
type: AdminForthDataTypes.STRING,
@@ -445,32 +455,43 @@ export default {
445455
name: 'id',
446456
primaryKey: true,
447457
fillOnCreate: () => randomUUID(),
448-
showIn: ['filter', 'show'],
458+
showIn: {
459+
list: false,
460+
edit: false,
461+
create: false,
462+
},
449463
},
450464
{
451465
name: 'title',
452466
required: true,
453-
showIn: ['list', 'create', 'edit', 'filter', 'show'],
467+
showIn: { all: true },
454468
maxLength: 255,
455469
minLength: 3,
456470
type: AdminForthDataTypes.STRING,
457471
},
458472
{
459473
name: 'picture',
460-
showIn: ['list', 'create', 'edit', 'filter', 'show'],
474+
showIn: { all: true },
461475
},
462476
{
463477
name: 'slug',
464-
showIn: ['filter', 'show'],
478+
showIn: {
479+
list: false,
480+
edit: false,
481+
create: false,
482+
},
465483
},
466484
{
467485
name: 'content',
468-
showIn: ['create', 'edit', 'filter', 'show'],
486+
showIn: { list: false },
469487
type: AdminForthDataTypes.RICHTEXT,
470488
},
471489
{
472490
name: 'createdAt',
473-
showIn: ['list', 'filter', 'show',],
491+
showIn: {
492+
edit: false,
493+
create: false,
494+
},
474495
fillOnCreate: () => (new Date()).toISOString(),
475496
},
476497
{
@@ -482,7 +503,11 @@ export default {
482503
foreignResource: {
483504
resourceId: 'user',
484505
},
485-
showIn: ['filter', 'show'],
506+
showIn: {
507+
list: false,
508+
edit: false,
509+
create: false,
510+
},
486511
fillOnCreate: ({ adminUser }: { adminUser: AdminUser }) => {
487512
return adminUser.dbUser.id;
488513
}
@@ -593,7 +618,10 @@ export default {
593618
foreignResource: {
594619
resourceId: 'post',
595620
},
596-
showIn: ['list', 'filter', 'show'],
621+
showIn: {
622+
edit: false,
623+
create: false,
624+
},
597625
},
598626
{
599627
name: 'resourceId',

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,18 @@ export default {
198198
name: 'id',
199199
type: AdminForthDataTypes.STRING,
200200
label: 'Identifier', // if you wish you can redefine label, defaulted to uppercased name
201-
showIn: ['filter', 'show'], // show column in filter and in show page
201+
showIn: { // show column in filter and in show page
202+
list: false,
203+
edit: false,
204+
create: false,
205+
},
202206
primaryKey: true,
203207
fillOnCreate: ({ initialRecord, adminUser }) => Math.random().toString(36).substring(7), // called during creation to generate content of field, initialRecord is values user entered, adminUser object of user who creates record
204208
},
205209
{
206210
name: 'title',
207211
required: true,
208-
showIn: ['list', 'create', 'edit', 'filter', 'show'], // all available options
212+
showIn: { all: false }, // all available options
209213
type: AdminForthDataTypes.STRING,
210214
maxLength: 255, // you can set max length for string fields
211215
minLength: 3, // you can set min length for string fields
@@ -214,7 +218,7 @@ export default {
214218
name: 'created_at',
215219
type: AdminForthDataTypes.DATETIME,
216220
allowMinMaxQuery: true,
217-
showIn: ['list', 'filter', 'show', 'edit'],
221+
showIn: { create: false },
218222
fillOnCreate: ({ initialRecord, adminUser }) => (new Date()).toISOString(),
219223
},
220224
{
@@ -243,7 +247,7 @@ export default {
243247
{
244248
name: 'description',
245249
sortable: false,
246-
showIn: ['show', 'edit', 'create', 'filter'],
250+
showIn: { list: false },
247251
},
248252
{
249253
name: 'country',

adminforth/documentation/docs/tutorial/01-helloWorld.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ export const admin = new AdminForth({
152152
name: 'id',
153153
primaryKey: true,
154154
fillOnCreate: () => Math.random().toString(36).substring(7),
155-
showIn: ['list', 'filter', 'show'],
155+
showIn: {
156+
edit: false,
157+
create: false,
158+
},
156159
},
157160
{
158161
name: 'email',
@@ -166,7 +169,10 @@ export const admin = new AdminForth({
166169
{
167170
name: 'createdAt',
168171
type: AdminForthDataTypes.DATETIME,
169-
showIn: ['list', 'filter', 'show'],
172+
showIn: {
173+
edit: false,
174+
create: false,
175+
},
170176
fillOnCreate: () => (new Date()).toISOString(),
171177
},
172178
{
@@ -183,10 +189,14 @@ export const admin = new AdminForth({
183189
editingNote: { edit: 'Leave empty to keep password unchanged' },
184190
minLength: 8,
185191
type: AdminForthDataTypes.STRING,
186-
showIn: ['create', 'edit'],
192+
showIn: {
193+
show: false,
194+
list: false,
195+
filter: false,
196+
},
187197
masked: true,
188198
},
189-
{ name: 'passwordHash', backendOnly: true, showIn: [] }
199+
{ name: 'passwordHash', backendOnly: true, showIn: { all: false } }
190200
],
191201
},
192202
{
@@ -200,23 +210,29 @@ export const admin = new AdminForth({
200210
name: 'id',
201211
primaryKey: true,
202212
fillOnCreate: () => Math.random().toString(36).substring(7),
203-
showIn: ['list', 'filter', 'show'],
213+
showIn: {
214+
edit: false,
215+
create: false,
216+
},
204217
},
205218
{
206219
name: 'title',
207220
type: AdminForthDataTypes.STRING,
208221
required: true,
209-
showIn: ['list', 'create', 'edit', 'filter', 'show'],
222+
showIn: { all: true },
210223
maxLength: 255,
211224
minLength: 3,
212225
},
213226
{
214227
name: 'content',
215-
showIn: ['list', 'create', 'edit', 'filter', 'show'],
228+
showIn: { all: true },
216229
},
217230
{
218231
name: 'createdAt',
219-
showIn: ['list', 'filter', 'show',],
232+
showIn: {
233+
edit: false,
234+
create: false,
235+
},
220236
fillOnCreate: () => (new Date()).toISOString(),
221237
},
222238
{
@@ -228,7 +244,10 @@ export const admin = new AdminForth({
228244
foreignResource: {
229245
resourceId: 'users',
230246
},
231-
showIn: ['list', 'filter', 'show'],
247+
showIn: {
248+
edit: false,
249+
create: false,
250+
},
232251
fillOnCreate: ({ adminUser }: { adminUser: AdminUser }) => {
233252
return adminUser.dbUser.id;
234253
}

adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ import { randomUUID } from 'crypto';
248248
{
249249
name: 'id',
250250
primaryKey: true,
251+
showIn: {
251252
//diff-remove
252-
showIn: ['filter', 'show'],
253-
//diff-add
254-
showIn: ['list', 'filter', 'show'],
253+
list: false,
254+
edit: false,
255+
create: false,
256+
},
255257
//diff-remove
256258
fillOnCreate: ({ initialRecord, adminUser }) => Math.random().toString(36).substring(7),
257259
//diff-add

adminforth/documentation/docs/tutorial/03-Customization/03-virtualColumns.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ columns: [
2525
//diff-add
2626
virtual: true,
2727
//diff-add
28-
showIn: [AdminForthResourcePages.show, AdminForthResourcePages.list],
28+
showIn: {
29+
//diff-add
30+
[AdminForthResourcePages.edit]: false,
31+
//diff-add
32+
[AdminForthResourcePages.create]: false,
33+
//diff-add
34+
[AdminForthResourcePages.filter]: false,
35+
//diff-add
36+
},
2937
//diff-add
3038
components: {
3139
//diff-add
@@ -89,7 +97,11 @@ columns: [
8997
editingNote: { edit: 'Leave empty to keep password unchanged' },
9098
minLength: 8,
9199
type: AdminForthDataTypes.STRING,
92-
showIn: ['create', 'edit'], // to show field only on create and edit pages
100+
showIn: { // to show field only on create and edit pages
101+
show: false,
102+
list: false,
103+
filter: false,
104+
},
93105
masked: true, // to show stars in input field
94106
}
95107
...
@@ -135,7 +147,7 @@ it will never pass this field to frontend.
135147
{
136148
name: 'password_hash',
137149
type: AdminForthDataTypes.STRING,
138-
showIn: [],
150+
showIn: { all: false },
139151
backendOnly: true, // will never go to frontend
140152
}
141153
```

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ import type { AdminUser } from 'adminforth';
7979
name: 'realtor_id',
8080
...
8181
//diff-add
82-
showIn: ['list', 'show', 'edit'], // don't even show this field in create
82+
showIn: { // don't even show this field in create
83+
//diff-add
84+
create: false,
85+
//diff-add
86+
filter: false,
87+
//diff-add
88+
},
8389
...
8490
},
8591
...

0 commit comments

Comments
 (0)