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

fix: don't show edit link for pending maps (will result in 404) #1753

Merged
merged 5 commits into from
Apr 10, 2024
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
2 changes: 1 addition & 1 deletion src/home/components/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test('Home: Display Story Maps', async () => {
expect(items.length).toBe(2);

const link1 = within(items[0]).getByRole('link', { name: 'Story 2' });
expect(link1).toHaveAttribute('href', '/tools/story-maps/lftawa9/id-2');
expect(link1).toHaveAttribute('href', '/tools/story-maps/lftawa9/id-2/edit');
const link2 = within(items[1]).getByRole('link', { name: 'Story 1' });
expect(link2).toHaveAttribute('href', '/tools/story-maps/46h36we/id-1/edit');
});
Expand Down
33 changes: 21 additions & 12 deletions src/storyMap/components/StoryMapsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const StoryMapListItem = props => {
[storyMap.membershipInfo.accountMembership]
);

const isPending = useMemo(
const isStoryMapMembershipPending = useMemo(
() => accountMembership?.membershipStatus === MEMBERSHIP_STATUS_PENDING,
[accountMembership]
);
Expand Down Expand Up @@ -165,16 +165,25 @@ const StoryMapListItem = props => {
)}
<CollaborationIndicator storyMap={storyMap} />
</Stack>
<RouterLink
id={`story-map-${storyMap.slug}-link`}
to={
storyMap.isPublished
? generateStoryMapUrl(storyMap)
: generateStoryMapEditUrl(storyMap)
}
>
{storyMap.title}
</RouterLink>
{/*
Unpublished drafts you have not accepted get no link, as it would 404.
Published and not accepted get a view link.
Published and accepted get an edit link.
*/}
{!storyMap.isPublished && isStoryMapMembershipPending ? (
storyMap.title
) : (
<RouterLink
id={`story-map-${storyMap.slug}-link`}
to={
isStoryMapMembershipPending
? generateStoryMapUrl(storyMap)
: generateStoryMapEditUrl(storyMap)
}
>
{storyMap.title}
</RouterLink>
)}
<Typography
variant="caption"
sx={{
Expand All @@ -199,7 +208,7 @@ const StoryMapListItem = props => {
spacing={2}
>
<Grid item xs={6}>
{isPending ? (
{isStoryMapMembershipPending ? (
<LoadingButton
size="small"
variant="outlined"
Expand Down
4 changes: 2 additions & 2 deletions src/storyMap/components/StoryMapsToolHome.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ test('StoryMapsToolHome: user story maps render correctly', async () => {
expect(items.length).toBe(2);

const link2 = within(items[0]).getByRole('link', { name: 'Story 2' });
expect(link2).toHaveAttribute('href', '/tools/story-maps/lftawa9/id-2');
expect(link2).toHaveAttribute('href', '/tools/story-maps/lftawa9/id-2/edit');
const link1 = within(items[1]).getByRole('link', { name: 'Story 1' });
expect(link1).toHaveAttribute('href', '/tools/story-maps/46h36we/id-1/edit');
});
Expand Down Expand Up @@ -234,7 +234,7 @@ test('StoryMapsToolHome: accept story map invite', async () => {
},
});

const storyMapItem = screen.getByRole('listitem', { name: 'Story 1' });
const storyMapItem = screen.getByRole('listitem', { name: '' });

const acceptButton = within(storyMapItem).getByRole('button', {
name: 'Accept',
Expand Down
Loading