Skip to content

Commit 0c3f2a5

Browse files
[#679] Add warning when previewed segments > max segment
1 parent 1cb3c1d commit 0c3f2a5

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

frontend/src/pages/cases/components/SegmentConfigurationForm.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "antd";
1313
import { selectProps } from "../../../lib";
1414
import { api } from "../../../lib";
15-
import { SegmentForm } from ".";
15+
import { MAX_SEGMENT, SegmentForm } from ".";
1616

1717
const SegmentConfigurationForm = ({
1818
uploadResult = {},
@@ -96,6 +96,51 @@ const SegmentConfigurationForm = ({
9696
});
9797
};
9898

99+
const segmentNumericalWarning = useMemo(() => {
100+
// Extra message for numerical variable
101+
if (
102+
variableType === "numerical" &&
103+
segmentFields?.length < numberOfSegments
104+
) {
105+
return (
106+
<Col span={24}>
107+
<Alert
108+
message={
109+
<>
110+
The variable {segmentationVariable} includes too many 0 or
111+
missing values to meaningfully create {numberOfSegments} segment
112+
{numberOfSegments > 1 ? "s" : ""}. <br />
113+
Consider using a different variable, or adjust the thresholds
114+
manually.
115+
</>
116+
}
117+
type="warning"
118+
/>
119+
</Col>
120+
);
121+
}
122+
return null;
123+
}, [variableType, segmentFields, numberOfSegments, segmentationVariable]);
124+
125+
const maxSegmentWarning = useMemo(() => {
126+
if (segmentFields?.length > MAX_SEGMENT) {
127+
return (
128+
<Col span={24}>
129+
<Alert
130+
message={
131+
<>
132+
The variable {segmentationVariable} includes more than five
133+
unique values. To proceed, please keep only up to 5 segments.
134+
</>
135+
}
136+
type="warning"
137+
/>
138+
</Col>
139+
);
140+
}
141+
return null;
142+
}, [segmentFields, segmentationVariable]);
143+
99144
return (
100145
<Row gutter={[16, 16]}>
101146
{/* SEGMENT CONFIGURATION */}
@@ -163,27 +208,8 @@ const SegmentConfigurationForm = ({
163208
Please review or adjust thresholds for separating segments below:
164209
</h3>
165210
<Row gutter={[20, 20]}>
166-
{
167-
// Extra message for numerical variable
168-
variableType === "numerical" &&
169-
segmentFields?.length < numberOfSegments ? (
170-
<Col span={24}>
171-
<Alert
172-
message={
173-
<>
174-
The variable {segmentationVariable} includes too many 0
175-
or missing values to meaningfully create{" "}
176-
{numberOfSegments} segment
177-
{numberOfSegments > 1 ? "s" : ""}. <br />
178-
Consider using a different variable, or adjust the
179-
thresholds manually.
180-
</>
181-
}
182-
type="warning"
183-
/>
184-
</Col>
185-
) : null
186-
}
211+
{segmentNumericalWarning}
212+
{maxSegmentWarning}
187213
<Col span={24}>
188214
<SegmentForm
189215
deletedSegmentIds={deletedSegmentIds}

0 commit comments

Comments
 (0)