Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/ticket-fields-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/modules/ticket-fields/RequestFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const RequestFormField = ({
? (organizationField?.value as string)
: defaultOrganizationId
}
brandId={brandId}
visibleFields={visibleFields}
onChange={(value) => handleChange(field, value)}
buildLookupFieldOptions={buildLookupFieldOptions}
Expand Down
68 changes: 68 additions & 0 deletions src/modules/ticket-fields/fields/LookupField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,74 @@ describe("buildAdvancedDynamicFilterParams", () => {
expect(result).toEqual([]);
});

it("returns ticket_brand_id filter with null value when no matching field exists", () => {
const filter: LookupRelationshipFieldFilter = {
all: [
{
field: "custom_object.testco.custom_fields.brandlurf",
operator: "matches",
value: "ticket_brand_id",
},
],
any: [],
};
const fields: TicketFieldObject[] = [
{
id: 12345,
name: "Test Field 1",
value: "fooValue",
error: null,
label: "Test Field 1",
required: false,
description: "",
type: "text",
options: [],
},
];

const result = buildAdvancedDynamicFilterParams(filter, fields);

expect(result).toEqual([{ key: "ticket_brand_id", value: null }]);
});

it("returns ticket_brand_id alongside ticket_fields filters", () => {
const filter: LookupRelationshipFieldFilter = {
all: [
{
field: "someField",
operator: "matches",
value: "ticket_fields_12345",
},
{
field: "brandField",
operator: "matches",
value: "ticket_brand_id",
},
],
any: [],
};
const fields: TicketFieldObject[] = [
{
id: 12345,
name: "Test Field 1",
value: "fooValue",
error: null,
label: "Test Field 1",
required: false,
description: "",
type: "text",
options: [],
},
];

const result = buildAdvancedDynamicFilterParams(filter, fields);

expect(result).toEqual([
{ key: "ticket_fields_12345", value: "fooValue" },
{ key: "ticket_brand_id", value: null },
]);
});

it("returns multiple filters if more than one matches", () => {
const filter: LookupRelationshipFieldFilter = {
all: [
Expand Down
21 changes: 17 additions & 4 deletions src/modules/ticket-fields/fields/LookupField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface LookupFieldProps {
field: TicketFieldObject;
userId: number;
organizationId: string | null;
brandId?: number;
onChange: (value: string) => void;
visibleFields: TicketFieldObject[];
buildLookupFieldOptions?: (
Expand All @@ -65,6 +66,7 @@ export function LookupField({
field,
userId,
organizationId,
brandId,
onChange,
visibleFields,
buildLookupFieldOptions,
Expand Down Expand Up @@ -144,11 +146,21 @@ export function LookupField({
);

for (const { key: filterValue, value: fieldValue } of filterPairs) {
if (filterValue) {
const filterValueParam = `filter[dynamic_values][${filterValue}]`;
const fieldValueParam = fieldValue?.toString() || "";
searchParams.set(filterValueParam, fieldValueParam);
if (!filterValue) continue;

if (filterValue === "ticket_brand_id") {
if (brandId) {
searchParams.set(
"filter[dynamic_values][ticket_brand_id]",
brandId.toString()
);
}
continue;
}

const filterValueParam = `filter[dynamic_values][${filterValue}]`;
const fieldValueParam = fieldValue?.toString() || "";
searchParams.set(filterValueParam, fieldValueParam);
}

if (organizationId) searchParams.set("organization_id", organizationId);
Expand Down Expand Up @@ -194,6 +206,7 @@ export function LookupField({
}
},
[
brandId,
customObjectKey,
field,
fieldId,
Expand Down
Loading