mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
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. 
52 lines
1.6 KiB
TypeScript
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}
|
|
/>
|
|
}
|
|
/>
|
|
);
|
|
};
|