From 74600f0eb53282d0b28505336112ba81fc247f3c Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 4 Jan 2021 13:14:45 +0800 Subject: [PATCH] fix: filter developer mode with isTruly/isFalsy --- .../plugin-pages/src/actions/getCollection.ts | 2 +- .../plugin-pages/src/actions/getRoutes.ts | 4 +- packages/plugin-pages/src/actions/getView.ts | 47 +++++++++++-------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/plugin-pages/src/actions/getCollection.ts b/packages/plugin-pages/src/actions/getCollection.ts index 4677204263..e821785234 100644 --- a/packages/plugin-pages/src/actions/getCollection.ts +++ b/packages/plugin-pages/src/actions/getCollection.ts @@ -19,7 +19,7 @@ export default async (ctx, next) => { const options = Tab.parseApiJson({ filter: { enabled: true, - developerMode: ctx.state.developerMode, + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, }, fields: { appends: ['associationField'], diff --git a/packages/plugin-pages/src/actions/getRoutes.ts b/packages/plugin-pages/src/actions/getRoutes.ts index d331c0e2a0..65547fa563 100644 --- a/packages/plugin-pages/src/actions/getRoutes.ts +++ b/packages/plugin-pages/src/actions/getRoutes.ts @@ -42,7 +42,7 @@ export default async function getRoutes(ctx, next) { const Collection = database.getModel('collections'); let pages = await Page.findAll(Page.parseApiJson({ filter: { - 'developerMode': ctx.state.developerMode, + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, }, sort: ['sort'], })); @@ -52,7 +52,7 @@ export default async function getRoutes(ctx, next) { if (page.get('path') === '/collections') { const collections = await Collection.findAll(Collection.parseApiJson({ filter: { - developerMode: ctx.state.developerMode, + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, showInDataMenu: true, }, sort: ['sort'], diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 08068820f8..9c92c5d9ae 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -38,13 +38,14 @@ const transforms = { } if (field.get('name') === 'filter' && field.get('collection_name') === 'views') { const { values } = ctx.action.params; - const all = await Field.findAll({ - where: { + const options = Field.parseApiJson({ + filter: { collection_name: get(values, 'associatedKey'), - developerMode: ctx.state.developerMode, + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, }, - order: [['sort', 'asc']], + sort: 'sort', }); + const all = await Field.findAll(options); set(prop, 'x-component-props.fields', all.filter(f => f.get('filterable'))); } if (type === 'select') { @@ -160,20 +161,22 @@ export default async (ctx, next) => { name: resourceName, }, }); - const where: any = { - developerMode: ctx.state.developerMode, + // const where: any = { + // developerMode: ctx.state.developerMode, + // } + const filter: any = { + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, } if (!view.get('draggable')) { - where.type = { - [Op.not]: 'sort', + filter.type = { + not: 'sort', }; } - let fields = await collection.getFields({ - where, - order: [ - ['sort', 'asc'], - ] + const fieldOptions = Field.parseApiJson({ + filter, + sort: 'sort', }); + let fields = await collection.getFields(fieldOptions); fields = fields.filter(field => { if (field.get('interface') === 'linkTo') { if (throughName && throughName === field.get('through')) { @@ -182,18 +185,18 @@ export default async (ctx, next) => { } return true; }) - const actions = await collection.getActions({ - where: { - developerMode: ctx.state.developerMode, + const options = Action.parseApiJson({ + filter: { + developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true}, }, - order: [ - ['sort', 'asc'], - ] + sort: 'sort', }); + const actions = await collection.getActions(options); let actionNames = view.get('actionNames') || []; if (actionNames.length === 0) { actionNames = ['filter', 'create', 'destroy']; } + if (view.get('type') === 'table') { const defaultTabs = await collection.getTabs({ where: { @@ -202,10 +205,14 @@ export default async (ctx, next) => { }); view.setDataValue('defaultTabName', get(defaultTabs, [0, 'name'])); } - + if (view.get('type') === 'table') { view.setDataValue('rowViewName', 'form'); } + if (view.get('type') === 'calendar') { + view.setDataValue('template', 'Calendar'); + view.setDataValue('rowViewName', 'form'); + } if (view.get('updateViewName')) { view.setDataValue('rowViewName', view.get('updateViewName')); }