Repository navigation
[CSM Portal] case detail: SLA tab #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e25e575
[CSM Portal] case detail: SLA tab
rksk b4261ed
[CSM Portal] SLA tab: consume numeric businessElapsedPercentage
rksk 9e8aa3b
[CSM Portal] SLA tab: point hook at /slas/search
rksk f721cf6
[CSM Portal] SLA tab: address review nitpicks
rksk a29a38e
[CSM Portal] SLA tab: align response key to the /slas contract
rksk 54ada31
[CSM Portal] SLA tab: cap page size at 50
rksk 1e1ad2c
[CSM Portal] SLA tab: per-row SLA consumption bar
rksk 90a0201
Merge remote-tracking branch 'origin/dev-app-csm-portal' into csm-sla-fe
rksk 110edae
[CSM Portal] SLA tab: report backend total + surface truncation
rksk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
apps/csm-portal/webapp/src/features/csm-cases/api/useGetCsmCaseSlas.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import { useQuery, type UseQueryResult } from "@tanstack/react-query"; | ||
| import { ApiQueryKeys } from "@constants/apiConstants"; | ||
| import { useBackendApi } from "@api/backend/client"; | ||
| import { toCaseSla } from "@features/csm-cases/utils/caseSlaMapping"; | ||
| import type { | ||
| CaseSlaList, | ||
| TaskSlaSearchPayload, | ||
| TaskSlaSearchResponse, | ||
| } from "@features/csm-cases/types/csmCases"; | ||
|
|
||
| const TASK_SLA_PAGE_LIMIT = 50; // entity caps the page size at 50 | ||
|
|
||
| /** | ||
| * Lists the SLA records attached to a case. | ||
| * | ||
| * Calls the task-SLA search endpoint scoped to this case's id (a case is a | ||
| * task) and maps each result onto the {@link CaseSla} row model the SLA table | ||
| * renders (see {@link toCaseSla}). The query only runs while `caseId` is set, | ||
| * so callers that mount this hook conditionally (e.g. only while the SLA tab | ||
| * is active) get lazy fetching for free. | ||
| */ | ||
| export function useGetCsmCaseSlas( | ||
| caseId: string | undefined, | ||
| ): UseQueryResult<CaseSlaList | null, Error> { | ||
| const api = useBackendApi(); | ||
| const enabled = !!caseId; | ||
|
|
||
| return useQuery<CaseSlaList | null, Error>({ | ||
| queryKey: [ApiQueryKeys.CSM_CASE_SLAS, caseId ?? ""], | ||
| queryFn: async (): Promise<CaseSlaList | null> => { | ||
| if (!caseId) return null; | ||
| const res = await api.post<TaskSlaSearchPayload, TaskSlaSearchResponse>( | ||
| "/slas/search", | ||
| { | ||
| filters: { taskIds: [caseId] }, | ||
| pagination: { limit: TASK_SLA_PAGE_LIMIT, offset: 0 }, | ||
| }, | ||
| ); | ||
| const slas = (res.slas ?? []).map(toCaseSla); | ||
| // Count reflects the rows actually rendered (this table always shows a | ||
| // case's full SLA list), not the backend's total-across-pages figure. | ||
| return { caseId, count: slas.length, slas }; | ||
| }, | ||
| enabled, | ||
| staleTime: 30_000, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
apps/csm-portal/webapp/src/features/csm-cases/components/CaseSlaTable.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it, vi, beforeEach } from "vitest"; | ||
| import "@testing-library/jest-dom/vitest"; | ||
| import { CaseSlaTable } from "@features/csm-cases/components/CaseSlaTable"; | ||
| import type { CaseSla, CaseSlaList } from "@features/csm-cases/types/csmCases"; | ||
| import { useGetCsmCaseSlas } from "@features/csm-cases/api/useGetCsmCaseSlas"; | ||
|
|
||
| vi.mock("@features/csm-cases/api/useGetCsmCaseSlas", () => ({ | ||
| useGetCsmCaseSlas: vi.fn(), | ||
| })); | ||
|
|
||
| const mockedUseGetCsmCaseSlas = vi.mocked(useGetCsmCaseSlas); | ||
|
|
||
| const SLA_ROW: CaseSla = { | ||
| id: "sla-1", | ||
| definition: "S1 - Response", | ||
| target: "1 Business Hour", | ||
| stage: "in_progress", | ||
| stageLabel: "In progress", | ||
| hasBreached: false, | ||
| businessTimeLeftLabel: "30 minutes", | ||
| businessElapsedLabel: "30 minutes", | ||
| businessElapsedPercent: 50, | ||
| startTime: "2026-07-01T10:00:00Z", | ||
| stopTime: null, | ||
| }; | ||
|
|
||
| function mockResult(overrides: Partial<ReturnType<typeof useGetCsmCaseSlas>>): void { | ||
| mockedUseGetCsmCaseSlas.mockReturnValue({ | ||
| data: null, | ||
| isLoading: false, | ||
| isError: false, | ||
| isFetching: false, | ||
| dataUpdatedAt: 0, | ||
| refetch: vi.fn(), | ||
| ...overrides, | ||
| } as unknown as ReturnType<typeof useGetCsmCaseSlas>); | ||
| } | ||
|
|
||
| describe("CaseSlaTable", () => { | ||
| beforeEach(() => { | ||
| mockedUseGetCsmCaseSlas.mockReset(); | ||
| }); | ||
|
|
||
| it("renders a loading skeleton while the query is in flight", () => { | ||
| mockResult({ isLoading: true }); | ||
| render(<CaseSlaTable caseId="case-1" />); | ||
| expect(screen.getByText("SLAs")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders an empty state when there are no SLAs", () => { | ||
| const empty: CaseSlaList = { caseId: "case-1", count: 0, slas: [] }; | ||
| mockResult({ data: empty }); | ||
| render(<CaseSlaTable caseId="case-1" />); | ||
| expect(screen.getByText("No SLAs on this case.")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders SLA rows with definition, stage, and time labels", () => { | ||
| const list: CaseSlaList = { caseId: "case-1", count: 1, slas: [SLA_ROW] }; | ||
| mockResult({ data: list }); | ||
| render(<CaseSlaTable caseId="case-1" />); | ||
| expect(screen.getByText("S1 - Response")).toBeInTheDocument(); | ||
| expect(screen.getByText("In progress")).toBeInTheDocument(); | ||
| expect(screen.getAllByText("30 minutes").length).toBeGreaterThan(0); | ||
| expect(screen.getByText("50%")).toBeInTheDocument(); | ||
| // Stop time is null → rendered as an em dash. | ||
| expect(screen.getByText("—")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders an error state with a retry action that refetches", () => { | ||
| const refetch = vi.fn(); | ||
| mockResult({ isError: true, refetch }); | ||
| render(<CaseSlaTable caseId="case-1" />); | ||
| expect(screen.getByText("Could not load SLAs for this case.")).toBeInTheDocument(); | ||
| fireEvent.click(screen.getByRole("button", { name: /retry/i })); | ||
| expect(refetch).toHaveBeenCalled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.