Skip to content

Commit cc43d5f

Browse files
committed
Refactor indexing rules to use new rule model
Updated integration indexing rules to use the new TurIntegrationIndexingRule model and service. Added a dynamic field component for managing rule values. Adjusted form fields and routing to match the new data structure and improved form UX with clearer labels and descriptions.
1 parent a587637 commit cc43d5f

File tree

4 files changed

+133
-50
lines changed

4 files changed

+133
-50
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { IntegrationIndexingRulesForm } from "@/components/integration/integration.indexing.rules.form";
22
import { SubPageHeader } from "@/components/sub.page.header";
3-
import type { TurIntegrationInstance } from "@/models/integration/integration-instance.model";
4-
import { TurIntegrationInstanceService } from "@/services/integration/integration.service";
3+
import type { TurIntegrationIndexingRule } from "@/models/integration/integration-indexing-rule.model";
4+
import { TurIntegrationIndexingRuleService } from "@/services/integration/integration-indexing-rule.service";
55
import { IconTools } from "@tabler/icons-react";
66
import { useEffect, useState } from "react";
77
import { useParams } from "react-router-dom";
8-
const turIntegrationInstanceService = new TurIntegrationInstanceService();
98

109
export default function IntegrationInstanceIndexingRulePage() {
11-
const { id } = useParams() as { id: string };
12-
const [integrationInstance, setIntegrationInstance] = useState<TurIntegrationInstance>({} as TurIntegrationInstance);
10+
const { id, ruleId } = useParams() as { id: string, ruleId: string };
11+
const [integrationIndexingRules, setIntegrationIndexingRules] = useState<TurIntegrationIndexingRule>({} as TurIntegrationIndexingRule);
12+
const turIntegrationIndexingRuleService = new TurIntegrationIndexingRuleService(id || "");
1313
const [isNew, setIsNew] = useState<boolean>(true);
1414
useEffect(() => {
1515
if (id !== "new") {
16-
turIntegrationInstanceService.get(id).then(setIntegrationInstance);
16+
turIntegrationIndexingRuleService.get(ruleId).then(setIntegrationIndexingRules);
1717
setIsNew(false);
1818
}
1919
}, [id])
2020
return (
2121
<>
2222
<SubPageHeader icon={IconTools} title="Indexing Rules" description="Establish guidelines for how the indexing process will operate." />
23-
<IntegrationIndexingRulesForm value={integrationInstance} isNew={isNew} />
23+
<IntegrationIndexingRulesForm value={integrationIndexingRules} isNew={isNew} />
2424
</>
2525
)
2626
}

