Skip to content

Commit

Permalink
refactor: Remove userId param
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Dec 7, 2023
1 parent fc7769e commit b58f57b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,18 @@ test('select user sites with project role', () => {
test('select user role when site owned', () => {
const user = generateUser();
const site = generateSite({ owner: user });
const store = createStore(initState([], [user], [site]));
const store = createStore(initState([], [user], [site], user.id));

const siteRole = selectUserRoleSite(store.getState(), site.id, user.id);
const siteRole = selectUserRoleSite(store.getState(), site.id);
expect(siteRole).toStrictEqual({ kind: 'site', role: 'owner' });
});

test('select user role in project of site', () => {
const user = generateUser();
const project = generateProject([generateMembership(user.id, 'viewer')]);
const site = generateSite({ project });
const store = createStore(initState([project], [user], [site]));
const store = createStore(initState([project], [user], [site], user.id));

const siteRole = selectUserRoleSite(store.getState(), site.id, user.id);
const siteRole = selectUserRoleSite(store.getState(), site.id);
expect(siteRole).toStrictEqual({ kind: 'project', role: 'viewer' });
});
9 changes: 3 additions & 6 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ export type SiteUserRole =
| { kind: 'site'; role: 'owner' }
| { kind: 'project'; role: UserRole };

const selectSiteId = (_state: any, siteId: string, userId: string) => [
siteId,
userId,
];
const selectSiteId = (_state: any, siteId: string) => siteId;

export const selectUserRoleSite = createSelector(
[selectSites, selectProjects, selectSiteId],
(sites, projects, [siteId, userId]) => {
[selectSites, selectProjects, selectSiteId, selectCurrentUserID],
(sites, projects, siteId, userId) => {
const site = sites[siteId];
if (!site) {
return null;
Expand Down

0 comments on commit b58f57b

Please sign in to comment.