Skip to content

Commit

Permalink
Add redirects to integrations instead of sources for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
karelhala committed Oct 18, 2023
1 parent a9c07f7 commit d13ae13
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/Header/Tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ReduxState } from '../../redux/store';
import BellIcon from '@patternfly/react-icons/dist/dynamic/icons/bell-icon';
import { toggleNotificationsDrawer } from '../../redux/actions';
import useWindowWidth from '../../hooks/useWindowWidth';
import { usePreviewFlag } from '../../utils/usePreviewFlag';

const isITLessEnv = ITLess();

Expand Down Expand Up @@ -80,6 +81,7 @@ const Tools = () => {
isRhosakEntitled: false,
isDemoAcc: false,
});
const enableIntegrations = usePreviewFlag('platform.sources.integrations');
const { xs } = useWindowWidth();
const user = useSelector(({ chrome: { user } }: ReduxState) => user!);
const unreadNotifications = useSelector(({ chrome: { notifications } }: ReduxState) => notifications.data.some((item) => !item.read));
Expand All @@ -88,7 +90,7 @@ const Tools = () => {
const libjwt = useContext(LibtJWTContext);
const intl = useIntl();
const location = useLocation();
const settingsPath = isITLessEnv ? `/settings/my-user-access` : `/settings/sources`;
const settingsPath = isITLessEnv ? `/settings/my-user-access` : enableIntegrations ? `/settings/integrations` : '/settings/sources';
const identityAndAccessManagmentPath = '/iam/user-access/users';
const betaSwitcherTitle = `${isBeta() ? intl.formatMessage(messages.stopUsing) : intl.formatMessage(messages.use)} ${intl.formatMessage(
messages.betaRelease
Expand Down
31 changes: 27 additions & 4 deletions src/components/Routes/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { Suspense, lazy } from 'react';
import React, { Suspense, lazy, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { Navigate, Route, Routes } from 'react-router-dom';
import ChromeRoute from '../ChromeRoute';
import NotFoundRoute from '../NotFoundRoute';
import LoadingFallback from '../../utils/loading-fallback';
import { ReduxState } from '../../redux/store';
import { usePreviewFlag } from '../../utils/usePreviewFlag';

const INTEGRATION_SOURCES = 'platform.sources.integrations';

const QuickstartCatalogRoute = lazy(() => import('../QuickstartsCatalogRoute'));

Expand All @@ -17,9 +20,21 @@ const redirects = [
path: '/docs',
to: '/api/docs',
},
{
path: '/settings',
to: '/settings/integrations',
previewFlag: {
value: true,
name: INTEGRATION_SOURCES,
},
},
{
path: '/settings',
to: '/settings/sources',
previewFlag: {
value: false,
name: INTEGRATION_SOURCES,
},
},
{
path: '/user-preferences',
Expand Down Expand Up @@ -52,6 +67,8 @@ export type RoutesProps = {
};

const ChromeRoutes = ({ routesProps }: RoutesProps) => {
const enableIntegrations = usePreviewFlag(INTEGRATION_SOURCES);
const previewFlags = useMemo<Record<string, boolean>>(() => ({ INTEGRATION_SOURCES: enableIntegrations }), [enableIntegrations]);
const moduleRoutes = useSelector(({ chrome: { moduleRoutes } }: ReduxState) => moduleRoutes);
const showBundleCatalog = localStorage.getItem('chrome:experimental:quickstarts') === 'true';

Expand All @@ -67,9 +84,15 @@ const ChromeRoutes = ({ routesProps }: RoutesProps) => {
}
/>
)}
{redirects.map(({ path, to }) => (
<Route key={path} path={path} element={<Navigate replace to={to} />} />
))}
{redirects.map(({ path, to, previewFlag }) => {
if (previewFlag) {
const found = Object.keys(previewFlags).find((item) => item === previewFlag.name);
if (previewFlags[found as string] !== previewFlag.value) {
return null;
}
}
return <Route key={path} path={path} element={<Navigate replace to={to} />} />;
})}
{moduleRoutes.map((app) => (
<Route key={app.path} path={app.absolute ? app.path : `${app.path}/*`} element={<ChromeRoute {...routesProps} {...app} />} />
))}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/usePreviewFlag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useFlag } from '@unleash/proxy-client-react';
import { isBeta, isProd } from './common';

export const usePreviewFlag = (flag: string) => {
const notificationsOverhaul = useFlag(flag);

if (isProd() && !isBeta()) {
return false;
}

return notificationsOverhaul;
};

0 comments on commit d13ae13

Please sign in to comment.