Skip to content

Commit

Permalink
Merge pull request #2913 from Hyperkid123/preview-release
Browse files Browse the repository at this point in the history
Remove preview release.
  • Loading branch information
Hyperkid123 authored Aug 1, 2024
2 parents 3e189dd + adba3fe commit 71fd911
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 233 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To run a script you have to install dependencies `npm install`. Then you are fre
> npm run dev
```

3. Open browser at `https://stage.foo.redhat.com:1337/` or Open browser at `https://stage.foo.redhat.com:1337/preview`.
3. Open browser at `https://stage.foo.redhat.com:1337/`.

### Running chrome with other applications locally

Expand All @@ -64,8 +64,8 @@ You can spin chrome locally together with other applications. Use `LOCAL_APPS` t

For illustration, to deploy Advisor together with Insights Chrome, you would require to

1. Run Advisor on any available port with `npm run start -- --port=8004` or `npm run start:beta -- --port=8004`,
2. Run Chrome and list the Advisor's port: `LOCAL_APPS=advisor:8004~http npm run dev` or `LOCAL_APPS=advisor:8004~http npm run dev:beta`.
1. Run Advisor on any available port with `npm run start -- --port=8004`,
2. Run Chrome and list the Advisor's port: `LOCAL_APPS=advisor:8004~http npm run dev`.
#### Example 2 (using devServer route)
Expand All @@ -85,7 +85,7 @@ devServer: {
}
...
```
3. Run insights-chrome with `npm run dev` or `npm run dev:beta`.
3. Run insights-chrome with `npm run dev`.
## Local search development
Expand Down
4 changes: 2 additions & 2 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const PFGenerator = asGenerator((item, ...rest) => {
return defaultTuples;
});

const publicPath = process.env.BETA === 'true' ? '/beta/apps/chrome/js/' : '/apps/chrome/js/';
const publicPath = '/apps/chrome/js/';
const commonConfig = ({ dev }) => {
/** @type { import("webpack").Configuration } */
return {
Expand Down Expand Up @@ -150,7 +150,7 @@ const commonConfig = ({ dev }) => {
...proxy({
env: 'stage-beta',
port: 1337,
appUrl: [/^\/*$/, /^\/beta\/*$/, /^\/preview\/*$/],
appUrl: [/^\/*$/],
useProxy: true,
publicPath,
proxyVerbose: true,
Expand Down
3 changes: 1 addition & 2 deletions config/webpack.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ const plugins = (dev = false, beta = false, restricted = false) => {
inject: 'body',
minify: false,
filename: dev ? 'index.html' : '../index.html',
// FIXME: Change to /preview on May
base: beta ? '/beta/' : '/',
base: '/',
templateParameters: {
pf4styles: `/${beta ? 'beta/' : ''}apps/chrome/js/pf/pf4-v4.css`,
pf5styles: `/${beta ? 'beta/' : ''}apps/chrome/js/pf/pf4-v5.css`,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@
},
"nyc": {
"report-dir": "cypress-coverage"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
2 changes: 1 addition & 1 deletion src/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function isInternalFlag(email: string, isInternal = false) {
}

function getUrl(type?: string, isPreview = false) {
if (['/beta', '/preview', '/'].includes(window.location.pathname)) {
if (['/'].includes(window.location.pathname)) {
return 'landing';
}

Expand Down
10 changes: 3 additions & 7 deletions src/auth/OIDCConnector/OIDCProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import React, { useEffect, useMemo, useState } from 'react';
import { DEFAULT_SSO_ROUTES, ITLess, isBeta, loadFedModules } from '../../utils/common';
import { DEFAULT_SSO_ROUTES, ITLess, loadFedModules } from '../../utils/common';
import { AuthProvider, AuthProviderProps } from 'react-oidc-context';
import { WebStorageStateStore } from 'oidc-client-ts';
import platformUrl from '../platformUrl';
import { OIDCSecured } from './OIDCSecured';
import AppPlaceholder from '../../components/AppPlaceholder';
import { postbackUrlSetup } from '../offline';

const LOCAL_PREVIEW = localStorage.getItem('chrome:local-preview') === 'true';
// TODO: remove this once the local preview is enabled by default
const betaPartial = LOCAL_PREVIEW ? '' : isBeta() ? '/beta' : '';

const OIDCProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
const [cookieElement, setCookieElement] = useState<HTMLAnchorElement | null>(null);
const [state, setState] = useState<
Expand Down Expand Up @@ -42,7 +38,7 @@ const OIDCProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
const authProviderProps: AuthProviderProps = useMemo(
() => ({
client_id: ITLess() ? 'console-dot' : 'cloud-services',
silent_redirect_uri: `https://${window.location.host}${betaPartial}/apps/chrome/silent-check-sso.html`,
silent_redirect_uri: `https://${window.location.host}/apps/chrome/silent-check-sso.html`,
automaticSilentRenew: true,
redirect_uri: `${window.location.origin}`,
authority: `${state?.ssoUrl}`,
Expand All @@ -52,7 +48,7 @@ const OIDCProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
authorization_endpoint: `${state?.ssoUrl}realms/redhat-external/protocol/openid-connect/auth`,
token_endpoint: `${state?.ssoUrl}realms/redhat-external/protocol/openid-connect/token`,
end_session_endpoint: `${state?.ssoUrl}realms/redhat-external/protocol/openid-connect/logout`,
check_session_iframe: `https://${window.location.host}${betaPartial}/apps/chrome/silent-check-sso.html`,
check_session_iframe: `https://${window.location.host}/apps/chrome/silent-check-sso.html`,
revocation_endpoint: `${state?.ssoUrl}realms/redhat-external/protocol/openid-connect/revoke`,
},
// removes code_challenge query param from the url
Expand Down
6 changes: 2 additions & 4 deletions src/auth/OIDCConnector/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthContextProps } from 'react-oidc-context';
import { ITLess, LOGIN_SCOPES_STORAGE_KEY, deleteLocalStorageItems, getRouterBasename, isBeta } from '../../utils/common';
import { ITLess, LOGIN_SCOPES_STORAGE_KEY, deleteLocalStorageItems } from '../../utils/common';
import { GLOBAL_FILTER_KEY, OFFLINE_REDIRECT_STORAGE_KEY } from '../../utils/consts';
import Cookies from 'js-cookie';
import logger from '../logger';
Expand Down Expand Up @@ -44,16 +44,14 @@ export async function logout(auth: AuthContextProps, bounce?: boolean) {
key.startsWith(GLOBAL_FILTER_KEY)
);
deleteLocalStorageItems([...keys, OFFLINE_REDIRECT_STORAGE_KEY, LOGIN_SCOPES_STORAGE_KEY]);
// FIXME: Remove this one local preview is enabled by default
const pathname = isBeta() ? getRouterBasename() : '';
if (bounce) {
const eightSeconds = new Date(new Date().getTime() + 8 * 1000);
Cookies.set('cs_loggedOut', 'true', {
expires: eightSeconds,
});
await auth.signoutRedirect({
redirectTarget: 'top',
post_logout_redirect_uri: `${window.location.origin}${pathname}`,
post_logout_redirect_uri: window.location.origin,
id_token_hint: undefined,
});
} else {
Expand Down
9 changes: 1 addition & 8 deletions src/components/AppFilter/useAppFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { getChromeStaticPathname } from '../../utils/common';
import { evaluateVisibility } from '../../utils/isNavItemVisible';
import { useAtomValue } from 'jotai';
import { chromeModulesAtom } from '../../state/atoms/chromeModuleAtom';
import { isPreviewAtom } from '../../state/atoms/releaseAtom';
import { navigationAtom } from '../../state/atoms/navigationAtom';

const LOCAL_PREVIEW = localStorage.getItem('chrome:local-preview') === 'true';

export type AppFilterBucket = {
id: string;
title: string;
Expand Down Expand Up @@ -81,7 +78,6 @@ type AppFilterState = {
};

const useAppFilter = () => {
const isPreview = useAtomValue(isPreviewAtom);
const [state, setState] = useState<AppFilterState>({
isLoaded: false,
isLoading: false,
Expand Down Expand Up @@ -183,10 +179,7 @@ const useAppFilter = () => {
.get<BundleNavigation>(`${getChromeStaticPathname('navigation')}/${fragment}-navigation.json?ts=${Date.now()}`)
// fallback static CSC for EE env
.catch(() => {
// FIXME: Remove this once local preview is enabled by default
// No /beta will be needed in the future
const previewFragment = LOCAL_PREVIEW ? '' : isPreview ? '/beta' : '';
return axios.get<BundleNavigation>(`${previewFragment}/config/chrome/${fragment}-navigation.json?ts=${Date.now()}`);
return axios.get<BundleNavigation>(`$/config/chrome/${fragment}-navigation.json?ts=${Date.now()}`);
})
.then(handleBundleData)
.then(() => Object.values(existingSchemas).map((data) => handleBundleData({ data } as { data: BundleNavigation })))
Expand Down
16 changes: 1 addition & 15 deletions src/components/Header/HeaderTests/Tools.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Tools, { switchRelease } from '../Tools';
import Tools from '../Tools';
import { act, render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
Expand Down Expand Up @@ -48,18 +48,4 @@ describe('Tools', () => {
});
expect(container.querySelector('div')).toMatchSnapshot();
});

it('should switch release correctly', () => {
const cases = [
['/beta/settings/rbac', '/settings/rbac'],
['/preview/settings/rbac', '/settings/rbac'],
['/settings/rbac', '/settings/rbac'],
];

cases.forEach(([input, expected]) => {
window.location.href = '';
switchRelease(true, input);
expect(window.location.href).toEqual(expected);
});
});
});
21 changes: 4 additions & 17 deletions src/components/Header/PreviewAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,21 @@ import cookie from 'js-cookie';
import HeaderAlert from './HeaderAlert';
import { useAtom } from 'jotai';
import { isPreviewAtom } from '../../state/atoms/releaseAtom';
import { isBeta } from '../../utils/common';
import { AlertActionLink, AlertVariant } from '@patternfly/react-core/dist/dynamic/components/Alert';
import { useLocation } from 'react-router-dom';
import { useFlag } from '@unleash/proxy-client-react';

const LOCAL_PREVIEW = localStorage.getItem('chrome:local-preview') === 'true';

const PreviewAlert = ({ switchRelease }: { switchRelease: (isBeta: boolean, pathname: string, previewEnabled: boolean) => void }) => {
const PreviewAlert = () => {
const [isPreview, togglePreview] = useAtom(isPreviewAtom);
const [prevPreviewValue, setPrevPreviewValue] = useState(isPreview);
const location = useLocation();
const previewEnabled = useFlag('platform.chrome.preview');

// FIXME: Remove the cookie check once the local preview is enabled by default
const shouldRenderAlert = LOCAL_PREVIEW ? isPreview !== prevPreviewValue : cookie.get('cs_toggledRelease') === 'true';
const isPreviewEnabled = LOCAL_PREVIEW ? isPreview : isBeta();
const shouldRenderAlert = isPreview !== prevPreviewValue;

function handlePreviewToggle() {
if (!LOCAL_PREVIEW) {
switchRelease(isPreviewEnabled, location.pathname, previewEnabled);
}
togglePreview();
}

return shouldRenderAlert ? (
<HeaderAlert
className="chr-c-alert-preview"
title={`Preview has been ${isPreviewEnabled ? 'enabled' : 'disabled'}.`}
title={`Preview has been ${isPreview ? 'enabled' : 'disabled'}.`}
variant={AlertVariant.info}
actionLinks={
<React.Fragment>
Expand All @@ -47,7 +34,7 @@ const PreviewAlert = ({ switchRelease }: { switchRelease: (isBeta: boolean, path
onClick={() => {
handlePreviewToggle();
}}
>{`${isPreviewEnabled ? 'Disable' : 'Enable'} preview`}</AlertActionLink>
>{`${isPreview ? 'Disable' : 'Enable'} preview`}</AlertActionLink>
</React.Fragment>
}
onDismiss={() => {
Expand Down
36 changes: 4 additions & 32 deletions src/components/Header/Tools.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import React, { memo, useContext, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useAtom, useAtomValue } from 'jotai';
import { Button } from '@patternfly/react-core/dist/dynamic/components/Button';
import { Divider } from '@patternfly/react-core/dist/dynamic/components/Divider';
Expand All @@ -16,7 +15,7 @@ import UserToggle from './UserToggle';
import ToolbarToggle, { ToolbarToggleDropdownItem } from './ToolbarToggle';
import SettingsToggle, { SettingsToggleDropdownGroup } from './SettingsToggle';
import cookie from 'js-cookie';
import { ITLess, getRouterBasename, getSection } from '../../utils/common';
import { ITLess, getSection } from '../../utils/common';
import { useIntl } from 'react-intl';
import { useFlag } from '@unleash/proxy-client-react';
import messages from '../../locales/Messages';
Expand All @@ -28,26 +27,8 @@ import { isPreviewAtom } from '../../state/atoms/releaseAtom';
import { notificationDrawerExpandedAtom, unreadNotificationsAtom } from '../../state/atoms/notificationDrawerAtom';
import PreviewAlert from './PreviewAlert';

const LOCAL_PREVIEW = localStorage.getItem('chrome:local-preview') === 'true';

const isITLessEnv = ITLess();

/**
* @deprecated Switch release will be replaced by the internal chrome state variable
*/
export const switchRelease = (isBeta: boolean, pathname: string, previewEnabled: boolean) => {
cookie.set('cs_toggledRelease', 'true');
const previewFragment = getRouterBasename(pathname);

let href = '';
if (isBeta) {
href = pathname.replace(previewFragment.includes('beta') ? /\/beta/ : /\/preview/, '');
} else {
href = previewEnabled ? `/preview${pathname}` : `/beta${pathname}`;
}
window.location.href = href;
};

const InternalButton = () => (
<Button
variant="plain"
Expand Down Expand Up @@ -115,7 +96,6 @@ const Tools = () => {
const unreadNotifications = useAtomValue(unreadNotificationsAtom);
const [isNotificationDrawerExpanded, toggleNotifications] = useAtom(notificationDrawerExpandedAtom);
const intl = useIntl();
const location = useLocation();
const settingsPath = isITLessEnv ? `/settings/my-user-access` : enableIntegrations ? `/settings/integrations` : '/settings/sources';
const identityAndAccessManagmentPath = '/iam/user-access/overview';
const betaSwitcherTitle = `${isPreview ? intl.formatMessage(messages.stopUsing) : intl.formatMessage(messages.use)} ${intl.formatMessage(
Expand All @@ -124,7 +104,6 @@ const Tools = () => {

const enableAuthDropdownOption = useFlag('platform.chrome.dropdown.authfactor');
const enableExpandedSettings = useFlag('platform.chrome.expanded-settings');
const previewEnabled = useFlag('platform.chrome.preview');
const isNotificationsEnabled = useFlag('platform.chrome.notifications-drawer');

const enableMyUserAccessLanding = useFlag('platform.chrome.my-user-access-landing-page');
Expand Down Expand Up @@ -186,13 +165,6 @@ const Tools = () => {
: []),
];

const handleToggle = () => {
if (!LOCAL_PREVIEW) {
switchRelease(isPreview, location.pathname, previewEnabled);
}
setIsPreview();
};

useEffect(() => {
if (user) {
setState({
Expand Down Expand Up @@ -259,7 +231,7 @@ const Tools = () => {
},
{
title: betaSwitcherTitle,
onClick: handleToggle,
onClick: () => setIsPreview(),
},
{ title: 'separator' },
...aboutMenuDropdownItems,
Expand Down Expand Up @@ -289,7 +261,7 @@ const Tools = () => {
labelOff="Preview off"
aria-label="Preview switcher"
isChecked={isPreview}
onChange={handleToggle}
onChange={() => setIsPreview()}
isReversed
className="chr-c-beta-switcher"
/>
Expand Down Expand Up @@ -397,7 +369,7 @@ const Tools = () => {
/>
</Tooltip>
</ToolbarItem>
<PreviewAlert switchRelease={switchRelease} />
<PreviewAlert />
</>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/RootApp/RootApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useQuickstartsStates from '../QuickStart/useQuickstartsStates';
import useHelpTopicState from '../QuickStart/useHelpTopicState';
import validateQuickstart from '../QuickStart/quickstartValidation';
import SegmentProvider from '../../analytics/SegmentProvider';
import { ITLess, chunkLoadErrorRefreshKey, getRouterBasename } from '../../utils/common';
import { ITLess, chunkLoadErrorRefreshKey } from '../../utils/common';
import useUserSSOScopes from '../../hooks/useUserSSOScopes';
import { DeepRequired } from 'utility-types';
import ReactDOM from 'react-dom';
Expand Down Expand Up @@ -111,7 +111,7 @@ const RootApp = memo((props: RootAppProps) => {
updateQuickStarts,
};
return (
<HistoryRouter history={chromeHistory as unknown as HistoryRouterProps['history']} basename={getRouterBasename()}>
<HistoryRouter history={chromeHistory as unknown as HistoryRouterProps['history']}>
<SegmentProvider>
<FeatureFlagsProvider>
{/* <CrossRequestNotifier /> */}
Expand Down
9 changes: 3 additions & 6 deletions src/hooks/useAllLinks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useEffect, useState } from 'react';
import { useAtomValue } from 'jotai';
import { BundleNav, BundleNavigation, NavItem } from '../@types/types';
import fetchNavigationFiles from '../utils/fetchNavigationFiles';
import { evaluateVisibility } from '../utils/isNavItemVisible';
import { isExpandableNav } from '../utils/common';
import { isPreviewAtom } from '../state/atoms/releaseAtom';

const getFirstChildRoute = (routes: NavItem[] = []): NavItem | undefined => {
const firstLeaf = routes.find((item) => !item.expandable && item.href);
Expand Down Expand Up @@ -83,8 +81,8 @@ const getNavLinks = (navItems: NavItem[]): NavItem[] => {
return links;
};

const fetchNavigation = async (isPreview: boolean) => {
const bundlesNavigation = await fetchNavigationFiles(isPreview).then((data) => data.map(handleBundleResponse));
const fetchNavigation = async () => {
const bundlesNavigation = await fetchNavigationFiles().then((data) => data.map(handleBundleResponse));
const parsedBundles = await Promise.all(
bundlesNavigation.map(async (bundleNav) => ({
...bundleNav,
Expand All @@ -96,10 +94,9 @@ const fetchNavigation = async (isPreview: boolean) => {
};

const useAllLinks = () => {
const isPreview = useAtomValue(isPreviewAtom);
const [allLinks, setAllLinks] = useState<NavItem[]>([]);
useEffect(() => {
fetchNavigation(isPreview).then(setAllLinks);
fetchNavigation().then(setAllLinks);
}, []);
return allLinks;
};
Expand Down
Loading

0 comments on commit 71fd911

Please sign in to comment.