1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00
unleash.unleash/frontend/src/component/segments/SegmentDelete/SegmentDelete.tsx
Thomas Heartman b021e7cf85
feat: show strategies used by segments (#5407)
This PR displays change request usage of segments when such usage is
returned from the API. It expects at least #5406 to have been merged
before it can be merged.


![image](https://github.com/Unleash/unleash/assets/17786332/c74bb1c9-07f9-4bca-95bb-4ca020398444)
2023-11-27 10:34:34 +00:00

52 lines
1.6 KiB
TypeScript

import React from 'react';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useStrategiesBySegment } from 'hooks/api/getters/useStrategiesBySegment/useStrategiesBySegment';
import { ISegment } from 'interfaces/segment';
import { SegmentDeleteConfirm } from './SegmentDeleteConfirm/SegmentDeleteConfirm';
import { SegmentDeleteUsedSegment } from './SegmentDeleteUsedSegment/SegmentDeleteUsedSegment';
interface ISegmentDeleteProps {
segment: ISegment;
open: boolean;
onClose: () => void;
onRemove: () => void;
}
export const SegmentDelete = ({
segment,
open,
onClose,
onRemove,
}: ISegmentDeleteProps) => {
const { strategies, changeRequestStrategies, loading } =
useStrategiesBySegment(segment.id);
const canDeleteSegment =
strategies?.length === 0 && changeRequestStrategies?.length === 0;
if (loading) {
return null;
}
return (
<ConditionallyRender
condition={canDeleteSegment}
show={
<SegmentDeleteConfirm
segment={segment}
open={open}
onClose={onClose}
onRemove={onRemove}
/>
}
elseShow={
<SegmentDeleteUsedSegment
segment={segment}
open={open}
onClose={onClose}
strategies={strategies}
changeRequestStrategies={changeRequestStrategies}
/>
}
/>
);
};