Skip to content

Commit 42ef236

Browse files
committed
remove emptySelectionHintKey from switches widget
use the new messages framework and revert the changes made in #22664
1 parent 6ee5e70 commit 42ef236

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

web/public/locales/en/views/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,7 @@
14331433
},
14341434
"reviewLabels": {
14351435
"summary": "{{count}} labels selected",
1436-
"empty": "No labels available",
1437-
"allNonAlertDetections": "All non-alert activity will be included as detections."
1436+
"empty": "No labels available"
14381437
},
14391438
"filters": {
14401439
"objectFieldLabel": "{{field}} for {{label}}"
@@ -1610,7 +1609,8 @@
16101609
"configMessages": {
16111610
"review": {
16121611
"recordDisabled": "Recording is disabled, review items will not be generated.",
1613-
"detectDisabled": "Object detection is disabled. Review items require detected objects to categorize alerts and detections."
1612+
"detectDisabled": "Object detection is disabled. Review items require detected objects to categorize alerts and detections.",
1613+
"allNonAlertDetections": "All non-alert activity will be included as detections."
16141614
},
16151615
"audio": {
16161616
"noAudioRole": "No streams have the audio role defined. You must enable the audio role for audio detection to function."

web/src/components/config-form/section-configs/review.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ const review: SectionConfigOverrides = {
2727
},
2828
},
2929
],
30+
fieldMessages: [
31+
{
32+
key: "detections-all-non-alert",
33+
field: "detections.labels",
34+
messageKey: "configMessages.review.allNonAlertDetections",
35+
severity: "info",
36+
position: "after",
37+
condition: (ctx) => {
38+
const labels = (
39+
ctx.formData?.detections as Record<string, unknown> | undefined
40+
)?.labels;
41+
return !Array.isArray(labels) || labels.length === 0;
42+
},
43+
},
44+
],
3045
fieldDocs: {
3146
"alerts.labels": "/configuration/review/#alerts-and-detections",
3247
"detections.labels": "/configuration/review/#alerts-and-detections",
@@ -59,8 +74,6 @@ const review: SectionConfigOverrides = {
5974
"ui:widget": "reviewLabels",
6075
"ui:options": {
6176
suppressMultiSchema: true,
62-
emptySelectionHintKey:
63-
"configForm.reviewLabels.allNonAlertDetections",
6477
},
6578
},
6679
required_zones: {

web/src/components/config-form/sections/BaseSection.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,24 @@ export function ConfigSection({
573573
if (activeFieldMessages.length === 0) return sectionConfig.uiSchema;
574574
const merged = { ...(sectionConfig.uiSchema ?? {}) };
575575
for (const msg of activeFieldMessages) {
576-
const fieldKey = msg.field;
577-
const existing = merged[fieldKey] as Record<string, unknown> | undefined;
576+
const segments = msg.field.split(".");
577+
// Navigate to the nested uiSchema node, shallow-cloning along the way
578+
let node = merged;
579+
for (let i = 0; i < segments.length - 1; i++) {
580+
const seg = segments[i];
581+
node[seg] = { ...(node[seg] as Record<string, unknown>) };
582+
node = node[seg] as Record<string, unknown>;
583+
}
584+
const leafKey = segments[segments.length - 1];
585+
const existing = node[leafKey] as Record<string, unknown> | undefined;
578586
const existingMessages = ((existing?.["ui:messages"] as unknown[]) ??
579587
[]) as Array<{
580588
key: string;
581589
messageKey: string;
582590
severity: string;
583591
position?: string;
584592
}>;
585-
merged[fieldKey] = {
593+
node[leafKey] = {
586594
...existing,
587595
"ui:messages": [
588596
...existingMessages,

web/src/components/config-form/theme/widgets/SwitchesWidget.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export type SwitchesWidgetOptions = {
4545
enableSearch?: boolean;
4646
/** Allow users to add custom entries not in the predefined list */
4747
allowCustomEntries?: boolean;
48-
/** i18n key for a hint shown when no entities are selected */
49-
emptySelectionHintKey?: string;
5048
};
5149

5250
function normalizeValue(value: unknown): string[] {
@@ -131,11 +129,6 @@ export function SwitchesWidget(props: WidgetProps) {
131129
[props.options],
132130
);
133131

134-
const emptySelectionHintKey = useMemo(
135-
() => props.options?.emptySelectionHintKey as string | undefined,
136-
[props.options],
137-
);
138-
139132
const selectedEntities = useMemo(() => normalizeValue(value), [value]);
140133
const [isOpen, setIsOpen] = useState(selectedEntities.length > 0);
141134
const [searchTerm, setSearchTerm] = useState("");
@@ -215,12 +208,6 @@ export function SwitchesWidget(props: WidgetProps) {
215208
</Button>
216209
</CollapsibleTrigger>
217210

218-
{emptySelectionHintKey && selectedEntities.length === 0 && t && (
219-
<div className="mt-0 pb-2 text-sm text-success">
220-
{t(emptySelectionHintKey, { ns: namespace })}
221-
</div>
222-
)}
223-
224211
<CollapsibleContent className="rounded-lg border border-input bg-secondary pb-1 pr-0 pt-2 md:max-w-md">
225212
{allEntities.length === 0 && !allowCustomEntries ? (
226213
<div className="text-sm text-muted-foreground">{emptyMessage}</div>

0 commit comments

Comments
 (0)