Skip to content

Commit 6b3f27c

Browse files
committed
Update indexing rules form to use dynamic site and field selection
Replaces static text inputs for source and attribute with Select components populated from Semantic Navigation sites and their fields. Fetches available sites and fields dynamically, improving usability and ensuring valid selections for rule configuration.
1 parent c45a14f commit 6b3f27c

File tree

1 file changed

+60
-20
lines changed

1 file changed

+60
-20
lines changed

turing-react/src/components/integration/integration.indexing.rules.form.tsx

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ import {
2626
Textarea
2727
} from "@/components/ui/textarea"
2828
import type { TurIntegrationIndexingRule } from "@/models/integration/integration-indexing-rule.model"
29+
import type { TurSNSiteField } from "@/models/sn/sn-site-field.model"
30+
import type { TurSNSite } from "@/models/sn/sn-site.model"
2931
import { TurIntegrationIndexingRuleService } from "@/services/integration/integration-indexing-rule.service"
30-
import { useEffect } from "react"
32+
import { TurSNFieldService } from "@/services/sn/sn.field.service"
33+
import { TurSNSiteService } from "@/services/sn/sn.service"
34+
import { useEffect, useState } from "react"
3135
import {
3236
useForm
3337
} from "react-hook-form"
@@ -42,10 +46,20 @@ interface Props {
4246
}
4347

4448
export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, integrationId, isNew }) => {
49+
const turSNSiteService = new TurSNSiteService();
50+
const turSNFieldService = new TurSNFieldService();
4551
const form = useForm<TurIntegrationIndexingRule>();
46-
const { control, register, setValue } = form;
47-
const navigate = useNavigate()
52+
const { control, register, setValue, watch } = form;
53+
const [turSNSites, setTurSNSites] = useState<TurSNSite[]>([] as TurSNSite[]);
54+
const [turSNSiteFields, setTurSNSiteFields] = useState<TurSNSiteField[]>([] as TurSNSiteField[]);
55+
const navigate = useNavigate();
56+
const selectedSource = watch("source");
57+
4858
useEffect(() => {
59+
turSNSiteService.query().then((sites) => {
60+
setTurSNSites(sites);
61+
});
62+
4963
setValue("id", value.id)
5064
setValue("name", value.name);
5165
setValue("description", value.description);
@@ -55,6 +69,21 @@ export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, integrati
5569
setValue("values", value.values);
5670
}, [setValue, value]);
5771

72+
useEffect(() => {
73+
if (selectedSource && turSNSites.length > 0) {
74+
const selectedSite = turSNSites.find((site) => site.name === selectedSource);
75+
if (selectedSite?.id) {
76+
turSNFieldService.query(selectedSite.id).then((fields) => {
77+
setTurSNSiteFields(fields);
78+
// Re-set attribute value after fields are loaded
79+
if (value.attribute) {
80+
setValue("attribute", value.attribute);
81+
}
82+
});
83+
}
84+
}
85+
}, [selectedSource, turSNSites]);
86+
5887

5988
function onSubmit(integrationIndexingRule: TurIntegrationIndexingRule) {
6089
try {
@@ -120,14 +149,20 @@ export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, integrati
120149
name="source"
121150
render={({ field }) => (
122151
<FormItem>
123-
<FormLabel>Content Source</FormLabel>
124-
<FormControl>
125-
<Input
126-
placeholder="e.g., WKND"
127-
type="text"
128-
{...field} />
129-
</FormControl>
130-
<FormDescription>The content path or source location where this rule will be applied.</FormDescription>
152+
<FormLabel>Semantic Navigation Site</FormLabel>
153+
<Select onValueChange={field.onChange} value={field.value}>
154+
<FormControl>
155+
<SelectTrigger>
156+
<SelectValue placeholder="Choose..." />
157+
</SelectTrigger>
158+
</FormControl>
159+
<SelectContent>
160+
{turSNSites.map((site) => (
161+
<SelectItem key={site.name} value={site.name}>{site.name}</SelectItem>
162+
))}
163+
</SelectContent>
164+
</Select>
165+
<FormDescription>The Semantic Navigation site where this rule will be applied.</FormDescription>
131166
<FormMessage />
132167
</FormItem>
133168
)}
@@ -137,19 +172,24 @@ export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, integrati
137172
name="attribute"
138173
render={({ field }) => (
139174
<FormItem>
140-
<FormLabel>Target Attribute</FormLabel>
141-
<FormControl>
142-
<Input
143-
placeholder="e.g., title"
144-
type="text"
145-
{...field} />
146-
</FormControl>
147-
<FormDescription>The content attribute or property name used to match against the values below.</FormDescription>
175+
<FormLabel>Field</FormLabel>
176+
<Select onValueChange={field.onChange} value={field.value}>
177+
<FormControl>
178+
<SelectTrigger>
179+
<SelectValue placeholder="Choose..." />
180+
</SelectTrigger>
181+
</FormControl>
182+
<SelectContent>
183+
{turSNSiteFields.map((field) => (
184+
<SelectItem key={field.name} value={field.name}>{field.name}</SelectItem>
185+
))}
186+
</SelectContent>
187+
</Select>
188+
<FormDescription>The content attribute used to match against the values below.</FormDescription>
148189
<FormMessage />
149190
</FormItem>
150191
)}
151192
/>
152-
153193
<FormField
154194
control={form.control}
155195
name="ruleType"

0 commit comments

Comments
 (0)