diff --git a/frontend/src/component/segments/SegmentDelete/SegmentDeleteUsedSegment/SegmentDeleteUsedSegment.tsx b/frontend/src/component/segments/SegmentDelete/SegmentDeleteUsedSegment/SegmentDeleteUsedSegment.tsx
index 2dda636189..1f407d2222 100644
--- a/frontend/src/component/segments/SegmentDelete/SegmentDeleteUsedSegment/SegmentDeleteUsedSegment.tsx
+++ b/frontend/src/component/segments/SegmentDelete/SegmentDeleteUsedSegment/SegmentDeleteUsedSegment.tsx
@@ -7,8 +7,11 @@ import { formatStrategyName } from 'utils/strategyNames';
import { styled } from '@mui/material';
import {
ChangeRequestInfo,
+ ChangeRequestNewStrategy,
ChangeRequestStrategy,
+ ChangeRequestUpdatedStrategy,
} from 'hooks/api/getters/useStrategiesBySegment/useStrategiesBySegment';
+import { sortStrategiesByFeature } from './sort-strategies';
const StyledUl = styled('ul')({
marginBottom: 0,
@@ -42,109 +45,11 @@ export const SegmentDeleteUsedSegment = ({
strategies,
changeRequestStrategies,
}: ISegmentDeleteUsedSegmentProps) => {
- // three kinds:
- // 1. strategies without crs
- // 2. crs without strategies
- // 3. strategies with crs
-
- // create a layered dictionary:
- // { featureName: { existingStrategies: { ...strategy, changeRequests: [crs] }, newStrategies: [crs] }
- const flagDict: {
- [key: string]: {
- existingStrategies: {
- [key: string]:
- | {
- strategy?: IFeatureStrategy;
- changeRequests: ChangeRequestInfo[];
- }
- | {
- strategy: IFeatureStrategy;
- changeRequests?: ChangeRequestInfo[];
- };
- };
- newStrategies: ChangeRequestStrategy[];
- };
- } = Object.fromEntries(
- (strategies ?? []).map((strategy) => [
- strategy.featureName!,
- {
- existingStrategies: {
- [strategy.id]: {
- strategy: strategy,
- },
- },
- newStrategies: [],
- },
- ]),
+ const sortedStrategies = sortStrategiesByFeature(
+ strategies ?? [],
+ changeRequestStrategies ?? [],
);
- for (const crStrategy of changeRequestStrategies ?? []) {
- const { featureName } = crStrategy;
-
- const isExistingStrategy = 'id' in crStrategy;
-
- if (isExistingStrategy) {
- const { id } = crStrategy;
- const existingEntry = flagDict[featureName]?.existingStrategies[id];
-
- if (existingEntry) {
- existingEntry.changeRequests = crStrategy.changeRequests;
- } else {
- if (!flagDict[featureName]) {
- flagDict[featureName] = {
- existingStrategies: {
- [id]: {
- changeRequests: crStrategy.changeRequests,
- },
- },
- newStrategies: [],
- };
- } else {
- flagDict[featureName].existingStrategies[
- id
- ].changeRequests = {
- crStrategy.changeRequests,
- };
- }
- }
- }
- }
-
- console.log(JSON.stringify(flagDict, null, 2));
-
- // group by flag name
- const features = (strategies ?? []).reduce((acc, strategy) => {
- if (!acc[strategy.featureName!]) {
- acc[strategy.featureName!] = [strategy];
- } else {
- acc[strategy.featureName!].push(strategy);
- }
- return acc;
- }, {} as { [key: string]: IFeatureStrategy[] });
-
- // can we turn strategies into strategies with optional CRs? Also, CR title?
- const existingStrategies: {
- [key: string]: IFeatureStrategy & {
- changeRequests?: ChangeRequestInfo[];
- };
- } = Object.fromEntries((strategies ?? []).map((s) => [s.id, s]));
-
- const { existing, notListed } = (changeRequestStrategies ?? []).reduce(
- (acc, strategy) => {
- if ('id' in strategy && strategy.id in existingStrategies) {
- existingStrategies[strategy.id].changeRequests =
- strategy.changeRequests;
- } else {
- acc.notListed.push(strategy);
- }
-
- return acc;
- },
- { existing: [], notListed: [] },
- );
-
- console.log(existing, notListed);
-
return (
+ {strategy.featureName}{' '}
+ {formatStrategyNameParens(strategy) +
+ ' — in change request '}
+
+