Skip to content

Commit

Permalink
refactor: remove ConditionallyRender with codemod
Browse files Browse the repository at this point in the history
Co-authored-by: Tymoteusz Czech <[email protected]>
  • Loading branch information
Codemod Bot and Tymek committed Aug 9, 2024
1 parent bc260a4 commit 0c9ad19
Show file tree
Hide file tree
Showing 390 changed files with 9,342 additions and 12,485 deletions.
95 changes: 43 additions & 52 deletions frontend/src/component/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Suspense, useEffect } from 'react';
import { Route, Routes } from 'react-router-dom';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { FeedbackNPS } from 'component/feedback/FeedbackNPS/FeedbackNPS';
import { LayoutPicker } from 'component/layout/LayoutPicker/LayoutPicker';
import Loader from 'component/common/Loader/Loader';
Expand Down Expand Up @@ -51,61 +50,53 @@ export const App = () => {
return (
<SWRProvider>
<Suspense fallback={<Loader type='fullscreen' />}>
<ConditionallyRender
condition={!hasFetchedAuth}
show={<Loader type='fullscreen' />}
elseShow={
<Demo>
<>
<ConditionallyRender
condition={Boolean(
uiConfig?.maintenanceMode,
)}
show={<MaintenanceBanner />}
/>
<LicenseBanner />
<ExternalBanners />
<InternalBanners />
<EdgeUpgradeBanner />
<StyledContainer>
<ToastRenderer />
<Routes>
{availableRoutes.map((route) => (
<Route
key={route.path}
path={route.path}
element={
<LayoutPicker
isStandalone={
route.isStandalone ===
true
}
>
<ProtectedRoute
route={route}
/>
</LayoutPicker>
}
/>
))}
{!hasFetchedAuth ? (
<Loader type='fullscreen' />
) : (
<Demo>
<>
{uiConfig?.maintenanceMode ? (
<MaintenanceBanner />
) : null}
<LicenseBanner />
<ExternalBanners />
<InternalBanners />
<EdgeUpgradeBanner />
<StyledContainer>
<ToastRenderer />
<Routes>
{availableRoutes.map((route) => (
<Route
path='/'
element={<InitialRedirect />}
key={route.path}
path={route.path}
element={
<LayoutPicker
isStandalone={
route.isStandalone ===
true
}
>
<ProtectedRoute
route={route}
/>
</LayoutPicker>
}
/>
<Route
path='*'
element={<NotFound />}
/>
</Routes>
))}
<Route
path='/'
element={<InitialRedirect />}
/>
<Route path='*' element={<NotFound />} />
</Routes>

<FeedbackNPS openUrl='http://feedback.unleash.run' />
<FeedbackNPS openUrl='http://feedback.unleash.run' />

<SplashPageRedirect />
</StyledContainer>
</>
</Demo>
}
/>
<SplashPageRedirect />
</StyledContainer>
</>
</Demo>
)}
</Suspense>
</SWRProvider>
);
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/component/admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ import { AdminTabsMenu } from './menu/AdminTabsMenu';
import { Banners } from './banners/Banners';
import { License } from './license/License';
import { useUiFlag } from 'hooks/useUiFlag';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';

export const Admin = () => {
const sidebarNavigationEnabled = useUiFlag('navigationSidebar');

return (
<>
<ConditionallyRender
condition={!sidebarNavigationEnabled}
show={<AdminTabsMenu />}
/>
{!sidebarNavigationEnabled ? <AdminTabsMenu /> : null}
<Routes>
<Route index element={<AdminIndex />} />
<Route path='users/*' element={<UsersAdmin />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Alert, Link } from '@mui/material';
import type React from 'react';
import type { ReactNode } from 'react';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { CancelButton, StyledBox, StyledForm } from './ApiTokenForm.styles';

interface IApiTokenFormProps {
Expand All @@ -25,18 +24,15 @@ const ApiTokenForm: React.FC<IApiTokenFormProps> = ({

return (
<StyledForm onSubmit={handleSubmit}>
<ConditionallyRender
condition={isUnleashCloud}
show={
<Alert severity='info' sx={{ mb: 4 }}>
Please be aware of our{' '}
<Link href='https://www.getunleash.io/fair-use-policy'>
fair use policy
</Link>
.
</Alert>
}
/>
{isUnleashCloud ? (
<Alert severity='info' sx={{ mb: 4 }}>
Please be aware of our{' '}
<Link href='https://www.getunleash.io/fair-use-policy'>
fair use policy
</Link>
.
</Alert>
) : null}
{children}
<StyledBox>
{actions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';
import type { IAutocompleteBoxOption } from 'component/common/AutocompleteBox/AutocompleteBox';
import { SelectAllButton } from './SelectAllButton/SelectAllButton';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';

const ALL_PROJECTS = '*';

Expand Down Expand Up @@ -96,15 +95,12 @@ export const SelectProjectInput: VFC<ISelectProjectInputProps> = ({

const renderGroup = ({ key, children }: AutocompleteRenderGroupParams) => (
<Fragment key={key}>
<ConditionallyRender
condition={options.length > 2}
show={
<SelectAllButton
isAllSelected={isAllSelected}
onClick={onSelectAllClick}
/>
}
/>
{options.length > 2 ? (
<SelectAllButton
isAllSelected={isAllSelected}
onClick={onSelectAllClick}
/>
) : null}
{children}
</Fragment>
);
Expand Down
26 changes: 11 additions & 15 deletions frontend/src/component/admin/apiToken/ConfirmToken/ConfirmToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Alert, Typography } from '@mui/material';
import { Link } from 'react-router-dom';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { UserToken } from './UserToken/UserToken';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { TokenType } from 'interfaces/token';

interface IConfirmUserLink {
Expand Down Expand Up @@ -32,20 +31,17 @@ export const ConfirmToken = ({
Your new token has been created successfully.
</Typography>
<UserToken token={token} />
<ConditionallyRender
condition={type === TokenType.FRONTEND}
show={
<Alert sx={{ mt: 2 }} severity='info'>
By default, all {TokenType.FRONTEND} tokens may be used
from any CORS origin. If you'd like to configure a
strict set of origins, please use the{' '}
<Link to='/admin/cors' target='_blank' rel='noreferrer'>
CORS origins configuration page
</Link>
.
</Alert>
}
/>
{type === TokenType.FRONTEND ? (
<Alert sx={{ mt: 2 }} severity='info'>
By default, all {TokenType.FRONTEND} tokens may be used from
any CORS origin. If you'd like to configure a strict set of
origins, please use the{' '}
<Link to='/admin/cors' target='_blank' rel='noreferrer'>
CORS origins configuration page
</Link>
.
</Alert>
) : null}
</Dialogue>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useUiFlag } from 'hooks/useUiFlag';
import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import ApiTokenForm from '../ApiTokenForm/ApiTokenForm';
Expand Down Expand Up @@ -176,17 +175,14 @@ export const CreateApiToken = ({ modal = false }: ICreateApiTokenProps) => {
environment={environment}
setEnvironment={setEnvironment}
/>
<ConditionallyRender
condition={resourceLimitsEnabled}
show={
<StyledLimit
name='API tokens'
shortName='tokens'
currentValue={currentValue}
limit={limit}
/>
}
/>
{resourceLimitsEnabled ? (
<StyledLimit
name='API tokens'
shortName='tokens'
currentValue={currentValue}
limit={limit}
/>
) : null}
</ApiTokenForm>
<ConfirmToken
open={showConfirm}
Expand Down
Loading

0 comments on commit 0c9ad19

Please sign in to comment.