Skip to content

Commit 45b3330

Browse files
fix: pass ticket_brand_id in LURF autocomplete request
When a lookup relationship field has a brand filter condition (ticket_brand_id), the autocomplete API request now includes the brand ID from the current Help Center brand. Previously the filter was sent with an empty value because brandId was not wired through to the LookupField component. - Add brandId prop to LookupField - Pass brandId from RequestFormField to LookupField - Add startsWith("ticket_fields_") guard to skip non-field filters - Add ticket_brand_id to search params when brand filter is defined - Add tests for ticket_brand_id filter handling CRYSTAL-888
1 parent 4cf574e commit 45b3330

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

assets/ticket-fields-bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/ticket-fields/RequestFormField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const RequestFormField = ({
143143
? (organizationField?.value as string)
144144
: defaultOrganizationId
145145
}
146+
brandId={brandId}
146147
visibleFields={visibleFields}
147148
onChange={(value) => handleChange(field, value)}
148149
buildLookupFieldOptions={buildLookupFieldOptions}

src/modules/ticket-fields/fields/LookupField.test.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,74 @@ describe("buildAdvancedDynamicFilterParams", () => {
141141
expect(result).toEqual([]);
142142
});
143143

144+
it("returns ticket_brand_id filter with null value when no matching field exists", () => {
145+
const filter: LookupRelationshipFieldFilter = {
146+
all: [
147+
{
148+
field: "custom_object.testco.custom_fields.brandlurf",
149+
operator: "matches",
150+
value: "ticket_brand_id",
151+
},
152+
],
153+
any: [],
154+
};
155+
const fields: TicketFieldObject[] = [
156+
{
157+
id: 12345,
158+
name: "Test Field 1",
159+
value: "fooValue",
160+
error: null,
161+
label: "Test Field 1",
162+
required: false,
163+
description: "",
164+
type: "text",
165+
options: [],
166+
},
167+
];
168+
169+
const result = buildAdvancedDynamicFilterParams(filter, fields);
170+
171+
expect(result).toEqual([{ key: "ticket_brand_id", value: null }]);
172+
});
173+
174+
it("returns ticket_brand_id alongside ticket_fields filters", () => {
175+
const filter: LookupRelationshipFieldFilter = {
176+
all: [
177+
{
178+
field: "someField",
179+
operator: "matches",
180+
value: "ticket_fields_12345",
181+
},
182+
{
183+
field: "brandField",
184+
operator: "matches",
185+
value: "ticket_brand_id",
186+
},
187+
],
188+
any: [],
189+
};
190+
const fields: TicketFieldObject[] = [
191+
{
192+
id: 12345,
193+
name: "Test Field 1",
194+
value: "fooValue",
195+
error: null,
196+
label: "Test Field 1",
197+
required: false,
198+
description: "",
199+
type: "text",
200+
options: [],
201+
},
202+
];
203+
204+
const result = buildAdvancedDynamicFilterParams(filter, fields);
205+
206+
expect(result).toEqual([
207+
{ key: "ticket_fields_12345", value: "fooValue" },
208+
{ key: "ticket_brand_id", value: null },
209+
]);
210+
});
211+
144212
it("returns multiple filters if more than one matches", () => {
145213
const filter: LookupRelationshipFieldFilter = {
146214
all: [

src/modules/ticket-fields/fields/LookupField.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface LookupFieldProps {
5252
field: TicketFieldObject;
5353
userId: number;
5454
organizationId: string | null;
55+
brandId?: number;
5556
onChange: (value: string) => void;
5657
visibleFields: TicketFieldObject[];
5758
buildLookupFieldOptions?: (
@@ -65,6 +66,7 @@ export function LookupField({
6566
field,
6667
userId,
6768
organizationId,
69+
brandId,
6870
onChange,
6971
visibleFields,
7072
buildLookupFieldOptions,
@@ -144,13 +146,23 @@ export function LookupField({
144146
);
145147

146148
for (const { key: filterValue, value: fieldValue } of filterPairs) {
147-
if (filterValue) {
149+
if (filterValue && filterValue.startsWith("ticket_fields_")) {
148150
const filterValueParam = `filter[dynamic_values][${filterValue}]`;
149151
const fieldValueParam = fieldValue?.toString() || "";
150152
searchParams.set(filterValueParam, fieldValueParam);
151153
}
152154
}
153155

156+
const hasBrandFilter = filterPairs.some(
157+
({ key }) => key === "ticket_brand_id"
158+
);
159+
if (brandId && hasBrandFilter) {
160+
searchParams.set(
161+
"filter[dynamic_values][ticket_brand_id]",
162+
brandId.toString()
163+
);
164+
}
165+
154166
if (organizationId) searchParams.set("organization_id", organizationId);
155167

156168
setIsLoadingOptions(true);
@@ -194,6 +206,7 @@ export function LookupField({
194206
}
195207
},
196208
[
209+
brandId,
197210
customObjectKey,
198211
field,
199212
fieldId,

0 commit comments

Comments
 (0)