Skip to content

Commit

Permalink
Simplify construction of adminMeta value
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed May 7, 2020
1 parent 1ca8951 commit da66c4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-cows-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/app-admin-ui': patch
---

Refactored internals, no functional changes.
36 changes: 13 additions & 23 deletions packages/app-admin-ui/client/providers/AdminMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ export const AdminMetaProvider = ({ children }) => {
const listsByPath = {};
const getListByKey = key => listsByKey[key];

const adminMeta = {
adminPath,
apiPath,
graphiqlPath,
pages,
hooks,
signinPath,
signoutPath,
authStrategy,
name,
...customMeta,
listKeys: Object.keys(lists || {}),
getListByKey,
getListByPath: path => listsByPath[path],
readViews,
preloadViews,
};

const viewsToLoad = new Set();
if (typeof hookView === 'function') {
viewsToLoad.add(hookView);
Expand Down Expand Up @@ -102,17 +84,25 @@ export const AdminMetaProvider = ({ children }) => {
}

const hookPages = hookViews.pages ? hookViews.pages() : [];
const adminMetaPages = adminMeta.pages ? adminMeta.pages : [];
const adminMetaPages = pages || [];

const value = {
...adminMeta,
adminPath,
apiPath,
graphiqlPath,
signinPath,
signoutPath,
authStrategy,
name,
listKeys: Object.keys(lists || {}),
getListByKey,
getListByPath: path => listsByPath[path],
hooks: hookViews,
pages: resolveCustomPages([...adminMetaPages, ...hookPages]),
...customMeta,
};

return <AdminMetaContext.Provider value={value}>{children}</AdminMetaContext.Provider>;
};

export const useAdminMeta = () => {
return useContext(AdminMetaContext);
};
export const useAdminMeta = () => useContext(AdminMetaContext);

0 comments on commit da66c4b

Please sign in to comment.