mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: add changes to draft (#2271)
* feat: add changes to draft * Make domain type and schema match * Deleting change from changeset * Add ability to merge * Revert "Add ability to merge" This reverts commit504e7e796e
. * gRevert "Deleting change from changeset" This reverts commit2effc20378
. * Revert "Make domain type and schema match" This reverts commit079f46c0db
. Co-authored-by: sjaanus <sellinjaanus@gmail.com>
This commit is contained in:
parent
b2c099a1c0
commit
c6c873d67d
@ -38,8 +38,9 @@ const FeatureOverviewEnvSwitch = ({
|
|||||||
const {
|
const {
|
||||||
onSuggestToggle,
|
onSuggestToggle,
|
||||||
onSuggestToggleClose,
|
onSuggestToggleClose,
|
||||||
|
onSuggestToggleConfirm,
|
||||||
suggestChangesDialogDetails,
|
suggestChangesDialogDetails,
|
||||||
} = useSuggestToggle();
|
} = useSuggestToggle(projectId);
|
||||||
|
|
||||||
const handleToggleEnvironmentOn = async () => {
|
const handleToggleEnvironmentOn = async () => {
|
||||||
try {
|
try {
|
||||||
@ -123,7 +124,7 @@ const FeatureOverviewEnvSwitch = ({
|
|||||||
onClose={onSuggestToggleClose}
|
onClose={onSuggestToggleClose}
|
||||||
featureName={featureId}
|
featureName={featureId}
|
||||||
environment={suggestChangesDialogDetails?.environment}
|
environment={suggestChangesDialogDetails?.environment}
|
||||||
onConfirm={() => {}}
|
onConfirm={onSuggestToggleConfirm}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -104,8 +104,9 @@ export const ProjectFeatureToggles = ({
|
|||||||
const {
|
const {
|
||||||
onSuggestToggle,
|
onSuggestToggle,
|
||||||
onSuggestToggleClose,
|
onSuggestToggleClose,
|
||||||
|
onSuggestToggleConfirm,
|
||||||
suggestChangesDialogDetails,
|
suggestChangesDialogDetails,
|
||||||
} = useSuggestToggle();
|
} = useSuggestToggle(projectId);
|
||||||
|
|
||||||
const onToggle = useCallback(
|
const onToggle = useCallback(
|
||||||
async (
|
async (
|
||||||
@ -521,7 +522,7 @@ export const ProjectFeatureToggles = ({
|
|||||||
onClose={onSuggestToggleClose}
|
onClose={onSuggestToggleClose}
|
||||||
featureName={suggestChangesDialogDetails?.featureName}
|
featureName={suggestChangesDialogDetails?.featureName}
|
||||||
environment={suggestChangesDialogDetails?.environment}
|
environment={suggestChangesDialogDetails?.environment}
|
||||||
onConfirm={() => {}}
|
onConfirm={onSuggestToggleConfirm}
|
||||||
/>
|
/>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
);
|
);
|
||||||
|
@ -17,7 +17,7 @@ export const DraftBanner: VFC<IDraftBannerProps> = ({ environment }) => {
|
|||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: 'sticky',
|
position: 'sticky',
|
||||||
top: 0,
|
top: -1,
|
||||||
zIndex: theme => theme.zIndex.appBar,
|
zIndex: theme => theme.zIndex.appBar,
|
||||||
borderTop: theme => `1px solid ${theme.palette.warning.border}`,
|
borderTop: theme => `1px solid ${theme.palette.warning.border}`,
|
||||||
borderBottom: theme =>
|
borderBottom: theme =>
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { Alert, Box, Typography } from '@mui/material';
|
import { Alert, Typography } from '@mui/material';
|
||||||
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
||||||
import useToast from 'hooks/useToast';
|
|
||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
|
||||||
|
|
||||||
interface ISuggestChangesDialogueProps {
|
interface ISuggestChangesDialogueProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -20,31 +18,19 @@ export const SuggestChangesDialogue: FC<ISuggestChangesDialogueProps> = ({
|
|||||||
enabled,
|
enabled,
|
||||||
featureName,
|
featureName,
|
||||||
environment,
|
environment,
|
||||||
}) => {
|
}) => (
|
||||||
const { setToastData, setToastApiError } = useToast();
|
|
||||||
|
|
||||||
const onSuggestClick = async () => {
|
|
||||||
try {
|
|
||||||
alert('Suggesting changes');
|
|
||||||
onConfirm();
|
|
||||||
} catch (error: unknown) {
|
|
||||||
setToastApiError(formatUnknownError(error));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialogue
|
<Dialogue
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
primaryButtonText="Add to draft"
|
primaryButtonText="Add to draft"
|
||||||
secondaryButtonText="Cancel"
|
secondaryButtonText="Cancel"
|
||||||
onClick={onSuggestClick}
|
onClick={onConfirm}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
title="Suggest changes"
|
title="Suggest changes"
|
||||||
>
|
>
|
||||||
<Alert severity="info" sx={{ mb: 2 }}>
|
<Alert severity="info" sx={{ mb: 2 }}>
|
||||||
Suggest changes is enabled for {environment}. Your changes needs
|
Suggest changes is enabled for {environment}. Your changes needs to
|
||||||
to be approved before they will be live. All the changes you do
|
be approved before they will be live. All the changes you do now
|
||||||
now will be added into a draft that you can submit for review.
|
will be added into a draft that you can submit for review.
|
||||||
</Alert>
|
</Alert>
|
||||||
<Typography variant="body2" color="text.secondary">
|
<Typography variant="body2" color="text.secondary">
|
||||||
Suggested changes:
|
Suggested changes:
|
||||||
@ -55,4 +41,3 @@ export const SuggestChangesDialogue: FC<ISuggestChangesDialogueProps> = ({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Dialogue>
|
</Dialogue>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
import useAPI from '../useApi/useApi';
|
||||||
|
|
||||||
|
interface ISuggestChangeSchema {
|
||||||
|
feature: string;
|
||||||
|
action:
|
||||||
|
| 'updateEnabled'
|
||||||
|
| 'strategyAdd'
|
||||||
|
| 'strategyUpdate'
|
||||||
|
| 'strategyDelete';
|
||||||
|
payload: string | boolean | object | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSuggestChangeApi = (project: string) => {
|
||||||
|
const { makeRequest, createRequest, errors, loading } = useAPI({
|
||||||
|
propagateErrors: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const addSuggestion = async (
|
||||||
|
environment: string,
|
||||||
|
payload: ISuggestChangeSchema
|
||||||
|
) => {
|
||||||
|
const path = `api/admin/projects/${project}/environments/${environment}/suggest-changes`;
|
||||||
|
const req = createRequest(path, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const response = await makeRequest(req.caller, req.id);
|
||||||
|
return await response.json();
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
addSuggestion,
|
||||||
|
errors,
|
||||||
|
loading,
|
||||||
|
};
|
||||||
|
};
|
@ -1,6 +1,11 @@
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
import useToast from 'hooks/useToast';
|
||||||
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
|
import { useSuggestChangeApi } from './api/actions/useSuggestChangeApi/useSuggestChangeApi';
|
||||||
|
|
||||||
export const useSuggestToggle = () => {
|
export const useSuggestToggle = (project: string) => {
|
||||||
|
const { setToastData, setToastApiError } = useToast();
|
||||||
|
const { addSuggestion } = useSuggestChangeApi(project);
|
||||||
const [suggestChangesDialogDetails, setSuggestChangesDialogDetails] =
|
const [suggestChangesDialogDetails, setSuggestChangesDialogDetails] =
|
||||||
useState<{
|
useState<{
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
@ -25,9 +30,30 @@ export const useSuggestToggle = () => {
|
|||||||
setSuggestChangesDialogDetails({ isOpen: false });
|
setSuggestChangesDialogDetails({ isOpen: false });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onSuggestToggleConfirm = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await addSuggestion(suggestChangesDialogDetails.environment!, {
|
||||||
|
feature: suggestChangesDialogDetails.featureName!,
|
||||||
|
action: 'updateEnabled',
|
||||||
|
payload: {
|
||||||
|
enabled: Boolean(suggestChangesDialogDetails.enabled),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setSuggestChangesDialogDetails({ isOpen: false });
|
||||||
|
setToastData({
|
||||||
|
type: 'success',
|
||||||
|
title: 'Changes added to the draft!',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setToastApiError(formatUnknownError(error));
|
||||||
|
setSuggestChangesDialogDetails({ isOpen: false });
|
||||||
|
}
|
||||||
|
}, [addSuggestion]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onSuggestToggle,
|
onSuggestToggle,
|
||||||
onSuggestToggleClose,
|
onSuggestToggleClose,
|
||||||
|
onSuggestToggleConfirm,
|
||||||
suggestChangesDialogDetails,
|
suggestChangesDialogDetails,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user