turing-react/src/app/routes/integration.routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const IntegrationRoutes = (
2525
<Route path="source" element={<IntegrationInstanceSourceListPage />} />
2626
<Route path="source/:sourceId" element={<IntegrationInstanceSourcePage />} />
2727
<Route path="indexing-rule" element={<IntegrationInstanceIndexingRulesListPage />} />
28-
<Route path="indexing-rule/:rulesId" element={<IntegrationInstanceIndexingRulesPage />} />
28+
<Route path="indexing-rule/:ruleId" element={<IntegrationInstanceIndexingRulesPage />} />
2929
<Route path="monitoring">
3030
<Route index element={<Navigate to="all" replace />} />
3131
<Route path=":source" element={<IntegrationInstanceMonitoringPage />} />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Button } from '@/components/ui/button';
2+
import { Input } from '@/components/ui/input';
3+
import { PlusCircle, Trash2 } from 'lucide-react';
4+
import { useFieldArray, type Control, type UseFormRegister } from 'react-hook-form';
5+
6+
interface DynamicIndexingRuleFieldsProps {
7+
control: Control<any>;
8+
register: UseFormRegister<any>;
9+
fieldName: string;
10+
}
11+
12+
export function DynamicIndexingRuleFields({ control, register, fieldName }: DynamicIndexingRuleFieldsProps) {
13+
const { fields, append, remove } = useFieldArray({
14+
control,
15+
name: fieldName,
16+
});
17+
18+
const handleAddField = () => {
19+
append('');
20+
};
21+
22+
return (
23+
<div className="flex flex-col gap-4 w-full">
24+
{fields.map((field, index) => (
25+
<div key={field.id} className="flex items-center gap-2">
26+
<Input
27+
className="grow"
28+
placeholder="Value"
29+
{...register(`${fieldName}.${index}`)}
30+
/>
31+
<Button
32+
variant="ghost"
33+
size="icon"
34+
onClick={() => remove(index)}
35+
aria-label="Remove the field"
36+
type="button"
37+
>
38+
<Trash2 className="h-4 w-4 text-red-500" />
39+
</Button>
40+
</div>
41+
))}
42+
43+
<div className="mt-2">
44+
<Button variant="outline" onClick={handleAddField} type="button">
45+
<PlusCircle className="h-4 w-4 mr-2" />
46+
Add
47+
</Button>
48+
</div>
49+
</div>
50+
);
51+
}

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

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,48 @@ import {
2525
import {
2626
Textarea
2727
} from "@/components/ui/textarea"
28-
import type { TurIntegrationInstance } from "@/models/integration/integration-instance.model.ts"
29-
import { TurIntegrationInstanceService } from "@/services/integration/integration.service"
28+
import type { TurIntegrationIndexingRule } from "@/models/integration/integration-indexing-rule.model"
29+
import { TurIntegrationIndexingRuleService } from "@/services/integration/integration-indexing-rule.service"
3030
import { useEffect } from "react"
3131
import {
3232
useForm
3333
} from "react-hook-form"
3434
import { useNavigate } from "react-router-dom"
3535
import { toast } from "sonner"
36-
const turIntegrationInstanceService = new TurIntegrationInstanceService();
36+
import { DynamicIndexingRuleFields } from "./dynamic.indexing.rule.field"
37+
3738
interface Props {
38-
value: TurIntegrationInstance;
39+
value: TurIntegrationIndexingRule;
3940
isNew: boolean;
4041
}
4142

4243
export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, isNew }) => {
43-
const form = useForm<TurIntegrationInstance>();
44-
const { setValue } = form;
44+
const form = useForm<TurIntegrationIndexingRule>();
45+
const { control, register, setValue } = form;
4546
const navigate = useNavigate()
4647
useEffect(() => {
4748
setValue("id", value.id)
48-
setValue("title", value.title);
49+
setValue("name", value.name);
4950
setValue("description", value.description);
50-
setValue("vendor", value.vendor);
51-
setValue("endpoint", value.endpoint);
52-
setValue("enabled", value.enabled);
51+
setValue("ruleType", value.ruleType);
52+
setValue("source", value.source);
53+
setValue("attribute", value.attribute);
54+
setValue("values", value.values);
5355
}, [setValue, value]);
5456

5557

56-
function onSubmit(integrationInstance: TurIntegrationInstance) {
58+
function onSubmit(integrationIndexingRule: TurIntegrationIndexingRule) {
5759
try {
5860
if (isNew) {
59-
turIntegrationInstanceService.create(integrationInstance);
60-
toast.success(`The ${integrationInstance.title} Integration Instance was saved`);
61+
const turIntegrationIndexingRuleService = new TurIntegrationIndexingRuleService("");
62+
turIntegrationIndexingRuleService.create(integrationIndexingRule);
63+
toast.success(`The ${integrationIndexingRule.name} Integration Indexing Rule was saved`);
6164
navigate(ROUTES.INTEGRATION_INSTANCE);
6265
}
6366
else {
64-
turIntegrationInstanceService.update(integrationInstance);
65-
toast.success(`The ${integrationInstance.title} Integration Instance was updated`);
67+
const turIntegrationIndexingRuleService = new TurIntegrationIndexingRuleService("");
68+
turIntegrationIndexingRuleService.update(integrationIndexingRule);
69+
toast.success(`The ${integrationIndexingRule.name} Integration Indexing Rule was updated`);
6670
}
6771
} catch (error) {
6872
console.error("Form submission error", error);
@@ -75,18 +79,18 @@ export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, isNew })
7579
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 py-8 pr-8">
7680
<FormField
7781
control={form.control}
78-
name="title"
82+
name="name"
7983
render={({ field }) => (
8084
<FormItem>
81-
<FormLabel>Name</FormLabel>
85+
<FormLabel>Rule Name</FormLabel>
8286
<FormControl>
8387
<Input
8488
{...field}
85-
placeholder="Title"
89+
placeholder="e.g., Ignore Draft Pages"
8690
type="text"
8791
/>
8892
</FormControl>
89-
<FormDescription>Integration instance title will appear on list.</FormDescription>
93+
<FormDescription>A unique, descriptive name to easily identify this rule in the list.</FormDescription>
9094
<FormMessage />
9195
</FormItem>
9296
)}
@@ -97,60 +101,88 @@ export const IntegrationIndexingRulesForm: React.FC<Props> = ({ value, isNew })
97101
name="description"
98102
render={({ field }) => (
99103
<FormItem>
100-
<FormLabel>Description</FormLabel>
104+
<FormLabel>Rule Description</FormLabel>
101105
<FormControl>
102106
<Textarea
103-
placeholder="Description"
107+
placeholder="e.g., Excludes all draft pages from indexing"
104108
className="resize-none"
105109
{...field}
106110
/>
107111
</FormControl>
108-
<FormDescription>Integration instance description will appear on list.</FormDescription>
112+
<FormDescription>Provide details about what this rule does and when it should be applied.</FormDescription>
109113
<FormMessage />
110114
</FormItem>
111115
)}
112116
/>
113-
114117
<FormField
115118
control={form.control}
116-
name="vendor"
119+
name="source"
117120
render={({ field }) => (
118121
<FormItem>
119-
<FormLabel>Vendor</FormLabel>
120-
<Select onValueChange={field.onChange} value={field.value}>
121-
<FormControl>
122-
<SelectTrigger>
123-
<SelectValue placeholder="Choose..." />
124-
</SelectTrigger>
125-
</FormControl>
126-
<SelectContent>
127-
<SelectItem key="AEM" value="AEM">AEM</SelectItem>
128-
<SelectItem key="WEB_CRAWLER" value="WEB_CRAWLER">Web Crawler</SelectItem>
129-
</SelectContent>
130-
</Select>
131-
<FormDescription>Integration vendor that will be used.</FormDescription>
122+
<FormLabel>Content Source</FormLabel>
123+
<FormControl>
124+
<Input
125+
placeholder="e.g., WKND"
126+
type="text"
127+
{...field} />
128+
</FormControl>
129+
<FormDescription>The content path or source location where this rule will be applied.</FormDescription>
132130
<FormMessage />
133131
</FormItem>
134132
)}
135133
/>
136-
137134
<FormField
138135
control={form.control}
139-
name="endpoint"
136+
name="attribute"
140137
render={({ field }) => (
141138
<FormItem>
142-
<FormLabel>Endpoint</FormLabel>
139+
<FormLabel>Target Attribute</FormLabel>
143140
<FormControl>
144141
<Input
145-
placeholder="URL"
142+
placeholder="e.g., title"
146143
type="text"
147144
{...field} />
148145
</FormControl>
149-
<FormDescription>Integration instance hostname will be connected.</FormDescription>
146+
<FormDescription>The content attribute or property name used to match against the values below.</FormDescription>
150147
<FormMessage />
151148
</FormItem>
152149
)}
153150
/>
151+
152+
<FormField
153+
control={form.control}
154+
name="ruleType"
155+
render={({ field }) => (
156+
<FormItem>
157+
<FormLabel>Action Type</FormLabel>
158+
<Select onValueChange={field.onChange} value={field.value}>
159+
<FormControl>
160+
<SelectTrigger>
161+
<SelectValue placeholder="Choose..." />
162+
</SelectTrigger>
163+
</FormControl>
164+
<SelectContent>
165+
<SelectItem key="IGNORE" value="IGNORE">Ignore</SelectItem>
166+
</SelectContent>
167+
</Select>
168+
<FormDescription>Defines the action to take when content matches this rule. "Ignore" will exclude matching content from indexing.</FormDescription>
169+
<FormMessage />
170+
</FormItem>
171+
)}
172+
/>
173+
174+
<FormItem>
175+
<FormLabel>Matching Values</FormLabel>
176+
<FormDescription>Add the values that the attribute should match. Content with matching attribute values will have the rule applied.</FormDescription>
177+
<FormControl>
178+
<DynamicIndexingRuleFields
179+
fieldName="values"
180+
control={control}
181+
register={register}
182+
/>
183+
</FormControl>
184+
</FormItem>
185+
154186
<Button type="submit">Save</Button>
155187
</form>
156188
</Form>

0 commit comments

Comments
 (0)