Skip to content

Commit

Permalink
feat: Include unaffiliated sites
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Oct 27, 2023
1 parent 2e4c775 commit 2bbb0d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ const generateProject = (
};
};

const generateSite = (project: Project): Site => {
const generateSite = (project?: Project): Site => {
const id = uuidv4();
const site: Site = {
projectId: project.id,
projectId: project?.id,
ownerId: undefined,
id,
name: 'Test Site',
Expand All @@ -68,7 +68,9 @@ const generateSite = (project: Project): Site => {
archived: false,
updatedAt: '2023-10-24',
};
project.sites[site.id] = true;
if (project !== undefined) {
project.sites[site.id] = true;
}
return site;
};

Expand Down Expand Up @@ -157,9 +159,10 @@ test('can access all projects with role', () => {
const project3 = generateProject([generateMembership(user.id, 'manager')]);
const site1 = generateSite(project1);
const site2 = generateSite(project2);
const site3 = generateSite();

const store = createStore(
initState([project1, project2, project3], [user], [site1, site2]),
initState([project1, project2, project3], [user], [site1, site2, site3]),
);
const pairs = selectProjectsWithTransferrableSites(
store.getState(),
Expand All @@ -178,5 +181,6 @@ test('can access all projects with role', () => {
siteName: site1.name,
},
],
unaffiliatedSites: [{ siteId: site3.id, siteName: site3.name }],
});
});
8 changes: 6 additions & 2 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ export const selectProjectsWithTransferrableSites = createSelector(
};
}),
);
let projectRecord = projects.reduce(

const unaffiliatedSites = Object.values(sites)
.filter(({ projectId }) => projectId === undefined)
.map(({ id, name }) => ({ siteId: id, siteName: name }));
const projectRecord = projects.reduce(
(x, { id, name }) => ({
...x,
[id]: { projectId: id, projectName: name },
}),
{} as Record<string, { projectId: string; projectName: string }>,
);
return { projects: projectRecord, sites: projectSites };
return { projects: projectRecord, sites: projectSites, unaffiliatedSites };
},
);

0 comments on commit 2bbb0d0

Please sign in to comment.