Skip to content

Commit

Permalink
[Gitar] Cleaning up stale flag: resourceLimits with value true (#7964)
Browse files Browse the repository at this point in the history
[![Gitar](https://raw.githubusercontent.com/gitarcode/.github/main/assets/gitar-banner.svg)](https://gitar.co)
  
  ---
This automated PR was generated by [Gitar](https://gitar.co). View
[docs](https://gitar.co/docs).

---------

Co-authored-by: Gitar <[email protected]>
Co-authored-by: Thomas Heartman <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent b0541a0 commit 4615ff4
Show file tree
Hide file tree
Showing 30 changed files with 181 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const server = testServerSetup();

const setupApi = (existingTokensCount: number) => {
testServerRoute(server, '/api/admin/ui-config', {
flags: {
resourceLimits: true,
},
resourceLimits: {
apiTokens: 1,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +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';
import { CreateButton } from 'component/common/CreateButton/CreateButton';
Expand Down Expand Up @@ -37,16 +35,14 @@ const StyledLimit = styled(Limit)(({ theme }) => ({
}));

const useApiTokenLimit = () => {
const resourceLimitsEnabled = useUiFlag('resourceLimits');
const { tokens, loading: loadingTokens } = useApiTokens();
const { uiConfig, loading: loadingConfig } = useUiConfig();
const apiTokensLimit = uiConfig.resourceLimits.apiTokens;

return {
resourceLimitsEnabled,
limit: apiTokensLimit,
currentValue: tokens.length,
limitReached: resourceLimitsEnabled && tokens.length >= apiTokensLimit,
limitReached: tokens.length >= apiTokensLimit,
loading: loadingConfig || loadingTokens,
};
};
Expand All @@ -58,7 +54,6 @@ export const CreateApiToken = ({ modal = false }: ICreateApiTokenProps) => {
const [showConfirm, setShowConfirm] = useState(false);
const [token, setToken] = useState('');
const {
resourceLimitsEnabled,
limit,
currentValue,
limitReached,
Expand Down Expand Up @@ -176,16 +171,11 @@ export const CreateApiToken = ({ modal = false }: ICreateApiTokenProps) => {
environment={environment}
setEnvironment={setEnvironment}
/>
<ConditionallyRender
condition={resourceLimitsEnabled}
show={
<StyledLimit
name='API tokens'
shortName='tokens'
currentValue={currentValue}
limit={limit}
/>
}
<StyledLimit
name='API tokens'
shortName='tokens'
currentValue={currentValue}
limit={limit}
/>
</ApiTokenForm>
<ConfirmToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ const setupApi = ({
apiTokenLimit,
}: { apiTokenCount: number; apiTokenLimit: number }) => {
testServerRoute(server, '/api/admin/ui-config', {
flags: {
resourceLimits: true,
},
resourceLimits: {
apiTokens: apiTokenLimit,
},
resourceLimits: { apiTokens: apiTokenLimit },
});

testServerRoute(server, '/api/admin/api-tokens', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CREATE_API_TOKEN_BUTTON } from 'utils/testIds';
import { useNavigate } from 'react-router-dom';
import Add from '@mui/icons-material/Add';
import { useApiTokens } from 'hooks/api/getters/useApiTokens/useApiTokens';
import { useUiFlag } from 'hooks/useUiFlag';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
interface ICreateApiTokenButton {
path: string;
Expand All @@ -12,9 +11,7 @@ interface ICreateApiTokenButton {
}

const useApiTokenLimit = (apiTokenLimit: number, apiTokenCount: number) => {
const resourceLimitsEnabled = useUiFlag('resourceLimits');
const limitReached =
resourceLimitsEnabled && apiTokenCount >= apiTokenLimit;
const limitReached = apiTokenCount >= apiTokenLimit;

return {
limitReached,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ import { FreeTextInput } from './FreeTextInput';
const server = testServerSetup();

const LIMIT = 3;

const setupApi = () => {
testServerRoute(server, '/api/admin/ui-config', {
flags: {
resourceLimits: true,
},
resourceLimits: {
constraintValues: LIMIT,
},
resourceLimits: { constraintValues: LIMIT },
});
};

Expand Down Expand Up @@ -126,8 +120,8 @@ test('should show limit reached indicator', async () => {
<FreeTextInput
error=''
values={['1', '2', '3']}
setValues={(newValues) => {}}
setError={(newError: string) => {}}
setValues={() => {}}
setError={() => {}}
removeValue={() => {}}
/>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import type React from 'react';
import { useState } from 'react';
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
import { parseParameterStrings } from 'utils/parseParameter';
import { useUiFlag } from 'hooks/useUiFlag';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Limit } from 'component/common/Limit/Limit';

interface IFreeTextInputProps {
Expand Down Expand Up @@ -72,7 +70,6 @@ export const FreeTextInput = ({
}: IFreeTextInputProps) => {
const [inputValues, setInputValues] = useState('');
const { classes: styles } = useStyles();
const resourceLimitsEnabled = useUiFlag('resourceLimits');
const { uiConfig, loading } = useUiConfig();
const constraintValuesLimit = uiConfig.resourceLimits.constraintValues;

Expand All @@ -88,9 +85,7 @@ export const FreeTextInput = ({
...values,
...parseParameterStrings(inputValues),
]);
const limitReached = Boolean(
resourceLimitsEnabled && newValues.length > constraintValuesLimit,
);
const limitReached = Boolean(newValues.length > constraintValuesLimit);

if (limitReached) {
setError(
Expand Down Expand Up @@ -148,16 +143,11 @@ export const FreeTextInput = ({
/>
</div>
<LimitContainer>
<ConditionallyRender
condition={resourceLimitsEnabled}
show={
<Limit
name='single constraint values'
shortName='values'
currentValue={values.length}
limit={constraintValuesLimit}
/>
}
<Limit
name='single constraint values'
shortName='values'
currentValue={values.length}
limit={constraintValuesLimit}
/>
</LimitContainer>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import { ADMIN } from '../../providers/AccessProvider/permissions';
const server = testServerSetup();

const setupApi = ({
resourceLimits,
limit,
environments,
}: { resourceLimits: boolean; limit: number; environments: number }) => {
}: { limit: number; environments: number }) => {
testServerRoute(server, '/api/admin/ui-config', {
flags: {
resourceLimits,
},
resourceLimits: {
environments: limit,
},
Expand All @@ -28,7 +24,7 @@ const setupApi = ({
};

test('show limit reached info', async () => {
setupApi({ environments: 1, limit: 1, resourceLimits: true });
setupApi({ environments: 1, limit: 1 });
render(<CreateEnvironment />, { permissions: [{ permission: ADMIN }] });

await screen.findByText('You have reached the limit for environments');
Expand All @@ -39,7 +35,7 @@ test('show limit reached info', async () => {
});

test('show approaching limit info', async () => {
setupApi({ environments: 9, limit: 10, resourceLimits: true });
setupApi({ environments: 9, limit: 10 });
render(<CreateEnvironment />, { permissions: [{ permission: ADMIN }] });

await screen.findByText('You are nearing the limit for environments');
Expand All @@ -48,10 +44,3 @@ test('show approaching limit info', async () => {
});
expect(createButton).toBeEnabled();
});

test('show limit reached info - no resource limits component', async () => {
setupApi({ environments: 1, limit: 1, resourceLimits: false });
render(<CreateEnvironment />);

await screen.findByText('Go back');
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@ import { useNavigate } from 'react-router-dom';
import useEnvironmentForm from '../hooks/useEnvironmentForm';
import EnvironmentForm from '../EnvironmentForm/EnvironmentForm';
import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import { Alert } from '@mui/material';
import { Button } from '@mui/material';
import { CreateButton } from 'component/common/CreateButton/CreateButton';
import useEnvironmentApi from 'hooks/api/actions/useEnvironmentApi/useEnvironmentApi';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import useToast from 'hooks/useToast';
import { useEnvironments } from 'hooks/api/getters/useEnvironments/useEnvironments';
import usePermissions from 'hooks/api/getters/usePermissions/usePermissions';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { PageContent } from 'component/common/PageContent/PageContent';
import { ADMIN } from 'component/providers/AccessProvider/permissions';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import { formatUnknownError } from 'utils/formatUnknownError';
import { GO_BACK } from 'constants/navigate';
import { Limit } from 'component/common/Limit/Limit';
import { useUiFlag } from 'hooks/useUiFlag';

const CreateEnvironment = () => {
const { setToastApiError, setToastData } = useToast();
const { uiConfig } = useUiConfig();
const resourceLimitsEnabled = useUiFlag('resourceLimits');
const environmentLimit = uiConfig.resourceLimits.environments;
const navigate = useNavigate();
const { environments } = useEnvironments();
Expand Down Expand Up @@ -73,13 +66,10 @@ const CreateEnvironment = () => {
};

return (
<ConditionallyRender
condition={resourceLimitsEnabled || canCreateMoreEnvs}
show={
<FormTemplate
loading={loading}
title='Create environment'
description='Environments allow you to manage your
<FormTemplate
loading={loading}
title='Create environment'
description='Environments allow you to manage your
product lifecycle from local development
through production. Your projects and
feature flags are accessible in all your
Expand All @@ -89,66 +79,36 @@ const CreateEnvironment = () => {
development or test environment without
enabling the feature flag in the
production environment.'
documentationLink='https://docs.getunleash.io/reference/environments'
documentationLinkLabel='Environments documentation'
formatApiCode={formatApiCode}
>
<EnvironmentForm
errors={errors}
handleSubmit={handleSubmit}
handleCancel={handleCancel}
validateEnvironmentName={validateEnvironmentName}
name={name}
type={type}
setName={setName}
setType={setType}
mode='Create'
clearErrors={clearErrors}
Limit={
<ConditionallyRender
condition={resourceLimitsEnabled}
show={
<Limit
name='environments'
limit={environmentLimit}
currentValue={environments.length}
/>
}
/>
}
>
<CreateButton
name='environment'
permission={ADMIN}
disabled={!canCreateMoreEnvs}
/>
</EnvironmentForm>
</FormTemplate>
}
elseShow={
<>
<PageContent
header={<PageHeader title='Create environment' />}
>
<Alert severity='error'>
<p>
Currently Unleash does not support more than{' '}
{environmentLimit} environments. If you need
more please reach out.
</p>
</Alert>
<br />
<Button
onClick={handleCancel}
variant='contained'
color='primary'
>
Go back
</Button>
</PageContent>
</>
}
/>
documentationLink='https://docs.getunleash.io/reference/environments'
documentationLinkLabel='Environments documentation'
formatApiCode={formatApiCode}
>
<EnvironmentForm
errors={errors}
handleSubmit={handleSubmit}
handleCancel={handleCancel}
validateEnvironmentName={validateEnvironmentName}
name={name}
type={type}
setName={setName}
setType={setType}
mode='Create'
clearErrors={clearErrors}
Limit={
<Limit
name='environments'
limit={environmentLimit}
currentValue={environments.length}
/>
}
>
<CreateButton
name='environment'
permission={ADMIN}
disabled={!canCreateMoreEnvs}
/>
</EnvironmentForm>
</FormTemplate>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const LIMIT = 5;

const setupApi = () => {
testServerRoute(server, '/api/admin/ui-config', {
flags: {
resourceLimits: true,
},
resourceLimits: {
constraints: LIMIT,
},
Expand Down
Loading

0 comments on commit 4615ff4

Please sign in to comment.