-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
195 additions
and
246 deletions.
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
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { ROUTES } from '@novu/shared-web'; | ||
import { FC } from 'react'; | ||
import { LocalNavMenu } from '../../studio/components/LocalNavMenu'; | ||
import { RootNavMenu } from './RootNavMenu'; | ||
import { SettingsNavMenu } from './SettingsNavMenu'; | ||
import { SidebarNav } from './SidebarNav'; | ||
|
||
export const MainNav: FC = () => { | ||
return <SidebarNav root={<RootNavMenu />} routeMenus={{ [ROUTES.SETTINGS]: <SettingsNavMenu /> }} />; | ||
return ( | ||
<SidebarNav | ||
root={<RootNavMenu />} | ||
routeMenus={{ [ROUTES.SETTINGS]: <SettingsNavMenu />, [ROUTES.STUDIO]: <LocalNavMenu /> }} | ||
/> | ||
); | ||
}; |
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
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
53 changes: 53 additions & 0 deletions
53
apps/web/src/studio/components/EnvironmentSelect/EnvironmentSelect.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,53 @@ | ||
import { Select, When } from '@novu/design-system'; | ||
import { css } from '@novu/novui/css'; | ||
import { navSelectStyles } from '../../../components/nav/NavSelect.styles'; | ||
import { EnvironmentPopover } from '../../../components/nav/EnvironmentSelect/EnvironmentPopover'; | ||
import { useEnvironmentSelect } from './useEnvironmentSelect'; | ||
|
||
export const EnvironmentSelectRenderer: React.FC<ReturnType<typeof useEnvironmentSelect>> = ({ | ||
icon, | ||
isPopoverOpened, | ||
setIsPopoverOpened, | ||
handlePopoverLinkClick, | ||
...selectProps | ||
}) => { | ||
return ( | ||
<EnvironmentPopover | ||
isPopoverOpened={isPopoverOpened} | ||
setIsPopoverOpened={setIsPopoverOpened} | ||
handlePopoverLinkClick={handlePopoverLinkClick} | ||
> | ||
<Select | ||
className={navSelectStyles} | ||
data-test-id="environment-switch" | ||
allowDeselect={false} | ||
icon={ | ||
<When truthy={!selectProps.loading}> | ||
<span | ||
className={css({ | ||
p: '50', | ||
borderRadius: '50', | ||
bg: 'surface.page', | ||
'& svg': { | ||
fill: 'typography.text.main', | ||
}, | ||
_after: { | ||
width: '100', | ||
}, | ||
})} | ||
> | ||
{icon} | ||
</span> | ||
</When> | ||
} | ||
{...selectProps} | ||
/> | ||
</EnvironmentPopover> | ||
); | ||
}; | ||
|
||
export const EnvironmentSelect = () => { | ||
const props = useEnvironmentSelect(); | ||
|
||
return <EnvironmentSelectRenderer {...props} />; | ||
}; |
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 @@ | ||
export * from './EnvironmentSelect'; |
63 changes: 63 additions & 0 deletions
63
apps/web/src/studio/components/EnvironmentSelect/useEnvironmentSelect.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,63 @@ | ||
import { type ISelectProps } from '@novu/design-system'; | ||
import { IconComputer, IconConstruction, IconRocketLaunch, type IIconProps } from '@novu/novui/icons'; | ||
import { ROUTES, useEnvController } from '@novu/shared-web'; | ||
import { useState } from 'react'; | ||
import { matchPath, useLocation } from 'react-router-dom'; | ||
import { EnvironmentEnum } from '../../constants/EnvironmentEnum'; | ||
|
||
const ENVIRONMENT_ICON_LOOKUP: Record<EnvironmentEnum, React.ReactElement<IIconProps>> = { | ||
[EnvironmentEnum.LOCAL]: <IconComputer />, | ||
[EnvironmentEnum.DEVELOPMENT]: <IconConstruction />, | ||
[EnvironmentEnum.PRODUCTION]: <IconRocketLaunch />, | ||
}; | ||
|
||
export const useEnvironmentSelect = () => { | ||
const [isPopoverOpened, setIsPopoverOpened] = useState<boolean>(false); | ||
const location = useLocation(); | ||
|
||
const { setEnvironment, isLoading, environment, readonly } = useEnvController({ | ||
onSuccess: (newEnvironment) => { | ||
setIsPopoverOpened(!!newEnvironment?._parentId); | ||
}, | ||
}); | ||
|
||
async function handlePopoverLinkClick(e) { | ||
e.preventDefault(); | ||
|
||
await setEnvironment(EnvironmentEnum.DEVELOPMENT, { route: ROUTES.CHANGES }); | ||
} | ||
|
||
const onChange: ISelectProps['onChange'] = async (value) => { | ||
if (typeof value !== 'string') { | ||
return; | ||
} | ||
|
||
/* | ||
* this navigates users to the "base" page of the application to avoid sub-pages opened with data from other | ||
* environments -- unless the path itself is based on a specific environment (e.g. API Keys) | ||
*/ | ||
const urlParts = location.pathname.replace('/', '').split('/'); | ||
const redirectRoute: string | undefined = checkIfEnvBasedRoute() ? undefined : urlParts[0]; | ||
await setEnvironment(value as EnvironmentEnum, { route: redirectRoute }); | ||
}; | ||
|
||
return { | ||
loading: isLoading, | ||
data: Object.values(EnvironmentEnum).map((value) => ({ | ||
label: value, | ||
value, | ||
})), | ||
value: environment?.name, | ||
onChange, | ||
readonly, | ||
icon: environment?.name ? ENVIRONMENT_ICON_LOOKUP[environment.name] : null, | ||
isPopoverOpened, | ||
setIsPopoverOpened, | ||
handlePopoverLinkClick, | ||
}; | ||
}; | ||
|
||
/** Determine if the current pathname is dependent on the current env */ | ||
function checkIfEnvBasedRoute() { | ||
return [ROUTES.API_KEYS, ROUTES.WEBHOOK].some((route) => matchPath(route, window.location.pathname)); | ||
} |
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,32 @@ | ||
import { IconRoute, IconSettings } from '@novu/novui/icons'; | ||
import { ROUTES } from '@novu/shared-web'; | ||
import { EnvironmentSelect } from './EnvironmentSelect/index'; | ||
import { NavMenu } from '../../components/nav/NavMenu'; | ||
import { NavMenuLinkButton } from '../../components/nav/NavMenuButton/NavMenuLinkButton'; | ||
import { NavMenuSection } from '../../components/nav/NavMenuSection'; | ||
import { OrganizationSelect } from '../../components/nav/OrganizationSelect/v2/index'; | ||
import { RootNavMenuFooter } from '../../components/nav/RootNavMenuFooter'; | ||
|
||
export const LocalNavMenu: React.FC = () => { | ||
return ( | ||
<NavMenu variant="root"> | ||
<NavMenuSection> | ||
<OrganizationSelect /> | ||
<NavMenuLinkButton | ||
label="Settings" | ||
icon={<IconSettings />} | ||
link={ROUTES.PROFILE} | ||
testId="side-nav-settings-link" | ||
/> | ||
<EnvironmentSelect /> | ||
<NavMenuLinkButton | ||
label="Workflows" | ||
icon={<IconRoute />} | ||
link={ROUTES.STUDIO_FLOWS} | ||
testId="side-nav-templates-link" | ||
/> | ||
</NavMenuSection> | ||
<RootNavMenuFooter /> | ||
</NavMenu> | ||
); | ||
}; |
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,5 @@ | ||
export enum EnvironmentEnum { | ||
LOCAL = 'Local', | ||
DEVELOPMENT = 'Development', | ||
PRODUCTION = 'Production', | ||
} |
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 @@ | ||
export * from './EnvironmentEnum'; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './panda-preset'; | ||
export * from './components'; | ||
export { type CoreProps } from './types'; |
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.