Skip to content

Commit b7981ed

Browse files
Merge pull request #663 from zendesk/maciejlorens/deactivated-custom-field-is-visible-on-sc-item-page
fix: hide deactivated Fields on the ServiceCatalog Item page
2 parents e109eb6 + e6de4c4 commit b7981ed

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("useItemFormFields", () => {
1818
title_in_portal: "Test Title",
1919
editable_in_portal: true,
2020
required_in_portal: true,
21+
active: true,
2122
};
2223

2324
const lookupField = {
@@ -28,6 +29,7 @@ describe("useItemFormFields", () => {
2829
editable_in_portal: true,
2930
relationship_target_type: "standard::service_catalog_item",
3031
required_in_portal: true,
32+
active: true,
3133
};
3234

3335
const expectedTextField = {
@@ -51,6 +53,7 @@ describe("useItemFormFields", () => {
5153
required_in_portal: true,
5254
title_in_portal: "Service",
5355
type: "lookup",
56+
active: true,
5457
};
5558

5659
const additionalTextField = {
@@ -393,4 +396,90 @@ describe("useItemFormFields", () => {
393396
},
394397
]);
395398
});
399+
400+
it("should not include fields with type 'subject', type 'description', active false, or editable_in_portal false in requestFields", async () => {
401+
const formResponse = {
402+
ticket_form: {
403+
id: 1,
404+
ticket_field_ids: [1, 2, 3, 4, 5, 6, 7],
405+
active: true,
406+
},
407+
};
408+
const ticketFieldResponse = {
409+
ticket_fields: [
410+
{
411+
...textField,
412+
id: 1,
413+
type: "text",
414+
active: true,
415+
editable_in_portal: true,
416+
required_in_portal: true,
417+
}, // should be present
418+
{
419+
...textField,
420+
id: 2,
421+
type: "subject",
422+
active: true,
423+
editable_in_portal: true,
424+
required_in_portal: true,
425+
}, // should be filtered out
426+
{
427+
...textField,
428+
id: 3,
429+
type: "description",
430+
active: true,
431+
editable_in_portal: true,
432+
required_in_portal: true,
433+
}, // should be filtered out
434+
{
435+
...textField,
436+
id: 4,
437+
type: "text",
438+
active: false,
439+
editable_in_portal: true,
440+
required_in_portal: true,
441+
}, // should be filtered out
442+
{
443+
...textField,
444+
id: 5,
445+
type: "text",
446+
active: true,
447+
editable_in_portal: false,
448+
required_in_portal: true,
449+
}, // should be filtered out
450+
{
451+
...textField,
452+
id: 6,
453+
type: "text",
454+
active: true,
455+
editable_in_portal: true,
456+
required_in_portal: true,
457+
}, // should be present
458+
{
459+
...lookupField,
460+
id: 7,
461+
}, // should be filtered out
462+
],
463+
};
464+
(globalThis.fetch as jest.Mock) = jest.fn((url) => {
465+
return Promise.resolve({
466+
json: () =>
467+
Promise.resolve(
468+
url.includes("/api/v2/ticket_forms/1")
469+
? formResponse
470+
: url.includes(`/api/v2/ticket_fields?locale=${baseLocale}`)
471+
? ticketFieldResponse
472+
: {}
473+
),
474+
status: 200,
475+
ok: true,
476+
});
477+
});
478+
const { result, waitForNextUpdate } = renderHook(() =>
479+
useItemFormFields(serviceCatalogItem, baseLocale)
480+
);
481+
await waitForNextUpdate();
482+
const presentIds = result.current.requestFields.map((f) => f.id);
483+
expect(presentIds).toEqual([1, 6]);
484+
});
396485
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const fetchTicketFields = async (
9797
ticketField &&
9898
ticketField.type !== "subject" &&
9999
ticketField.type !== "description" &&
100+
ticketField.active &&
100101
ticketField.editable_in_portal
101102
) {
102103
if (

0 commit comments

Comments
 (0)