From b716d96eff5dd14074d383b74507218e6833ea48 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Tue, 5 May 2020 15:14:23 +1000 Subject: [PATCH 1/2] Add Keystone.getAdminViews() --- .changeset/curly-pumpkins-call.md | 6 ++++++ packages/app-admin-ui/index.js | 11 ++++------- packages/keystone/lib/Keystone/index.js | 10 ++++++++++ packages/keystone/lib/List/index.js | 1 - 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 .changeset/curly-pumpkins-call.md diff --git a/.changeset/curly-pumpkins-call.md b/.changeset/curly-pumpkins-call.md new file mode 100644 index 00000000000..e4c3b2962f1 --- /dev/null +++ b/.changeset/curly-pumpkins-call.md @@ -0,0 +1,6 @@ +--- +'@keystonejs/app-admin-ui': major +'@keystonejs/keystone': major +--- + +Added a method `Keystone.getAdminViews({ schemaName })` which returns the views for the Admin UI. `List.getAdminMeta()` no longer returns a `views` values. diff --git a/packages/app-admin-ui/index.js b/packages/app-admin-ui/index.js index d9cee1f6c8a..76a69499ec2 100644 --- a/packages/app-admin-ui/index.js +++ b/packages/app-admin-ui/index.js @@ -120,13 +120,10 @@ class AdminUIApp { getAdminViews({ keystone, includeLists }) { const { pages, hooks } = this; - const { lists } = keystone.getAdminMeta({ schemaName: this._schemaName }); - const listViews = includeLists - ? Object.entries(lists).reduce( - (obj, [listPath, { views }]) => ({ ...obj, [listPath]: views }), - {} - ) - : {}; + const { listViews } = includeLists + ? keystone.getAdminViews({ schemaName: this._schemaName }) + : { listViews: {} }; + return { pages, hooks, listViews }; } diff --git a/packages/keystone/lib/Keystone/index.js b/packages/keystone/lib/Keystone/index.js index 4802d154610..42b368e099f 100644 --- a/packages/keystone/lib/Keystone/index.js +++ b/packages/keystone/lib/Keystone/index.js @@ -490,6 +490,16 @@ module.exports = class Keystone { return { lists, name: this.name }; } + getAdminViews({ schemaName }) { + return { + listViews: arrayToObject( + this.listsArray.filter(list => list.access[schemaName].read && !list.isAuxList), + 'key', + list => list.views + ), + }; + } + // It's not Keystone core's responsibility to create an executable schema, but // once one is, Keystone wants to be able to expose the ability to query that // schema, so this function enables other modules to register that function. diff --git a/packages/keystone/lib/List/index.js b/packages/keystone/lib/List/index.js index a0c13431d1c..d2c70b3839a 100644 --- a/packages/keystone/lib/List/index.js +++ b/packages/keystone/lib/List/index.js @@ -346,7 +346,6 @@ module.exports = class List { fields: this.fields .filter(field => field.access[schemaName].read) .map(field => field.getAdminMeta({ schemaName })), - views: this.views, adminDoc: this.adminDoc, adminConfig: { defaultPageSize, From 1dc1320ac019ea2307d3520efc39fbc60ed663a9 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Wed, 6 May 2020 09:57:59 +1000 Subject: [PATCH 2/2] Remove obsolete test --- packages/keystone/tests/List.test.js | 36 ---------------------------- 1 file changed, 36 deletions(-) diff --git a/packages/keystone/tests/List.test.js b/packages/keystone/tests/List.test.js index b448249530a..7f112a55a37 100644 --- a/packages/keystone/tests/List.test.js +++ b/packages/keystone/tests/List.test.js @@ -474,42 +474,6 @@ describe('getAdminMeta()', () => { expect(adminMeta.fields[3].path).toEqual('other'); expect(adminMeta.fields[4].path).toEqual('writeOnce'); }); - - test('getAdminMeta() - views', () => { - const list = setup(); - const schemaName = 'public'; - const adminMeta = list.getAdminMeta({ schemaName }); - - expect(adminMeta.views).toEqual({ - id: {}, // Mocked - name: { - Controller: resolveViewPath('Text/views/Controller'), - Field: resolveViewPath('Text/views/Field'), - Filter: resolveViewPath('Text/views/Filter'), - }, - email: { - Controller: resolveViewPath('Text/views/Controller'), - Field: resolveViewPath('Text/views/Field'), - Filter: resolveViewPath('Text/views/Filter'), - }, - other: { - Controller: resolveViewPath('Relationship/views/Controller'), - Field: resolveViewPath('Relationship/views/Field'), - Filter: resolveViewPath('Relationship/views/Filter'), - Cell: resolveViewPath('Relationship/views/Cell'), - }, - hidden: { - Controller: resolveViewPath('Text/views/Controller'), - Field: resolveViewPath('Text/views/Field'), - Filter: resolveViewPath('Text/views/Filter'), - }, - writeOnce: { - Controller: resolveViewPath('Text/views/Controller'), - Field: resolveViewPath('Text/views/Field'), - Filter: resolveViewPath('Text/views/Filter'), - }, - }); - }); }); describe(`getGqlTypes() `, () => {