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

feat: add impressionData switch to create feature form (#639)

* feat: add impressionData switch to create feature form

* fix: update text

* fix: styling

* fix: conflict

* fix: update link

* fix: remove unused styles

Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
This commit is contained in:
Youssef Khedher 2022-02-03 12:39:43 +01:00 committed by GitHub
parent d4a4c80b33
commit 899a0f330e
7 changed files with 84 additions and 16 deletions

View File

@ -28,6 +28,8 @@ const CreateFeature = () => {
description, description,
setDescription, setDescription,
validateToggleName, validateToggleName,
impressionData,
setImpressionData,
getTogglePayload, getTogglePayload,
clearErrors, clearErrors,
errors, errors,
@ -90,6 +92,8 @@ const CreateFeature = () => {
setProject={setProject} setProject={setProject}
setDescription={setDescription} setDescription={setDescription}
validateToggleName={validateToggleName} validateToggleName={validateToggleName}
setImpressionData={setImpressionData}
impressionData={impressionData}
errors={errors} errors={errors}
handleSubmit={handleSubmit} handleSubmit={handleSubmit}
handleCancel={handleCancel} handleCancel={handleCancel}

View File

@ -29,17 +29,20 @@ const EditFeature = () => {
setProject, setProject,
description, description,
setDescription, setDescription,
impressionData,
setImpressionData,
clearErrors, clearErrors,
errors, errors,
} = useFeatureForm( } = useFeatureForm(
feature?.name, feature?.name,
feature?.type, feature?.type,
feature?.project, feature?.project,
feature?.description feature?.description,
feature?.impressionData
); );
const createPatch = () => { const createPatch = () => {
const comparison = { ...feature, type, description }; const comparison = { ...feature, type, description, impressionData };
const patch = jsonpatch.compare(feature, comparison); const patch = jsonpatch.compare(feature, comparison);
return patch; return patch;
}; };
@ -95,11 +98,12 @@ const EditFeature = () => {
errors={errors} errors={errors}
handleSubmit={handleSubmit} handleSubmit={handleSubmit}
handleCancel={handleCancel} handleCancel={handleCancel}
impressionData={impressionData}
setImpressionData={setImpressionData}
mode="Edit" mode="Edit"
clearErrors={clearErrors} clearErrors={clearErrors}
> >
<PermissionButton <PermissionButton
onClick={handleSubmit}
permission={UPDATE_FEATURE} permission={UPDATE_FEATURE}
projectId={project} projectId={project}
type="submit" type="submit"

View File

@ -17,6 +17,9 @@ export const useStyles = makeStyles(theme => ({
minWidth: '379px', minWidth: '379px',
}, },
}, },
link: {
color: theme.palette.primary.light,
},
label: { label: {
minWidth: '300px', minWidth: '300px',
[theme.breakpoints.down(600)]: { [theme.breakpoints.down(600)]: {
@ -58,4 +61,12 @@ export const useStyles = makeStyles(theme => ({
position: 'absolute', position: 'absolute',
top: '-8px', top: '-8px',
}, },
roleSubtitle: {
margin: '0.5rem 0',
},
flexRow: {
display: 'flex',
alignItems: 'center',
marginTop: '0.5rem',
},
})); }));

View File

@ -1,6 +1,6 @@
import { CREATE_FEATURE } from '../../../providers/AccessProvider/permissions'; import { CREATE_FEATURE } from '../../../providers/AccessProvider/permissions';
import Input from '../../../common/Input/Input'; import Input from '../../../common/Input/Input';
import { Button } from '@material-ui/core'; import { Button, FormControl, Switch, Typography } from '@material-ui/core';
import { useStyles } from './FeatureForm.styles'; import { useStyles } from './FeatureForm.styles';
import FeatureTypeSelect from '../../FeatureView2/FeatureSettings/FeatureSettingsMetadata/FeatureTypeSelect/FeatureTypeSelect'; import FeatureTypeSelect from '../../FeatureView2/FeatureSettings/FeatureSettingsMetadata/FeatureTypeSelect/FeatureTypeSelect';
import { CF_DESC_ID, CF_NAME_ID, CF_TYPE_ID } from '../../../../testIds'; import { CF_DESC_ID, CF_NAME_ID, CF_TYPE_ID } from '../../../../testIds';
@ -17,11 +17,13 @@ interface IFeatureToggleForm {
name: string; name: string;
description: string; description: string;
project: string; project: string;
impressionData: boolean;
setType: React.Dispatch<React.SetStateAction<string>>; setType: React.Dispatch<React.SetStateAction<string>>;
setName: React.Dispatch<React.SetStateAction<string>>; setName: React.Dispatch<React.SetStateAction<string>>;
setDescription: React.Dispatch<React.SetStateAction<string>>; setDescription: React.Dispatch<React.SetStateAction<string>>;
setProject: React.Dispatch<React.SetStateAction<string>>; setProject: React.Dispatch<React.SetStateAction<string>>;
validateToggleName: () => void; validateToggleName: () => void;
setImpressionData: React.Dispatch<React.SetStateAction<boolean>>;
handleSubmit: (e: any) => void; handleSubmit: (e: any) => void;
handleCancel: () => void; handleCancel: () => void;
errors: { [key: string]: string }; errors: { [key: string]: string };
@ -40,6 +42,8 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
setDescription, setDescription,
setProject, setProject,
validateToggleName, validateToggleName,
setImpressionData,
impressionData,
handleSubmit, handleSubmit,
handleCancel, handleCancel,
errors, errors,
@ -81,9 +85,7 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
</p> </p>
<FeatureTypeSelect <FeatureTypeSelect
value={type} value={type}
onChange={(e: React.SyntheticEvent) => onChange={(e: React.ChangeEvent) => setType(e.target.value)}
setType(e.target.value)
}
label={'Toggle type'} label={'Toggle type'}
id="feature-type-select" id="feature-type-select"
editable editable
@ -108,7 +110,6 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
value={project} value={project}
onChange={e => setProject(e.target.value)} onChange={e => setProject(e.target.value)}
enabled={editable} enabled={editable}
label="Project"
filter={projectFilterGenerator( filter={projectFilterGenerator(
{ permissions }, { permissions },
CREATE_FEATURE CREATE_FEATURE
@ -127,11 +128,39 @@ const FeatureForm: React.FC<IFeatureToggleForm> = ({
label="Description" label="Description"
placeholder="A short description of the feature toggle" placeholder="A short description of the feature toggle"
value={description} value={description}
inputProps={{ data-test={CF_DESC_ID}
'data-test': CF_DESC_ID,
}}
onChange={e => setDescription(e.target.value)} onChange={e => setDescription(e.target.value)}
/> />
<FormControl>
<Typography
variant="subtitle1"
className={styles.roleSubtitle}
data-loading
>
Impression Data
</Typography>
<p>
When you enable impression data for a feature toggle,
your client SDKs will emit events you can listen for
every time this toggle gets triggered. Learn more in{' '}
<a
className={styles.link}
target="_blank"
rel="noopener noreferrer"
href="https://docs.getunleash.io/advanced/impression_data"
>
the impression data documentation
</a>
</p>
<div className={styles.flexRow}>
<Switch
name="impressionData"
onChange={() => setImpressionData(!impressionData)}
checked={impressionData}
/>
<Typography>{impressionData ? 'Yes' : 'No'}</Typography>
</div>
</FormControl>
</div> </div>
<div className={styles.buttonContainer}> <div className={styles.buttonContainer}>

View File

@ -8,7 +8,8 @@ const useFeatureForm = (
initialName = '', initialName = '',
initialType = 'release', initialType = 'release',
initialProject = 'default', initialProject = 'default',
initialDescription = '' initialDescription = '',
initialImpressionData = false
) => { ) => {
const { projectId } = useParams<IFeatureViewParams>(); const { projectId } = useParams<IFeatureViewParams>();
const params = useQueryParams(); const params = useQueryParams();
@ -18,6 +19,9 @@ const useFeatureForm = (
const [name, setName] = useState(toggleQueryName || initialName); const [name, setName] = useState(toggleQueryName || initialName);
const [project, setProject] = useState(projectId || initialProject); const [project, setProject] = useState(projectId || initialProject);
const [description, setDescription] = useState(initialDescription); const [description, setDescription] = useState(initialDescription);
const [impressionData, setImpressionData] = useState<boolean>(
initialImpressionData
);
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
useEffect(() => { useEffect(() => {
@ -38,12 +42,17 @@ const useFeatureForm = (
setDescription(initialDescription); setDescription(initialDescription);
}, [initialDescription]); }, [initialDescription]);
useEffect(() => {
setImpressionData(initialImpressionData);
}, [initialImpressionData]);
const getTogglePayload = () => { const getTogglePayload = () => {
return { return {
type: type, type,
name: name, name,
projectId: project, projectId: project,
description: description, description: description,
impressionData
}; };
}; };
@ -81,6 +90,8 @@ const useFeatureForm = (
setProject, setProject,
description, description,
setDescription, setDescription,
impressionData,
setImpressionData,
getTogglePayload, getTogglePayload,
validateToggleName, validateToggleName,
clearErrors, clearErrors,

View File

@ -1,4 +1,4 @@
import { IFeatureToggleDTO } from '../../../../interfaces/featureToggle'; import { IFeatureTogglePayload } from '../../../../interfaces/featureToggle';
import { ITag } from '../../../../interfaces/tags'; import { ITag } from '../../../../interfaces/tags';
import useAPI from '../useApi/useApi'; import useAPI from '../useApi/useApi';
import { Operation } from 'fast-json-patch'; import { Operation } from 'fast-json-patch';
@ -26,7 +26,7 @@ const useFeatureApi = () => {
const createFeatureToggle = async ( const createFeatureToggle = async (
projectId: string, projectId: string,
featureToggle: IFeatureToggleDTO featureToggle: IFeatureTogglePayload
) => { ) => {
const path = `api/admin/projects/${projectId}/features`; const path = `api/admin/projects/${projectId}/features`;
const req = createRequest(path, { const req = createRequest(path, {

View File

@ -21,6 +21,14 @@ export interface IFeatureToggleDTO {
variants: IFeatureVariant[]; variants: IFeatureVariant[];
} }
export interface IFeatureTogglePayload {
description: string;
name: string;
projectId: string;
type: string;
impressionData: boolean;
}
export interface IFeatureToggle { export interface IFeatureToggle {
stale: boolean; stale: boolean;
archived: boolean; archived: boolean;
@ -32,6 +40,7 @@ export interface IFeatureToggle {
project: string; project: string;
type: string; type: string;
variants: IFeatureVariant[]; variants: IFeatureVariant[];
impressionData: boolean;
} }
export interface IFeatureEnvironment { export interface IFeatureEnvironment {