1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

1-1307: Show info about flag naming patterns before making mistakes (#4616)

This PR adds info about a project's flag naming pattern to the flag
creation form. This way, it's displayed before the user tries to create
a flag, so that they have all the necessary information before making
mistakes.


![image](https://github.com/Unleash/unleash/assets/17786332/7a3fb036-5315-4c2b-934d-004da6b364a3)
This commit is contained in:
Thomas Heartman 2023-09-06 12:14:17 +02:00 committed by GitHub
parent 0b8b772ff1
commit 1ffa0b86d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View File

@ -137,6 +137,7 @@ const CreateFeature = () => {
handleCancel={handleCancel} handleCancel={handleCancel}
mode="Create" mode="Create"
clearErrors={clearErrors} clearErrors={clearErrors}
featureNaming={projectInfo.featureNaming}
> >
<CreateButton <CreateButton
name="feature toggle" name="feature toggle"

View File

@ -21,6 +21,7 @@ import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import React from 'react'; import React from 'react';
import { useAuthPermissions } from 'hooks/api/getters/useAuth/useAuthPermissions'; import { useAuthPermissions } from 'hooks/api/getters/useAuth/useAuthPermissions';
import { FeatureNamingType } from 'interfaces/project';
interface IFeatureToggleForm { interface IFeatureToggleForm {
type: string; type: string;
@ -33,6 +34,7 @@ interface IFeatureToggleForm {
setDescription: React.Dispatch<React.SetStateAction<string>>; setDescription: React.Dispatch<React.SetStateAction<string>>;
setProject: React.Dispatch<React.SetStateAction<string>>; setProject: React.Dispatch<React.SetStateAction<string>>;
setImpressionData: React.Dispatch<React.SetStateAction<boolean>>; setImpressionData: React.Dispatch<React.SetStateAction<boolean>>;
featureNaming?: FeatureNamingType;
validateToggleName?: () => void; validateToggleName?: () => void;
handleSubmit: (e: any) => void; handleSubmit: (e: any) => void;
handleCancel: () => void; handleCancel: () => void;
@ -80,6 +82,11 @@ const StyledTypeDescription = styled('p')(({ theme }) => ({
position: 'relative', position: 'relative',
})); }));
const StyledFlagNamingInfo = styled('div')(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
color: theme.palette.text.secondary,
}));
const StyledButtonContainer = styled('div')({ const StyledButtonContainer = styled('div')({
marginTop: 'auto', marginTop: 'auto',
display: 'flex', display: 'flex',
@ -111,6 +118,7 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
setDescription, setDescription,
setProject, setProject,
validateToggleName, validateToggleName,
featureNaming,
setImpressionData, setImpressionData,
impressionData, impressionData,
handleSubmit, handleSubmit,
@ -128,16 +136,52 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
return featureTypes.find(toggle => toggle.id === type)?.description; return featureTypes.find(toggle => toggle.id === type)?.description;
}; };
const displayFeatureNamingInfo = Boolean(featureNaming?.pattern);
return ( return (
<StyledForm onSubmit={handleSubmit}> <StyledForm onSubmit={handleSubmit}>
<StyledContainer> <StyledContainer>
<StyledInputDescription> <StyledInputDescription>
What would you like to call your toggle? What would you like to call your toggle?
</StyledInputDescription> </StyledInputDescription>
<ConditionallyRender
condition={displayFeatureNamingInfo}
show={
<StyledFlagNamingInfo>
<p>
This project has feature flag naming patterns
enabled.
</p>
<dl id="feature-naming-pattern-info">
<dt>Pattern</dt>
<dd>
<code>{featureNaming?.pattern}</code>
</dd>
{Boolean(featureNaming?.example) && (
<>
<dt>Example</dt>
<dd>{featureNaming?.example}</dd>
</>
)}
{Boolean(featureNaming?.description) && (
<>
<dt>Description</dt>
<dd>{featureNaming?.description}</dd>
</>
)}
</dl>
</StyledFlagNamingInfo>
}
/>
<StyledInput <StyledInput
autoFocus autoFocus
disabled={mode === 'Edit'} disabled={mode === 'Edit'}
label="Name" label="Name"
aria-details={
displayFeatureNamingInfo
? 'feature-naming-pattern-info'
: undefined
}
id="feature-toggle-name" id="feature-toggle-name"
error={Boolean(errors.name)} error={Boolean(errors.name)}
errorText={errors.name} errorText={errors.name}

View File

@ -352,7 +352,7 @@ const ProjectForm: React.FC<IProjectForm> = ({
label={'Naming Example'} label={'Naming Example'}
name="feature flag naming example" name="feature flag naming example"
type={'text'} type={'text'}
aria-describedBy="pattern-additional-description" aria-describedby="pattern-additional-description"
value={featureNamingExample || ''} value={featureNamingExample || ''}
placeholder="dx.feature1.1-135" placeholder="dx.feature1.1-135"
error={Boolean(errors.namingExample)} error={Boolean(errors.namingExample)}
@ -367,7 +367,7 @@ const ProjectForm: React.FC<IProjectForm> = ({
label={'Naming pattern description'} label={'Naming pattern description'}
name="feature flag naming description" name="feature flag naming description"
type={'text'} type={'text'}
aria-describedBy="pattern-additional-description" aria-describedby="pattern-additional-description"
placeholder={`<project>.<featureName>.<ticket> placeholder={`<project>.<featureName>.<ticket>
The flag name should contain the project name, the feature name, and the ticket number, each separated by a dot.`} The flag name should contain the project name, the feature name, and the ticket number, each separated by a dot.`}