Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Keystone.getAdminViews() #2893

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/curly-pumpkins-call.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 4 additions & 7 deletions packages/app-admin-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
10 changes: 10 additions & 0 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/keystone/lib/List/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 0 additions & 36 deletions packages/keystone/tests/List.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() `, () => {
Expand Down