Skip to content

Commit

Permalink
1-1342: show flag naming pattern info when you copy toggles (#4629)
Browse files Browse the repository at this point in the history
Because you need to match the pattern when copying toggles, it's
important that we show the required information to the user.

This change adds information about the pattern to the page. This isn't
its final design, but it's more important that the information is
there (to avoid user frustration) than that it is pretty.
  • Loading branch information
thomasheartman authored Sep 7, 2023
1 parent cfbf47d commit 3b754ec
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions frontend/src/component/feature/CopyFeature/CopyFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { useChangeRequestsEnabled } from '../../../hooks/useChangeRequestsEnabled';
import useProject from 'hooks/api/getters/useProject/useProject';

const StyledPage = styled(Paper)(({ theme }) => ({
overflow: 'visible',
Expand Down Expand Up @@ -69,6 +70,10 @@ export const CopyFeatureToggle = () => {
const { isChangeRequestConfiguredInAnyEnv } =
useChangeRequestsEnabled(projectId);

const {
project: { featureNaming },
} = useProject(projectId);

const setValue: ChangeEventHandler<HTMLInputElement> = event => {
const value = trim(event.target.value);
setNewToggleName(value);
Expand Down Expand Up @@ -111,6 +116,8 @@ export const CopyFeatureToggle = () => {

if (!feature || !feature.name) return <span>Toggle not found</span>;

const displayFeatureNamingInfo = Boolean(featureNaming?.pattern);

return (
<StyledPage className={themeStyles.fullwidth}>
<StyledHeader>
Expand All @@ -130,6 +137,47 @@ export const CopyFeatureToggle = () => {
. You must give the new feature toggle a unique name before
you can proceed.
</StyledDescription>

<ConditionallyRender
condition={displayFeatureNamingInfo}
show={
<>
<p>
This project has feature flag naming patterns
enabled, so the name must also match the
configured pattern.
</p>
<dl id="feature-naming-pattern-info">
<dt>Pattern</dt>
<dd>
<code>{featureNaming?.pattern}</code>
</dd>
<ConditionallyRender
condition={Boolean(featureNaming?.example)}
show={
<>
<dt>Example</dt>
<dd>{featureNaming?.example}</dd>
</>
}
/>
<ConditionallyRender
condition={Boolean(
featureNaming?.description
)}
show={
<>
<dt>Description</dt>
<dd>
{featureNaming?.description}
</dd>
</>
}
/>
</dl>
</>
}
/>
<StyledForm onSubmit={onSubmit}>
<TextField
label="Name"
Expand All @@ -142,6 +190,11 @@ export const CopyFeatureToggle = () => {
variant="outlined"
size="small"
aria-required
aria-details={
displayFeatureNamingInfo
? 'feature-naming-pattern-info'
: undefined
}
autoFocus
/>
<StyledFormControlLabel
Expand Down

0 comments on commit 3b754ec

Please sign in to comment.