From f39d1021d0c946f4cc5686f3bac66c4cc9a05caa Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Mon, 31 Oct 2022 13:46:54 +0100 Subject: [PATCH] feat: discard suggested draft change (#2285) * feat: discard suggested draft change * fix: suggest changes api frontend integration * fix suggested changes discard --- .../DraftBanner/DraftBanner.tsx | 2 +- .../SuggestedFeatureToggleChange.tsx | 17 ++++++-- .../ToggleStatusChange.tsx | 37 +++++++++++++---- .../SuggestedChangesSidebar.tsx | 4 ++ .../SuggestedChangeset/SuggestedChangeset.tsx | 41 +++++++++++++++++-- .../useSuggestChangeApi.ts | 17 ++++++++ 6 files changed, 101 insertions(+), 17 deletions(-) diff --git a/frontend/src/component/suggestChanges/DraftBanner/DraftBanner.tsx b/frontend/src/component/suggestChanges/DraftBanner/DraftBanner.tsx index 7ff4b90e708..f399e607bf8 100644 --- a/frontend/src/component/suggestChanges/DraftBanner/DraftBanner.tsx +++ b/frontend/src/component/suggestChanges/DraftBanner/DraftBanner.tsx @@ -16,7 +16,7 @@ export const DraftBanner: VFC = ({ project }) => { const { draft, loading } = useSuggestedChangesDraft(project); const environment = ''; - if (!loading && draft?.length === 0) { + if ((!loading && !draft) || draft?.length === 0) { return null; } diff --git a/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/SuggestedFeatureToggleChange.tsx b/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/SuggestedFeatureToggleChange.tsx index a134ffe46f0..6e1dd3c80ec 100644 --- a/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/SuggestedFeatureToggleChange.tsx +++ b/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/SuggestedFeatureToggleChange.tsx @@ -1,14 +1,17 @@ import { FC } from 'react'; +import { Link } from 'react-router-dom'; import { Box, Card, Typography } from '@mui/material'; import ToggleOnIcon from '@mui/icons-material/ToggleOn'; interface ISuggestedFeatureToggleChange { - featureToggleName: string; + featureName: string; + projectId: string; + onNavigate?: () => void; } export const SuggestedFeatureToggleChange: FC< ISuggestedFeatureToggleChange -> = ({ featureToggleName, children }) => { +> = ({ featureName, projectId, onNavigate, children }) => { return ( - {featureToggleName} + + {featureName} + {children} diff --git a/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/ToggleStatusChange.tsx b/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/ToggleStatusChange.tsx index bad5907f347..f8da0ccc6b7 100644 --- a/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/ToggleStatusChange.tsx +++ b/frontend/src/component/suggestChanges/SuggestedChangeOverview/SuggestedFeatureToggleChange/ToggleStatusChange.tsx @@ -1,15 +1,34 @@ -import { Box } from '@mui/material'; -import { FC } from 'react'; +import { VFC } from 'react'; +import { Link, Box, Typography } from '@mui/material'; import { PlaygroundResultChip } from 'component/playground/Playground/PlaygroundResultsTable/PlaygroundResultChip/PlaygroundResultChip'; +import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; -export const ToggleStatusChange: FC<{ enabled: boolean }> = ({ enabled }) => { +interface IPlaygroundResultsTable { + enabled: boolean; + onDiscard?: () => void; +} + +export const ToggleStatusChange: VFC = ({ + enabled, + onDiscard, +}) => { return ( - - New status:{' '} - + + New status:{' '} + + + + Discard + + } /> ); diff --git a/frontend/src/component/suggestChanges/SuggestedChangesSidebar/SuggestedChangesSidebar.tsx b/frontend/src/component/suggestChanges/SuggestedChangesSidebar/SuggestedChangesSidebar.tsx index 84f10fa5355..46e2afd0d70 100644 --- a/frontend/src/component/suggestChanges/SuggestedChangesSidebar/SuggestedChangesSidebar.tsx +++ b/frontend/src/component/suggestChanges/SuggestedChangesSidebar/SuggestedChangesSidebar.tsx @@ -135,6 +135,10 @@ export const SuggestedChangesSidebar: VFC = ({
{ + onClose(); + }} + onRefetch={refetchSuggestedChanges} /> = ({ suggestedChange }) => { + onRefetch?: () => void; + onNavigate?: () => void; +} + +export const SuggestedChangeset: VFC = ({ + suggestedChange, + onRefetch, + onNavigate, +}) => { + const { discardSuggestions } = useSuggestChangeApi(); + const { setToastData, setToastApiError } = useToast(); + const onDiscard = (id: number) => async () => { + try { + await discardSuggestions( + suggestedChange.project, + suggestedChange.id, + id + ); + setToastData({ + title: 'Change discarded from suggestion draft.', + type: 'success', + }); + onRefetch?.(); + } catch (error: unknown) { + setToastApiError(formatUnknownError(error)); + } + }; + return ( Changes {suggestedChange.features?.map(featureToggleChange => ( {featureToggleChange.changes.map(change => ( @@ -33,6 +65,7 @@ export const SuggestedChangeset: FC<{ show={ } /> diff --git a/frontend/src/hooks/api/actions/useSuggestChangeApi/useSuggestChangeApi.ts b/frontend/src/hooks/api/actions/useSuggestChangeApi/useSuggestChangeApi.ts index 3533ccaa844..1267802c794 100644 --- a/frontend/src/hooks/api/actions/useSuggestChangeApi/useSuggestChangeApi.ts +++ b/frontend/src/hooks/api/actions/useSuggestChangeApi/useSuggestChangeApi.ts @@ -64,10 +64,27 @@ export const useSuggestChangeApi = () => { } }; + const discardSuggestions = async ( + project: string, + changesetId: number, + changeId: number + ) => { + const path = `api/admin/projects/${project}/suggest-changes/${changesetId}/changes/${changeId}`; + const req = createRequest(path, { + method: 'DELETE', + }); + try { + return await makeRequest(req.caller, req.id); + } catch (e) { + throw e; + } + }; + return { addSuggestion, applyChanges, changeState, + discardSuggestions, errors, loading, };