Skip to content

Commit

Permalink
Merge pull request #2665 from RedHatInsights/master
Browse files Browse the repository at this point in the history
[stable] Update build
  • Loading branch information
Hyperkid123 authored Oct 19, 2023
2 parents 6ca8f57 + bfa7bc3 commit 46682ac
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 94 deletions.
2 changes: 1 addition & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const commonConfig = ({ dev }) => {
},
],
},
plugins: plugins(dev, process.env.BETA === 'true'),
plugins: plugins(dev, process.env.BETA === 'true', process.env.NODE_ENV === 'restricted'),
devServer: {
allowedHosts: 'all',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions config/webpack.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getDynamicModules = require('./get-dynamic-modules');

const deps = require('../package.json').dependencies;

const plugins = (dev = false, beta = false) => {
const plugins = (dev = false, beta = false, restricted = false) => {
const ChunkMapper = new (require('./chunk-mapper'))({
modules: 'chrome',
_unstableHotReload: dev,
Expand Down Expand Up @@ -53,7 +53,7 @@ const plugins = (dev = false, beta = false) => {
}),
ChunkMapper,
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../src/index.ejs'),
template: restricted ? path.resolve(__dirname, '../src/indexRes.ejs') : path.resolve(__dirname, '../src/index.ejs'),
inject: 'body',
minify: false,
filename: dev ? 'index.html' : '../index.html',
Expand Down
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "NODE_ENV=production webpack --config config/webpack.config.js --mode=production",
"build:beta": "BETA=true npm run build",
"build:dev": "NODE_ENV=development webpack --config config/webpack.config.js --mode=development",
"build:res": "NODE_ENV=restricted webpack --config config/webpack.config.js --mode=production",
"cypress": "cypress",
"cypress:run": "cypress run --browser electron",
"dev": "DEV_SERVER=true webpack serve --config config/webpack.config.js --mode=development",
Expand Down Expand Up @@ -134,7 +135,7 @@
"@patternfly/react-core": "^5.0.1",
"@patternfly/react-icons": "^5.0.1",
"@patternfly/react-tokens": "^5.0.1",
"@redhat-cloud-services/chrome": "^0.0.11",
"@redhat-cloud-services/chrome": "^1.0.2",
"@redhat-cloud-services/entitlements-client": "1.2.0",
"@redhat-cloud-services/frontend-components": "^4.0.10",
"@redhat-cloud-services/frontend-components-notifications": "^4.0.2",
Expand Down
14 changes: 9 additions & 5 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChromeUser } from '@redhat-cloud-services/types';
import { Store } from 'redux';

import * as jwt from '../jwt/jwt';
import { getTokenWithAuthorizationCode } from '../cognito/auth';
import { createUser, getTokenWithAuthorizationCode } from '../cognito/auth';
import { ITLessCognito } from '../utils/common';
import consts, { defaultAuthOptions as defaultOptions } from '../utils/consts';
import { ACCOUNT_REQUEST_TIMEOUT, ACTIVE_REMOTE_REQUEST, CROSS_ACCESS_ACCOUNT_NUMBER, CROSS_ACCESS_ORG_ID } from '../utils/consts';
Expand Down Expand Up @@ -59,10 +59,14 @@ export const createAuthObject = (libjwt: LibJWT, getUser: () => Promise<ChromeUs
});

export const createGetUser = (libjwt: LibJWT): (() => Promise<ChromeUser | undefined | void>) => {
return () =>
libjwt.initPromise.then(libjwt.jwt.getUserInfo).catch(() => {
libjwt.jwt.logoutAllTabs();
});
if (isITLessCognito) {
return () => createUser();
} else {
return () =>
libjwt.initPromise.then(libjwt.jwt.getUserInfo).catch(() => {
libjwt.jwt.logoutAllTabs();
});
}
};

export const createGetUserPermissions = (libJwt: LibJWT, getUser: () => Promise<void | ChromeUser>) => {
Expand Down
28 changes: 17 additions & 11 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import initializeJWT from './jwt/initialize-jwt';
import AppPlaceholder from './components/AppPlaceholder';
import { initializeVisibilityFunctions } from './utils/VisibilitySingleton';
import { createGetUser } from './auth';
import { getTokenWithAuthorizationCode } from './cognito/auth';

const language: keyof typeof messages = 'en';

Expand All @@ -46,16 +47,18 @@ const initializeAccessRequestCookies = () => {
const libjwtSetup = (chromeConfig: { ssoUrl?: string }, ssoScopes: string[] = []) => {
const libjwt = auth({ ...chromeConfig, ssoScopes } || { ssoScopes });

libjwt.initPromise.then(() => {
return libjwt.jwt
.getUserInfo()
.then((chromeUser) => {
if (chromeUser) {
sentry(chromeUser);
}
})
.catch(noop);
});
if (!ITLess()) {
libjwt.initPromise.then(() => {
return libjwt.jwt
.getUserInfo()
.then((chromeUser) => {
if (chromeUser) {
sentry(chromeUser);
}
})
.catch(noop);
});
}

return libjwt;
};
Expand Down Expand Up @@ -96,7 +99,10 @@ const useInitialize = () => {
const getUser = createGetUser(libJwt);
initializeVisibilityFunctions({
getUser,
getToken: () => libJwt!.initPromise.then(() => libJwt!.jwt.getUserInfo().then(() => libJwt!.jwt.getEncodedToken())),
getToken: () =>
ITLessCognito()
? getTokenWithAuthorizationCode()
: libJwt!.initPromise.then(() => libJwt!.jwt.getUserInfo().then(() => libJwt!.jwt.getEncodedToken())),
getUserPermissions: createGetUserPermissions(libJwt, getUser),
});

Expand Down
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
15 changes: 5 additions & 10 deletions src/components/RootApp/RootApp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Suspense, lazy, memo, useEffect } from 'react';
import { unstable_HistoryRouter as HistoryRouter, HistoryRouterProps } from 'react-router-dom';
import { HelpTopicContainer, QuickStart, QuickStartContainer, QuickStartContainerProps } from '@patternfly/quickstarts';
import { ChromeProvider } from '@redhat-cloud-services/chrome';
import chromeHistory from '../../utils/chromeHistory';
import { FeatureFlagsProvider } from '../FeatureFlags';
import ScalprumRoot from './ScalprumRoot';
Expand All @@ -15,7 +14,6 @@ import SegmentProvider from '../../analytics/SegmentProvider';
import { ReduxState } from '../../redux/store';
import { AppsConfig } from '@scalprum/core';
import { ITLess, chunkLoadErrorRefreshKey, getRouterBasename } from '../../utils/common';
import useBundle from '../../hooks/useBundle';
import useUserSSOScopes from '../../hooks/useUserSSOScopes';
import { DeepRequired } from 'utility-types';
import ReactDOM from 'react-dom';
Expand All @@ -40,7 +38,6 @@ const RootApp = memo((props: RootAppProps) => {
},
}: ReduxState) => Object.values(quickstarts).flat()
);
const { bundleTitle } = useBundle();
const user = useSelector(({ chrome }: DeepRequired<ReduxState>) => chrome.user);
const isDebuggerEnabled = useSelector<ReduxState, boolean | undefined>(({ chrome: { isDebuggerEnabled } }) => isDebuggerEnabled);

Expand Down Expand Up @@ -122,13 +119,11 @@ const RootApp = memo((props: RootAppProps) => {
<Suspense fallback={null}>
{user?.identity?.account_number && !ITLess() && isDebuggerEnabled && ReactDOM.createPortal(<Debugger user={user} />, document.body)}
</Suspense>
<ChromeProvider bundle={bundleTitle}>
<QuickStartContainer {...quickStartProps}>
<HelpTopicContainer helpTopics={helpTopics}>
<ScalprumRoot {...props} quickstartsAPI={quickstartsAPI} helpTopicsAPI={helpTopicsAPI} />
</HelpTopicContainer>
</QuickStartContainer>
</ChromeProvider>
<QuickStartContainer {...quickStartProps}>
<HelpTopicContainer helpTopics={helpTopics}>
<ScalprumRoot {...props} quickstartsAPI={quickstartsAPI} helpTopicsAPI={helpTopicsAPI} />
</HelpTopicContainer>
</QuickStartContainer>
</FeatureFlagsProvider>
</SegmentProvider>
</HistoryRouter>
Expand Down
63 changes: 33 additions & 30 deletions src/components/RootApp/ScalprumRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HelpTopic, HelpTopicContext } from '@patternfly/quickstarts';
import isEqual from 'lodash/isEqual';
import { AppsConfig } from '@scalprum/core';
import { ChromeAPI, EnableTopicsArgs } from '@redhat-cloud-services/types';
import { ChromeProvider } from '@redhat-cloud-services/chrome';

import chromeHistory from '../../utils/chromeHistory';
import DefaultLayout from '../../layouts/DefaultLayout';
Expand Down Expand Up @@ -195,42 +196,44 @@ const ScalprumRoot = memo(
*/
<InternalChromeContext.Provider value={chromeApi}>
<ScalprumProvider {...scalprumProviderProps}>
<Routes>
<Route
index
path="/"
element={<DefaultLayout Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} {...props} />}
/>
<Route
path="/connect/products"
element={
<Suspense fallback={LoadingFallback}>
<ProductSelection />
</Suspense>
}
/>
<Route
path="/allservices"
element={
<Suspense fallback={LoadingFallback}>
<AllServices Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} />
</Suspense>
}
/>
{!ITLess() && (
<ChromeProvider>
<Routes>
<Route
index
path="/"
element={<DefaultLayout Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} {...props} />}
/>
<Route
path="/connect/products"
element={
<Suspense fallback={LoadingFallback}>
<ProductSelection />
</Suspense>
}
/>
<Route
path="/favoritedservices"
path="/allservices"
element={
<Suspense fallback={LoadingFallback}>
<FavoritedServices Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} />
<AllServices Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} />
</Suspense>
}
/>
)}
{ITLess() && <Route path="/insights/satellite" element={<SatelliteToken />} />}
<Route path="/security" element={<DefaultLayout {...props} />} />
<Route path="*" element={<DefaultLayout Sidebar={Navigation} {...props} />} />
</Routes>
{!ITLess() && (
<Route
path="/favoritedservices"
element={
<Suspense fallback={LoadingFallback}>
<FavoritedServices Footer={<Footer setCookieElement={setCookieElement} cookieElement={cookieElement} />} />
</Suspense>
}
/>
)}
{ITLess() && <Route path="/insights/satellite" element={<SatelliteToken />} />}
<Route path="/security" element={<DefaultLayout {...props} />} />
<Route path="*" element={<DefaultLayout Sidebar={Navigation} {...props} />} />
</Routes>
</ChromeProvider>
</ScalprumProvider>
</InternalChromeContext.Provider>
);
Expand Down
35 changes: 31 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,25 @@ 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',
to: '/user-preferences/notifications',
},
{
path: '/quay',
Expand Down Expand Up @@ -48,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 @@ -63,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
Loading

0 comments on commit 46682ac

Please sign in to comment.