Skip to content

Commit 4d9986f

Browse files
committed
fix: hide category lookup field from submit request form
1 parent 1e7186c commit 4d9986f

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

src/modules/service-catalog/hooks/useItemFormFields.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,57 @@ describe("useItemFormFields", () => {
487487
const presentIds = result.current.requestFields.map((f) => f.id);
488488
expect(presentIds).toEqual([1, 6]);
489489
});
490+
491+
it("should filter out category lookup field from requestFields", async () => {
492+
const categoryLookupField = {
493+
id: 8,
494+
type: "lookup",
495+
description: "Category",
496+
title_in_portal: "Category",
497+
editable_in_portal: true,
498+
relationship_target_type:
499+
"zen:custom_object:standard::service_catalog_category",
500+
required_in_portal: false,
501+
active: true,
502+
};
503+
504+
const formResponse = {
505+
ticket_form: {
506+
id: 1,
507+
ticket_field_ids: [1, 2, 8],
508+
active: true,
509+
},
510+
};
511+
512+
const ticketFieldResponse = {
513+
ticket_fields: [textField, lookupField, categoryLookupField],
514+
};
515+
516+
(globalThis.fetch as jest.Mock) = jest.fn((url) => {
517+
return Promise.resolve({
518+
json: () =>
519+
Promise.resolve(
520+
url.includes("/api/v2/ticket_forms/1")
521+
? formResponse
522+
: url.includes(`/api/v2/ticket_fields?locale=${baseLocale}`)
523+
? ticketFieldResponse
524+
: {}
525+
),
526+
status: 200,
527+
ok: true,
528+
});
529+
});
530+
531+
const { result, waitForNextUpdate } = renderHook(() =>
532+
useItemFormFields(serviceCatalogItem, baseLocale)
533+
);
534+
535+
await waitForNextUpdate();
536+
537+
const presentIds = result.current.requestFields.map((f) => f.id);
538+
expect(presentIds).toEqual([1]);
539+
expect(result.current.associatedLookupField).toEqual(
540+
expect.objectContaining({ id: 2, type: "lookup" })
541+
);
542+
});
490543
});

src/modules/service-catalog/hooks/useItemFormFields.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,23 @@ const formatField = (field: TicketField): TicketFieldObject => {
9797
};
9898
};
9999

100+
const HIDDEN_SERVICE_CATALOG_LOOKUP_KEYS = [
101+
"standard::service_catalog_item",
102+
"standard::service_catalog_category",
103+
];
104+
100105
const isAssociatedLookupField = (field: TicketField) => {
101106
const customObjectKey = getCustomObjectKey(
102107
field.relationship_target_type as string
103108
);
104-
if (customObjectKey === "standard::service_catalog_item") {
105-
return true;
106-
}
107-
return false;
109+
return customObjectKey === "standard::service_catalog_item";
110+
};
111+
112+
const isHiddenServiceCatalogLookup = (field: TicketField) => {
113+
const customObjectKey = getCustomObjectKey(
114+
field.relationship_target_type as string
115+
);
116+
return HIDDEN_SERVICE_CATALOG_LOOKUP_KEYS.includes(customObjectKey);
108117
};
109118

110119
const enrichFieldsWithAssetConfig = (
@@ -183,10 +192,11 @@ const fetchTicketFields = async (
183192
) {
184193
if (
185194
ticketField.type === "lookup" &&
186-
isAssociatedLookupField(ticketField)
195+
isHiddenServiceCatalogLookup(ticketField)
187196
) {
188-
associatedLookupField = ticketField;
189-
197+
if (isAssociatedLookupField(ticketField)) {
198+
associatedLookupField = ticketField;
199+
}
190200
return null;
191201
}
192202
return formatField(ticketField);

0 commit comments

Comments
 (0)