-
Notifications
You must be signed in to change notification settings - Fork 5
[Content] Content item Redirects tab #3514
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
Open
finnar-bin
wants to merge
16
commits into
dev
Choose a base branch
from
feature/3422-content-item-redirects-tab
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d12494b
Added redirects tab
finnar-bin 5d03b81
Render table data
finnar-bin f8036c9
Update cell render
finnar-bin e7ed026
Update action menu items
finnar-bin fe38b97
Merge branch 'dev' into feature/3422-content-item-redirects-tab
finnar-bin 81245c2
Update redirects tab icon
finnar-bin 7cb51bb
Added delete redirect flow
finnar-bin 2360632
Merge branch 'dev' into feature/3422-content-item-redirects-tab
finnar-bin bbdaa9c
Use redirects app components for edit redirect
finnar-bin d104af0
Clean up
finnar-bin 800e62b
Merge branch 'dev' into feature/3422-content-item-redirects-tab
finnar-bin 9d9c1cc
Add content item redirects tab tests
finnar-bin bb137bd
Remove unused imports
finnar-bin b52e48e
Merge branch 'dev' into feature/3422-content-item-redirects-tab
finnar-bin efcdd06
Simplified more actions click handler
finnar-bin 88cacb9
Merge branch 'dev' into feature/3422-content-item-redirects-tab
finnar-bin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const NOW = new Date().getTime(); | ||
|
||
describe("Content item redirects", () => { | ||
before(() => { | ||
// Create a new redirect | ||
cy.waitOn("/v1/web/redirects", () => { | ||
cy.visit("/redirects"); | ||
}); | ||
|
||
cy.intercept("/v1/web/redirects").as("redirects"); | ||
cy.getBySelector("RedirectActionCreateButton").click(); | ||
cy.getBySelector("RedirectsFieldPath") | ||
.find("input") | ||
.type(`/test-redirect/${NOW}`); | ||
cy.getBySelector("RedirectsSearchFieldInputField").find("input").click(); | ||
cy.wait(2000); | ||
cy.getBySelector("RedirectsSearchFieldInputField") | ||
.find("input") | ||
.type("all field types{downArrow}{enter}"); | ||
cy.getBySelector("RedirectsCreateButton").click(); | ||
cy.wait("@redirects"); | ||
}); | ||
|
||
it("should show redirects for a content item", () => { | ||
cy.waitOn("/v1/content/models*", () => { | ||
cy.visit("/content/6-556370-8sh47g/7-b939a4-457q19/redirects"); | ||
}); | ||
|
||
cy.contains(`/test-redirect/${NOW}`, { timeout: 10000 }).should("exist"); | ||
}); | ||
|
||
it("should be able to edit a redirect", () => { | ||
cy.intercept("/v1/web/redirects").as("redirects"); | ||
cy.contains(`/test-redirect/${NOW}`) | ||
.parent() | ||
.within(() => { | ||
cy.get(".MuiDataGrid-actionsCell button").click(); | ||
}); | ||
cy.getBySelector("EditRedirect").click(); | ||
cy.getBySelector("RedirectsFieldPath").find("input").type(`/updated`); | ||
cy.getBySelector("RedirectsCreateButton").click({ timeout: 10000 }); | ||
|
||
cy.wait("@redirects"); | ||
|
||
cy.contains(`/test-redirect/${NOW}/updated`, { timeout: 10000 }).should( | ||
"exist" | ||
); | ||
}); | ||
|
||
it("should be able to delete a redirect", () => { | ||
cy.intercept("/v1/web/redirects").as("redirects"); | ||
cy.get(".MuiDataGrid-actionsCell button").last().click(); | ||
cy.getBySelector("DeleteRedirect").click(); | ||
cy.getBySelector("ConfirmDeleteRedirect").click(); | ||
|
||
cy.wait("@redirects").then(() => { | ||
cy.get(".MuiDataGrid-cell") | ||
.contains(`/test-redirect/${NOW}/updated`, { timeout: 10000 }) | ||
.should("not.exist"); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
src/apps/content-editor/src/app/views/Redirects/DeleteRedirectModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import { useEffect } from "react"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogTitle, | ||
Typography, | ||
Box, | ||
Stack, | ||
Button, | ||
DialogActions, | ||
Link, | ||
} from "@mui/material"; | ||
import { DeleteRounded, Description, HiveRounded } from "@mui/icons-material"; | ||
import { LoadingButton } from "@mui/lab"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { useDomain } from "../../../../../../shell/hooks/use-domain"; | ||
import { useDeleteRedirectMutation } from "../../../../../../shell/services/instance"; | ||
import { notify } from "../../../../../../shell/store/notifications"; | ||
import { RedirectsTargetType } from "../../../../../../shell/services/types"; | ||
|
||
const HTTP_CODE_OPTIONS = { | ||
301: "301 - Permanent Redirect", | ||
302: "302 - Temporary Redirect", | ||
} as const; | ||
|
||
type DeleteRedirectModalProps = { | ||
targetPath: string; | ||
incomingPath: string; | ||
ZUID: string; | ||
httpCode: number; | ||
targetType: RedirectsTargetType; | ||
onClose: () => void; | ||
}; | ||
export const DeleteRedirectModal = ({ | ||
targetPath, | ||
incomingPath, | ||
ZUID, | ||
httpCode, | ||
targetType, | ||
onClose, | ||
}: DeleteRedirectModalProps) => { | ||
const domain = useDomain(); | ||
const dispatch = useDispatch(); | ||
const [ | ||
deleteRedirect, | ||
{ isLoading: isDeletingRedirect, isSuccess: isRedirectDeleted }, | ||
] = useDeleteRedirectMutation(); | ||
|
||
useEffect(() => { | ||
if (isRedirectDeleted) { | ||
onClose(); | ||
dispatch( | ||
notify({ | ||
message: `Redirect Deleted: ${incomingPath}`, | ||
kind: "error", | ||
}) | ||
); | ||
} | ||
}, [isRedirectDeleted]); | ||
|
||
const handleDelete = () => { | ||
deleteRedirect({ ZUID }); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
open | ||
slotProps={{ | ||
paper: { | ||
sx: { | ||
maxWidth: 480, | ||
}, | ||
}, | ||
}} | ||
onClose={onClose} | ||
> | ||
<DialogTitle> | ||
<Stack gap={1.5}> | ||
<Box | ||
sx={{ | ||
backgroundColor: "red.100", | ||
borderRadius: "100%", | ||
width: "40px", | ||
height: "40px", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<DeleteRounded color="error" /> | ||
</Box> | ||
<Box> | ||
<Box mb={1}> | ||
<Typography variant="h5" display="inline" fontWeight={700}> | ||
Delete Redirect: | ||
</Typography> | ||
<Typography variant="h5" display="inline"> | ||
{incomingPath} | ||
</Typography> | ||
</Box> | ||
<Typography variant="body2" color="text.secondary"> | ||
Deleting this redirect will remove it immediately from your site. | ||
This action cannot be undone. | ||
</Typography> | ||
</Box> | ||
</Stack> | ||
</DialogTitle> | ||
<DialogContent> | ||
<Typography variant="body2" fontWeight={700} mb={2.5}> | ||
More details | ||
</Typography> | ||
<Stack width="100%" border={1} borderColor="border" borderRadius={2}> | ||
<Stack direction="row" height={54} alignItems="center" px={2}> | ||
<Typography | ||
variant="body2" | ||
fontWeight={700} | ||
sx={{ flexBasis: 160 }} | ||
> | ||
HTTP Code | ||
</Typography> | ||
<Typography variant="body2" sx={{ flex: 1 }}> | ||
{HTTP_CODE_OPTIONS[httpCode as keyof typeof HTTP_CODE_OPTIONS]} | ||
</Typography> | ||
</Stack> | ||
<Stack | ||
direction="row" | ||
height={54} | ||
alignItems="center" | ||
borderTop={1} | ||
borderBottom={1} | ||
borderColor="border" | ||
px={2} | ||
> | ||
<Typography | ||
variant="body2" | ||
fontWeight={700} | ||
sx={{ flexBasis: 160 }} | ||
> | ||
Redirect Type | ||
</Typography> | ||
<RedirectType type={targetType} /> | ||
</Stack> | ||
<Stack direction="row" height={54} alignItems="center" px={2}> | ||
<Typography | ||
variant="body2" | ||
fontWeight={700} | ||
sx={{ flexBasis: 160 }} | ||
> | ||
Redirect Target | ||
</Typography> | ||
<Link | ||
variant="body2" | ||
href={`${domain}${targetPath}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
sx={{ flex: 1 }} | ||
> | ||
{targetPath} | ||
</Link> | ||
</Stack> | ||
</Stack> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
variant="text" | ||
color="inherit" | ||
onClick={onClose} | ||
disabled={isDeletingRedirect} | ||
> | ||
Cancel | ||
</Button> | ||
<LoadingButton | ||
data-cy="ConfirmDeleteRedirect" | ||
variant="contained" | ||
color="error" | ||
onClick={handleDelete} | ||
loading={isDeletingRedirect} | ||
> | ||
Delete Forever | ||
</LoadingButton> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
const RedirectType = ({ type }: { type: RedirectsTargetType }) => { | ||
if (type === "path") { | ||
return ( | ||
<Stack direction="row" alignItems="center" gap={1.5}> | ||
<HiveRounded fontSize="small" color="action" /> | ||
<Typography variant="body2" sx={{ flex: 1 }}> | ||
Wildcard | ||
</Typography> | ||
</Stack> | ||
); | ||
} | ||
|
||
if (type === "page") { | ||
return ( | ||
<Stack direction="row" alignItems="center" gap={1.5}> | ||
<Description fontSize="small" color="action" /> | ||
<Typography variant="body2" sx={{ flex: 1 }}> | ||
Internal | ||
</Typography> | ||
</Stack> | ||
); | ||
} | ||
|
||
return <></>; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.