Skip to content

Commit

Permalink
Merge pull request #1128 from jay-hodgson/SWC-7026
Browse files Browse the repository at this point in the history
SWC-7026: optional callback on toggling experimental mode
  • Loading branch information
jay-hodgson authored Aug 13, 2024
2 parents b59ab58 + 6f1e2f9 commit 2b95dad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { useTheme } from '@mui/material'
const experimentalModeText =
'This mode gives you early access to features that are still in development. Please note that we do not guarantee an absence of errors, and that the data created using these features may be lost during product upgrade.'

const ExperimentalMode: React.FC = () => {
export type ExperimentalModeProps = {
onExperimentalModeToggle?: (newValue: boolean) => void
}
const ExperimentalMode: React.FunctionComponent<ExperimentalModeProps> = ({
onExperimentalModeToggle,
}) => {
const [isExperimentalModeOn, setIsExperimentalModeOn] =
useState<boolean>(false)
const cookies = new UniversalCookies()
Expand All @@ -31,12 +36,18 @@ const ExperimentalMode: React.FC = () => {
const createExperimentalModeCookie = () => {
cookies.set(EXPERIMENTAL_MODE_COOKIE, { path: '/' })
setIsExperimentalModeOn(true)
if (onExperimentalModeToggle) {
onExperimentalModeToggle(true)
}
}

const deleteExperimentalModeCookie = () => {
// cookie.remove requires to re-calculate date obj each time, this is more straightforward
document.cookie = `${EXPERIMENTAL_MODE_COOKIE}= ; expires = Thu, 01 Jan 1970 00:00:00 GMT`
setIsExperimentalModeOn(false)
if (onExperimentalModeToggle) {
onExperimentalModeToggle(false)
}
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ export const Demo: Story = {
gotoPlace: (href: string) => {
window.alert(`Footer calling back to change route to ${href}`)
},
onExperimentalModeToggle: (newMode: boolean) => {
window.alert(
`Footer calling back to toggle experimental mode to ${newMode}`,
)
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type SynapseFooterProps = {
srcVersion: string
repoVersion: string
gotoPlace: (href: string) => void
onExperimentalModeToggle: (newValue: boolean) => void
}

const currentYear = new Date().getFullYear()
Expand All @@ -26,6 +27,7 @@ export const SynapseFooter: React.FunctionComponent<SynapseFooterProps> = ({
srcVersion,
repoVersion,
gotoPlace,
onExperimentalModeToggle,
}) => {
const { accessToken } = useSynapseContext()
const registrationUrl = useOneSageURL('/register1')
Expand Down Expand Up @@ -298,7 +300,7 @@ export const SynapseFooter: React.FunctionComponent<SynapseFooterProps> = ({
repo: {repoVersion}
</Typography>
</Box>
<ExperimentalMode />
<ExperimentalMode onExperimentalModeToggle={onExperimentalModeToggle} />
</Box>
</Box>
)
Expand Down

0 comments on commit 2b95dad

Please sign in to comment.