Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show a dialog when adding a release plan to a change request enabled feature environment #9139

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useReleasePlansApi } from 'hooks/api/actions/useReleasePlansApi/useRele
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { useReleasePlans } from 'hooks/api/getters/useReleasePlans/useReleasePlans';
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
import { useUiFlag } from 'hooks/useUiFlag';

const StyledIcon = styled('div')(({ theme }) => ({
width: theme.spacing(4),
Expand Down Expand Up @@ -51,33 +53,46 @@ interface IFeatureReleasePlanCardProps {
featureId: string;
environmentId: string;
releasePlanTemplate: IReleasePlanTemplate;
setAddingTemplateId: (templateId: string) => void;
}

export const FeatureReleasePlanCard = ({
projectId,
featureId,
environmentId,
releasePlanTemplate,
setAddingTemplateId,
}: IFeatureReleasePlanCardProps) => {
const Icon = getFeatureStrategyIcon('releasePlanTemplate');
const { trackEvent } = usePlausibleTracker();
const { refetch } = useReleasePlans(projectId, featureId, environmentId);
const { addReleasePlanToFeature } = useReleasePlansApi();
const { setToastApiError, setToastData } = useToast();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
const releasePlanChangeRequestsEnabled = useUiFlag(
'releasePlanChangeRequests',
);

const addReleasePlan = async () => {
const addReleasePlan = async (e: React.MouseEvent) => {
daveleek marked this conversation as resolved.
Show resolved Hide resolved
try {
await addReleasePlanToFeature(
featureId,
releasePlanTemplate.id,
projectId,
environmentId,
);
setToastData({
type: 'success',
text: 'Release plan added',
});
refetch();
if (
releasePlanChangeRequestsEnabled &&
isChangeRequestConfigured(environmentId)
) {
setAddingTemplateId(releasePlanTemplate.id);
daveleek marked this conversation as resolved.
Show resolved Hide resolved
} else {
await addReleasePlanToFeature(
featureId,
releasePlanTemplate.id,
projectId,
environmentId,
);
setToastData({
type: 'success',
text: 'Release plan added',
});
refetch();
}
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { formatCreateStrategyPath } from '../FeatureStrategyCreate/FeatureStrate
import MoreVert from '@mui/icons-material/MoreVert';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { useUiFlag } from 'hooks/useUiFlag';
import { ReleasePlanAddChangeRequestDialog } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanAddChangeRequestDialog';

interface IFeatureStrategyMenuProps {
label: string;
Expand Down Expand Up @@ -50,6 +51,9 @@ export const FeatureStrategyMenu = ({
const [anchor, setAnchor] = useState<Element>();
const navigate = useNavigate();
const { trackEvent } = usePlausibleTracker();
const [addingTemplateId, setAddingTemplateId] = useState<
string | undefined
>();
const isPopoverOpen = Boolean(anchor);
const popoverId = isPopoverOpen ? 'FeatureStrategyMenuPopover' : undefined;
const flagOverviewRedesignEnabled = useUiFlag('flagOverviewRedesign');
Expand Down Expand Up @@ -115,6 +119,7 @@ export const FeatureStrategyMenu = ({
projectId={projectId}
featureId={featureId}
environmentId={environmentId}
setAddingTemplateId={setAddingTemplateId}
/>
</Popover>
</StyledStrategyMenu>
Expand Down Expand Up @@ -175,8 +180,15 @@ export const FeatureStrategyMenu = ({
projectId={projectId}
featureId={featureId}
environmentId={environmentId}
setAddingTemplateId={setAddingTemplateId}
/>
</Popover>
<ReleasePlanAddChangeRequestDialog
onClosing={() => setAddingTemplateId(undefined)}
featureId={featureId}
environmentId={environmentId}
releaseTemplateId={addingTemplateId}
/>
</StyledStrategyMenu>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IFeatureStrategyMenuCardsProps {
projectId: string;
featureId: string;
environmentId: string;
setAddingTemplateId: (templateId: string) => void;
}

const StyledTypography = styled(Typography)(({ theme }) => ({
Expand All @@ -20,6 +21,7 @@ export const FeatureStrategyMenuCards = ({
projectId,
featureId,
environmentId,
setAddingTemplateId,
}: IFeatureStrategyMenuCardsProps) => {
const { strategies } = useStrategies();
const { templates } = useReleasePlanTemplates();
Expand Down Expand Up @@ -68,6 +70,7 @@ export const FeatureStrategyMenuCards = ({
featureId={featureId}
environmentId={environmentId}
releasePlanTemplate={template}
setAddingTemplateId={setAddingTemplateId}
/>
</ListItem>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { useReleasePlanTemplate } from 'hooks/api/getters/useReleasePlanTemplates/useReleasePlanTemplate';
import useToast from 'hooks/useToast';
import { styled, Button } from '@mui/material';

const StyledBoldSpan = styled('span')(({ theme }) => ({
fontWeight: theme.typography.fontWeightBold,
}));

export const ReleasePlanAddChangeRequestDialog = ({
featureId,
environmentId,
releaseTemplateId,
onClosing,
}: {
featureId: string;
environmentId: string;
releaseTemplateId: string | undefined;
daveleek marked this conversation as resolved.
Show resolved Hide resolved
onClosing: () => void;
}) => {
if (!releaseTemplateId) {
return null;
}
const template = useReleasePlanTemplate(releaseTemplateId);
const { setToastData } = useToast();

const addReleasePlanToChangeRequest = async () => {
setToastData({
type: 'success',
text: 'Added to draft',
});
onClosing();
};

return (
<Dialogue
title='Request changes'
open={true}
daveleek marked this conversation as resolved.
Show resolved Hide resolved
secondaryButtonText='Cancel'
onClose={() => {
onClosing();
}}
customButton={
<Button
color='primary'
variant='contained'
onClick={addReleasePlanToChangeRequest}
autoFocus={true}
>
Add suggestion to draft
</Button>
}
>
<p>
<StyledBoldSpan>Add</StyledBoldSpan> release template{' '}
<StyledBoldSpan>{template?.template.name}</StyledBoldSpan> to{' '}
<StyledBoldSpan>{featureId}</StyledBoldSpan> in{' '}
<StyledBoldSpan>{environmentId}</StyledBoldSpan>
</p>
</Dialogue>
);
};
Loading