-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Add Preview/Draft Layout Wrapper for Testing Links #4090
Open
RODO94
wants to merge
7
commits into
main
Choose a base branch
from
rory/preview-wrapper
base: main
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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
557c9e9
initial wiring
RODO94 e9c3fe0
add subdomain logic for published link
RODO94 8985c45
variable renaming and url refinement
RODO94 e1349ad
switch window.open with react-navi
RODO94 bb506d9
add warning page to Draft view
RODO94 b1f10fc
refine logic in Card component
RODO94 30fbf51
add param description to Card
RODO94 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 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
34 changes: 34 additions & 0 deletions
34
editor.planx.uk/src/@planx/components/shared/Preview/NavigateToPublishedButton.tsx
This file contains 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,34 @@ | ||
import Link from "@mui/material/Link"; | ||
import Typography from "@mui/material/Typography"; | ||
import React from "react"; | ||
|
||
import { InnerContainer } from "./SaveResumeButton"; | ||
|
||
const NavigateToPublishedButton: React.FC = () => { | ||
const testEnvironment = window.location.pathname.endsWith("/draft") | ||
? "/draft" | ||
: "/preview"; | ||
|
||
const editorLink = window.location.pathname.replace( | ||
testEnvironment, | ||
"/published", | ||
) as `/${string}`; | ||
RODO94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const redirectLink = `${window.location.origin}${editorLink}`; | ||
RODO94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const handleClick = () => { | ||
window.open(redirectLink, "_blank"); | ||
}; | ||
|
||
return ( | ||
<InnerContainer> | ||
<Typography variant="body1">or</Typography> | ||
<Link onClick={handleClick} component="button"> | ||
<Typography variant="body1" textAlign="left"> | ||
Go to the live service | ||
</Typography> | ||
</Link> | ||
</InnerContainer> | ||
); | ||
}; | ||
|
||
export default NavigateToPublishedButton; |
This file contains 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 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,24 @@ | ||
import Box from "@mui/material/Box"; | ||
import Card from "@planx/components/shared/Preview/Card"; | ||
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader"; | ||
import React, { PropsWithChildren, useState } from "react"; | ||
|
||
export const TestWarningPage = ({ children }: PropsWithChildren) => { | ||
const [showChildren, setShowChildren] = useState(false); | ||
return ( | ||
<> | ||
{showChildren ? ( | ||
children | ||
) : ( | ||
RODO94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Box width="100%"> | ||
<Card handleSubmit={() => setShowChildren(true)} isTestWrapper={true}> | ||
<CardHeader | ||
title="This is a test environment" | ||
description="This version of the service is unpublished and for testing only. Do not use it to submit real applications" | ||
></CardHeader> | ||
</Card> | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is now shared, it should be its own component.
Generally we'd try to avoid feature to feature imports like this. The main reason being that when I make a change in future on this component it's not inherently obvious that it's going to have a knock on effect in an unrelated component.
A few options here - we could repeat the style, extract it to its own very simple component, or make a component which is the "or" text option which then takes in a callback function. I think the later is the best option here as it keeps an "or" text options consistent and we could control within the card that it only shows once and doesn't stack as is currently possible.
How about a component which took in a condition (to decide if it's shown or hidden) and a callback (to be called when clicked), which is then passed into the
Card
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great comment, thanks for the suggestions here. @DafyddLlyr
This may be an indulgence at the wrong time, but I've been reading a bit on decoupling code for maintainability and thus, taken a slightly different approach using the comment as inspo.
I wanted to keep the handleClick logic within each
SaveAndResumeButton
andNavigateToPublishedButton
so they could expand or become more complex in future without bloating out theCard
and it means the components can focus on doing one thing well at a time.I have put in an extra component,
OrNavigationButton
to handle the logic of the displaying either button based on atype
it receives from theCard
component, so it again just does one wee thing well. TheCard
comp can then do a small function to define what type to show.Lemme know if I've led myself astray and you're suggestion is a cleaner way of doing what I was hoping to do!