Skip to content

Commit 62fdf2a

Browse files
Merge pull request #759 from zendesk/navkumar/CRYSTAL-888-brand-lurf-filter
fix: pass ticket_brand_id in LURF autocomplete request
2 parents 4cf574e + 5cfaecc commit 62fdf2a

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
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: 17 additions & 4 deletions
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,11 +146,21 @@ export function LookupField({
144146
);
145147

146148
for (const { key: filterValue, value: fieldValue } of filterPairs) {
147-
if (filterValue) {
148-
const filterValueParam = `filter[dynamic_values][${filterValue}]`;
149-
const fieldValueParam = fieldValue?.toString() || "";
150-
searchParams.set(filterValueParam, fieldValueParam);
149+
if (!filterValue) continue;
150+
151+
if (filterValue === "ticket_brand_id") {
152+
if (brandId) {
153+
searchParams.set(
154+
"filter[dynamic_values][ticket_brand_id]",
155+
brandId.toString()
156+
);
157+
}
158+
continue;
151159
}
160+
161+
const filterValueParam = `filter[dynamic_values][${filterValue}]`;
162+
const fieldValueParam = fieldValue?.toString() || "";
163+
searchParams.set(filterValueParam, fieldValueParam);
152164
}
153165

154166
if (organizationId) searchParams.set("organization_id", organizationId);
@@ -194,6 +206,7 @@ export function LookupField({
194206
}
195207
},
196208
[
209+
brandId,
197210
customObjectKey,
198211
field,
199212
fieldId,

0 commit comments

Comments
 (0)