mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02:00
chore: set up context for sidebar CRs
This commit is contained in:
parent
e04bccace5
commit
e98fbf82cb
@ -1,4 +1,4 @@
|
|||||||
import { VFC } from 'react';
|
import { useState, VFC } from 'react';
|
||||||
import { Box, Button, styled, Typography } from '@mui/material';
|
import { Box, Button, styled, Typography } from '@mui/material';
|
||||||
import { DynamicSidebarModal } from 'component/common/SidebarModal/SidebarModal';
|
import { DynamicSidebarModal } from 'component/common/SidebarModal/SidebarModal';
|
||||||
import { PageContent } from 'component/common/PageContent/PageContent';
|
import { PageContent } from 'component/common/PageContent/PageContent';
|
||||||
@ -11,6 +11,7 @@ import useToast from 'hooks/useToast';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import { EnvironmentChangeRequest } from './EnvironmentChangeRequest/EnvironmentChangeRequest';
|
import { EnvironmentChangeRequest } from './EnvironmentChangeRequest/EnvironmentChangeRequest';
|
||||||
import { ReviewChangesHeader } from './ReviewChangesHeader/ReviewChangesHeader';
|
import { ReviewChangesHeader } from './ReviewChangesHeader/ReviewChangesHeader';
|
||||||
|
import { ChangeRequestPlausibleProvider } from '../ChangeRequestContext';
|
||||||
|
|
||||||
interface IChangeRequestSidebarProps {
|
interface IChangeRequestSidebarProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@ -76,15 +77,18 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
loading,
|
loading,
|
||||||
refetch: refetchChangeRequest,
|
refetch: refetchChangeRequest,
|
||||||
} = usePendingChangeRequests(project);
|
} = usePendingChangeRequests(project);
|
||||||
const { changeState, discardDraft } = useChangeRequestApi();
|
const { discardDraft } = useChangeRequestApi();
|
||||||
const { setToastApiError } = useToast();
|
const { setToastApiError } = useToast();
|
||||||
|
const [
|
||||||
|
changeRequestChangesWillOverwrite,
|
||||||
|
setChangeRequestChangesWillOverwrite,
|
||||||
|
] = useState(false);
|
||||||
|
|
||||||
const onReview = async (draftId: number, comment?: string) => {
|
const onReview = async (
|
||||||
|
changeState: (project: string) => Promise<void>,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
await changeState(project, draftId, 'Draft', {
|
await changeState(project);
|
||||||
state: 'In review',
|
|
||||||
comment,
|
|
||||||
});
|
|
||||||
refetchChangeRequest();
|
refetchChangeRequest();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
@ -130,19 +134,29 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
header={<ReviewChangesHeader />}
|
header={<ReviewChangesHeader />}
|
||||||
>
|
>
|
||||||
{data?.map((environmentChangeRequest) => (
|
{data?.map((environmentChangeRequest) => (
|
||||||
<EnvironmentChangeRequest
|
<ChangeRequestPlausibleProvider
|
||||||
key={environmentChangeRequest.id}
|
key={environmentChangeRequest.id}
|
||||||
environmentChangeRequest={environmentChangeRequest}
|
value={{
|
||||||
onClose={onClose}
|
willOverwriteStrategyChanges:
|
||||||
onReview={onReview}
|
changeRequestChangesWillOverwrite,
|
||||||
onDiscard={onDiscard}
|
registerWillOverwriteStrategyChanges: () =>
|
||||||
|
setChangeRequestChangesWillOverwrite(true),
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<ChangeRequest
|
<EnvironmentChangeRequest
|
||||||
changeRequest={environmentChangeRequest}
|
key={environmentChangeRequest.id}
|
||||||
onNavigate={onClose}
|
environmentChangeRequest={environmentChangeRequest}
|
||||||
onRefetch={refetchChangeRequest}
|
onClose={onClose}
|
||||||
/>
|
onReview={onReview}
|
||||||
</EnvironmentChangeRequest>
|
onDiscard={onDiscard}
|
||||||
|
>
|
||||||
|
<ChangeRequest
|
||||||
|
changeRequest={environmentChangeRequest}
|
||||||
|
onNavigate={onClose}
|
||||||
|
onRefetch={refetchChangeRequest}
|
||||||
|
/>
|
||||||
|
</EnvironmentChangeRequest>
|
||||||
|
</ChangeRequestPlausibleProvider>
|
||||||
))}
|
))}
|
||||||
</StyledPageContent>
|
</StyledPageContent>
|
||||||
</DynamicSidebarModal>
|
</DynamicSidebarModal>
|
||||||
|
@ -23,6 +23,7 @@ import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
|||||||
import Input from 'component/common/Input/Input';
|
import Input from 'component/common/Input/Input';
|
||||||
import { ChangeRequestTitle } from './ChangeRequestTitle';
|
import { ChangeRequestTitle } from './ChangeRequestTitle';
|
||||||
import { UpdateCount } from 'component/changeRequest/UpdateCount';
|
import { UpdateCount } from 'component/changeRequest/UpdateCount';
|
||||||
|
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
||||||
|
|
||||||
const SubmitChangeRequestButton: FC<{ onClick: () => void; count: number }> = ({
|
const SubmitChangeRequestButton: FC<{ onClick: () => void; count: number }> = ({
|
||||||
onClick,
|
onClick,
|
||||||
@ -56,7 +57,7 @@ const ChangeRequestContent = styled(Box)(({ theme }) => ({
|
|||||||
export const EnvironmentChangeRequest: FC<{
|
export const EnvironmentChangeRequest: FC<{
|
||||||
environmentChangeRequest: ChangeRequestType;
|
environmentChangeRequest: ChangeRequestType;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onReview: (id: number, comment?: string) => void;
|
onReview: (changeState: (project: string) => Promise<void>) => void;
|
||||||
onDiscard: (id: number) => void;
|
onDiscard: (id: number) => void;
|
||||||
}> = ({ environmentChangeRequest, onClose, onReview, onDiscard, children }) => {
|
}> = ({ environmentChangeRequest, onClose, onReview, onDiscard, children }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -64,6 +65,12 @@ export const EnvironmentChangeRequest: FC<{
|
|||||||
const [commentText, setCommentText] = useState('');
|
const [commentText, setCommentText] = useState('');
|
||||||
const { user } = useAuthUser();
|
const { user } = useAuthUser();
|
||||||
const [title, setTitle] = useState(environmentChangeRequest.title);
|
const [title, setTitle] = useState(environmentChangeRequest.title);
|
||||||
|
const { changeState } = useChangeRequestApi();
|
||||||
|
const sendToReview = async (project: string) =>
|
||||||
|
changeState(project, environmentChangeRequest.id, 'Draft', {
|
||||||
|
state: 'In review',
|
||||||
|
comment: commentText,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box key={environmentChangeRequest.id}>
|
<Box key={environmentChangeRequest.id}>
|
||||||
@ -141,12 +148,7 @@ export const EnvironmentChangeRequest: FC<{
|
|||||||
show={
|
show={
|
||||||
<>
|
<>
|
||||||
<SubmitChangeRequestButton
|
<SubmitChangeRequestButton
|
||||||
onClick={() =>
|
onClick={() => onReview(sendToReview)}
|
||||||
onReview(
|
|
||||||
environmentChangeRequest.id,
|
|
||||||
commentText,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
count={changesCount(
|
count={changesCount(
|
||||||
environmentChangeRequest,
|
environmentChangeRequest,
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user