diff --git a/apps/csm-portal/microapp/src/components/case-detail/LinkCaseDialog.tsx b/apps/csm-portal/microapp/src/components/case-detail/LinkCaseDialog.tsx new file mode 100644 index 0000000000..0a35befaf0 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/case-detail/LinkCaseDialog.tsx @@ -0,0 +1,214 @@ +// 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 { useMemo, useState } from "react"; +import { + alpha, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControlLabel, + Radio, + RadioGroup, + Skeleton, + Stack, + TextField, + Typography, +} from "@wso2/oxygen-ui"; +import { Search } from "@wso2/oxygen-ui-icons-react"; +import { useQuery } from "@tanstack/react-query"; +import { cases, QUICK_SEARCH_MIN_QUERY_LEN } from "@src/services/cases"; +import type { CaseSummary } from "@src/types"; +import { SeverityChip, StatusChip } from "@components/support/Chips"; +import { useDebouncedValue } from "@utils/useDebouncedValue"; + +export type CaseLinkType = "parent" | "related"; + +interface LinkCaseDialogProps { + /** The case being linked from — excluded from its own search results. */ + currentCaseId: string; + /** True while a PATCH is in flight; disables the actions. */ + isLinking: boolean; + onClose: () => void; + /** Link the current case to `targetCaseId` as either its parent or a related case. */ + onLink: (targetCaseId: string, linkType: CaseLinkType) => void; +} + +/** + * Search-and-select a case to link the current one to — either as its **parent** (`PATCH + * { parentId }`, the hierarchical major-case/child-case relationship) or as a **related case** + * (`PATCH { relatedCaseId }`, a looser cross-link). Mirrors the webapp's LinkCaseDialog: picking a + * search result doesn't link immediately — it shows a selected-case summary to confirm against + * first, with a "Change" button back to search; the PATCH only fires from "Link". + */ +export function LinkCaseDialog({ currentCaseId, isLinking, onClose, onLink }: LinkCaseDialogProps) { + const [linkType, setLinkType] = useState("parent"); + const [input, setInput] = useState(""); + const [selected, setSelected] = useState(null); + const debouncedInput = useDebouncedValue(input.trim(), 300); + const { data, isFetching, isError } = useQuery(cases.quickSearch(debouncedInput)); + + const candidates = useMemo(() => (data ?? []).filter((c) => c.id !== currentCaseId), [data, currentCaseId]); + + return ( + + Link to another case + + + setLinkType(e.target.value as CaseLinkType)}> + } label="As parent" /> + } + label="As related case" + /> + + + {linkType === "parent" + ? "The hierarchical major-case/child-case relationship — this case can't close while it has open children linked this way." + : "A looser cross-link; not subject to the child-case close restriction."} + + + {selected ? ( + ({ + px: 1.5, + py: 1, + borderRadius: 1, + border: "1px solid", + borderColor: "success.main", + bgcolor: alpha(theme.palette.success.main, 0.1), + })} + > + + + {selected.number} — {selected.subject} + + + + {selected.severity && } + {selected.assignedEngineer?.name && ( + + {selected.assignedEngineer.name} + + )} + + + + + ) : ( + + setInput(e.target.value)} + placeholder="Search by case number or subject…" + size="small" + fullWidth + autoFocus + slotProps={{ input: { startAdornment: } }} + /> + {input.trim().length < QUICK_SEARCH_MIN_QUERY_LEN ? ( + + Type at least {QUICK_SEARCH_MIN_QUERY_LEN} characters to search + + ) : isFetching ? ( + + {[0, 1, 2].map((i) => ( + + ))} + + ) : isError ? ( + + Could not search cases. Try again. + + ) : candidates.length === 0 ? ( + + No matching cases. + + ) : ( + + {candidates.map((hit) => ( + + ))} + + )} + + )} + + + + + + + + ); +} diff --git a/apps/csm-portal/microapp/src/components/case-detail/LinkedItemsTab.tsx b/apps/csm-portal/microapp/src/components/case-detail/LinkedItemsTab.tsx new file mode 100644 index 0000000000..5c7df20ccd --- /dev/null +++ b/apps/csm-portal/microapp/src/components/case-detail/LinkedItemsTab.tsx @@ -0,0 +1,350 @@ +// 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 { useMemo, type JSX, type ReactNode } from "react"; +import { Box, Button, Card, Chip, Skeleton, Stack, Tooltip, Typography, pxToRem, useTheme } from "@wso2/oxygen-ui"; +import { ChevronRight, GitFork, GitPullRequest, Link as LinkIcon, Plus } from "@wso2/oxygen-ui-icons-react"; +import { Link } from "react-router-dom"; +import { useQueries, useQuery } from "@tanstack/react-query"; +import { cases, type ChildCaseRow } from "@src/services/cases"; +import { changeRequests } from "@src/services/changeRequests"; +import type { CaseDetail, CaseLinkRefDto } from "@src/types"; +import { SeverityChip, StatusChip } from "@components/support/Chips"; +import { changeRequestStateColor, changeRequestStateLabel } from "@components/operations/config"; + +interface LinkedItemsTabProps { + caseId: string; + caseDetail: CaseDetail; + isClosed: boolean; + onLinkCase: () => void; + onCreateServiceRequest: () => void; +} + +/** + * "Linked Items" tab — mirrors the webapp's CsmCaseDetailPage `related` tab (Child cases, Linked + * service requests, Linked change requests), adapted from its desktop tables to mobile cards. The + * webapp's per-widget refresh buttons are dropped — the microapp doesn't have that convention + * anywhere else in the case detail page, which already re-fetches the whole case on every mutation + * (see CaseDetailPage.tsx's invalidateCase). + */ +export function LinkedItemsTab({ + caseId, + caseDetail, + isClosed, + onLinkCase, + onCreateServiceRequest, +}: LinkedItemsTabProps) { + // Content-relevance, not a data-source gate: shown whenever this is a service request (the only + // case type that carries the link) or the list already has entries — mirrors the webapp. + const showLinkedChangeRequests = caseDetail.type === "service_request" || caseDetail.linkedChangeRequests.length > 0; + + return ( + + + + + + + + + + + + {showLinkedChangeRequests && } + + ); +} + +// --------------------------------------------------------------------------- +// Shared row shell — a tappable case card compact enough to list several per +// tab, unlike the full support/CaseCard.tsx (which needs fields these linked +// refs don't always carry, e.g. wso2Id/updatedOn/type). +// --------------------------------------------------------------------------- + +function LinkedItemsSection({ + icon, + title, + count, + action, + emptyMessage, + children, +}: { + icon: JSX.Element; + title: string; + count?: number; + action?: ReactNode; + emptyMessage: string; + children: ReactNode; +}) { + const isEmpty = count === 0; + return ( + + + + + {icon} + + {title} + {typeof count === "number" && count > 0 ? ` (${count})` : ""} + + + {action} + + {isEmpty ? ( + + {emptyMessage} + + ) : ( + {children} + )} + + + ); +} + +function CaseRow({ + to, + label, + severity, + state, + assigneeName, + loading, +}: { + to: string; + label: string; + severity?: CaseDetailSeverity; + state?: CaseDetailState; + assigneeName?: string | null; + /** True while enrichment (state/severity/assignee) is still resolving — shows skeletons for + * those fields instead of a bare "—", matching LinkedServiceRequestsSection's rows before the + * shared child-cases search resolves. */ + loading?: boolean; +}): JSX.Element { + const theme = useTheme(); + return ( + + + + + {label} + + + {loading ? : state && } + {severity && } + {!loading && assigneeName && ( + + {assigneeName} + + )} + + + + + + ); +} + +// Narrow aliases so CaseRow's props stay readable above without importing the full CaseState/ +// CaseSeverity union names twice. +type CaseDetailSeverity = NonNullable; +type CaseDetailState = CaseDetail["state"]; + +// --------------------------------------------------------------------------- +// 1. Child cases — cases whose own parentId points at this one. +// --------------------------------------------------------------------------- + +function ChildCasesSection({ caseId }: { caseId: string }) { + const { data, isLoading, isError } = useQuery(cases.searchChildren(caseId)); + const rows = data?.cases ?? []; + + return ( + } + title="Child cases" + count={isLoading || isError ? undefined : rows.length} + emptyMessage="No child cases linked to this case." + > + {isError ? ( + + Could not load child cases for this case. + + ) : isLoading ? ( + + {[0, 1].map((i) => ( + + ))} + + ) : ( + rows.map((c) => ) + )} + + ); +} + +function ChildCaseCardRow({ row }: { row: ChildCaseRow }) { + return ( + + ); +} + +// --------------------------------------------------------------------------- +// 2. Linked service requests — the case-detail payload's own refs, enriched +// with state/severity/assignee from the same child-cases search (shared +// cache entry — service requests are children too, just restricted to the +// ids the case-detail response already names). +// --------------------------------------------------------------------------- + +function LinkedServiceRequestsSection({ + caseId, + refs, + createDisabled, + onCreateServiceRequest, +}: { + caseId: string; + refs: CaseLinkRefDto[]; + createDisabled: boolean; + onCreateServiceRequest: () => void; +}) { + const { data, isLoading, isError } = useQuery(cases.searchChildren(caseId)); + const enrichedById = useMemo(() => { + const map = new Map(); + for (const row of data?.cases ?? []) map.set(row.id, row); + return map; + }, [data]); + // isError means enrichment is unavailable, not pending — fall straight to a plain row instead + // of a skeleton that would spin forever. + const enriching = isLoading && !isError; + + return ( + } + title="Linked service requests" + count={refs.length} + emptyMessage="No service requests linked to this case." + action={ + + + + + + } + > + {refs.map((ref) => { + const enriched = enrichedById.get(ref.id); + return ( + + ); + })} + + ); +} + +// --------------------------------------------------------------------------- +// 3. Linked change requests — raised from this service request. Each ref only +// carries id/number/name; state and target environment are fetched per row +// (fanned out with useQueries, mirroring the webapp), so a slow or failed +// row never blocks or hides the others. +// --------------------------------------------------------------------------- + +function LinkedChangeRequestsSection({ refs }: { refs: CaseLinkRefDto[] }) { + const queries = useQueries({ + queries: refs.map((ref) => changeRequests.get(ref.id)), + }); + + return ( + } + title="Linked change requests" + count={refs.length} + emptyMessage="No change requests have been raised from this service request yet." + > + {refs.map((ref, i) => { + const query = queries[i]; + const detail = query?.data; + const rowLoading = query?.isLoading ?? false; + return ( + + + + + {[ref.number, ref.name].filter(Boolean).join(" — ")} + + + {rowLoading ? ( + + ) : detail ? ( + + ) : null} + {!rowLoading && detail?.deployment?.name && ( + + {detail.deployment.name} + + )} + + + + + ); + })} + + ); +} diff --git a/apps/csm-portal/microapp/src/pages/CaseDetailPage.tsx b/apps/csm-portal/microapp/src/pages/CaseDetailPage.tsx index cde3cedc5c..1c39c493b6 100644 --- a/apps/csm-portal/microapp/src/pages/CaseDetailPage.tsx +++ b/apps/csm-portal/microapp/src/pages/CaseDetailPage.tsx @@ -15,7 +15,7 @@ // under the License. import { Suspense, useRef, useState, type ReactNode } from "react"; -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { Card, Divider, Grid, Skeleton, Stack, Tab, Tabs, Typography, pxToRem } from "@wso2/oxygen-ui"; import { Building2, @@ -54,6 +54,8 @@ import { TYPE_CONFIG } from "@components/support/config"; import { CaseActionBar } from "@components/case-detail/CaseActionBar"; import { CaseMoreMenu } from "@components/case-detail/CaseMoreMenu"; import { ChangeSeverityDialog } from "@components/case-detail/ChangeSeverityDialog"; +import { LinkCaseDialog, type CaseLinkType } from "@components/case-detail/LinkCaseDialog"; +import { LinkedItemsTab } from "@components/case-detail/LinkedItemsTab"; import { LogTimeCardDialog } from "@components/case-detail/LogTimeCardDialog"; import { ResolutionDialog } from "@components/case-detail/ResolutionDialog"; import { CommentComposer } from "@components/case-detail/CommentComposer"; @@ -63,16 +65,18 @@ import { SlaTab } from "@components/case-detail/SlaTab"; import { AttachmentsTab } from "@components/case-detail/AttachmentsTab"; import { CallRequestsTab } from "@components/case-detail/CallRequestsTab"; import { TimeTrackingTab } from "@components/case-detail/TimeTrackingTab"; +import type { CreateServiceRequestFromCaseNavState } from "@pages/NewServiceRequestPage"; import { formatDate } from "@utils/dateTime"; import { Logger } from "@utils/logger"; import { toApiError } from "@utils/ApiError"; import type { PendingAttachment } from "@utils/attachments"; -type CaseTabId = "activities" | "details" | "sla" | "attachments" | "time" | "call-requests"; +type CaseTabId = "activities" | "details" | "related" | "sla" | "attachments" | "time" | "call-requests"; const TAB_DEFS: Array<{ id: CaseTabId; label: string }> = [ { id: "activities", label: "Activities" }, { id: "details", label: "Details" }, + { id: "related", label: "Linked Items" }, { id: "sla", label: "SLAs" }, { id: "attachments", label: "Attachments" }, { id: "time", label: "Time tracking" }, @@ -96,6 +100,7 @@ export default function CaseDetailPage() { } function CaseDetailContent({ id }: { id: string }) { + const navigate = useNavigate(); const queryClient = useQueryClient(); const { data: caseDetail } = useSuspenseQuery(cases.get(id)); const { data: comments } = useSuspenseQuery(cases.comments(id)); @@ -119,9 +124,12 @@ function CaseDetailContent({ id }: { id: string }) { const [logTimeOpen, setLogTimeOpen] = useState(false); const [isLoggingTime, setIsLoggingTime] = useState(false); const [logTimeError, setLogTimeError] = useState(null); + const [linkCaseOpen, setLinkCaseOpen] = useState(false); + const [isLinkingCase, setIsLinkingCase] = useState(false); + const ANNOUNCEMENT_HIDDEN_TABS: CaseTabId[] = ["related", "sla", "time", "call-requests"]; const visibleTabDefs = isAnnouncement - ? TAB_DEFS.filter((tab) => tab.id !== "sla" && tab.id !== "time" && tab.id !== "call-requests") + ? TAB_DEFS.filter((tab) => !ANNOUNCEMENT_HIDDEN_TABS.includes(tab.id)) : TAB_DEFS; // If a case turns out to be an announcement (only knowable once caseDetail // loads) while a tab hidden for announcements is active, fall back to @@ -336,6 +344,32 @@ function CaseDetailContent({ id }: { id: string }) { .finally(() => setIsLoggingTime(false)); }; + const handleLinkCase = (targetCaseId: string, linkType: CaseLinkType): void => { + setIsLinkingCase(true); + setMutationError(null); + cases + .patch(id, linkType === "parent" ? { parentId: targetCaseId } : { relatedCaseId: targetCaseId }) + .then(() => { + setLinkCaseOpen(false); + invalidateCase(); + }) + .catch(() => setMutationError("Could not link the case. Please try again.")) + .finally(() => setIsLinkingCase(false)); + }; + + // Pre-fills the create-service-request form and links the new SR back to this case in one step + // (see CreateServiceRequestFromCaseNavState) — no separate create-then-link round trip. + const handleCreateServiceRequest = (): void => { + const navState: CreateServiceRequestFromCaseNavState = { + projectId: caseDetail.project.id, + relatedCaseId: caseDetail.id, + relatedCaseNumber: caseDetail.number, + deploymentId: caseDetail.deployment?.id, + deployedProductId: caseDetail.deployedProduct?.id, + }; + navigate("/operations/service-requests/new", { state: navState }); + }; + // Text and inline attachments upload as separate requests (the backend's comment payload has no // file field — see CaseCommentCreatePayloadDto), mirroring NewCasePage's create-then-attach // pattern. An empty comment with attachments still sends: the case gets the files with no @@ -440,6 +474,16 @@ function CaseDetailContent({ id }: { id: string }) { )} + {effectiveTab === "related" && ( + setLinkCaseOpen(true)} + onCreateServiceRequest={handleCreateServiceRequest} + /> + )} + {effectiveTab === "sla" && } {effectiveTab === "attachments" && } @@ -498,6 +542,14 @@ function CaseDetailContent({ id }: { id: string }) { onSubmit={handleLogTimeSubmit} /> )} + {linkCaseOpen && ( + setLinkCaseOpen(false)} + onLink={handleLinkCase} + /> + )} ); } diff --git a/apps/csm-portal/microapp/src/pages/NewServiceRequestPage.tsx b/apps/csm-portal/microapp/src/pages/NewServiceRequestPage.tsx index 8334862b9d..964bd32cf1 100644 --- a/apps/csm-portal/microapp/src/pages/NewServiceRequestPage.tsx +++ b/apps/csm-portal/microapp/src/pages/NewServiceRequestPage.tsx @@ -14,13 +14,14 @@ // specific language governing permissions and limitations // under the License. -import { useMemo, useState } from "react"; -import { useNavigate } from "react-router-dom"; +import { useEffect, useMemo, useState } from "react"; +import { useLocation, useNavigate } from "react-router-dom"; import { Button, FormControl, FormHelperText, InputLabel, MenuItem, Select, Stack, Typography } from "@wso2/oxygen-ui"; import { useMutation, useQuery } from "@tanstack/react-query"; import { cases } from "@src/services/cases"; import { deployments } from "@src/services/deployments"; import { catalogs } from "@src/services/catalogs"; +import { projects } from "@src/services/projects"; import { attachments as attachmentsService } from "@src/services/attachments"; import type { Project } from "@src/types"; import { Logger } from "@utils/logger"; @@ -35,18 +36,32 @@ import { } from "@utils/catalogVariables"; import type { PendingAttachment } from "@utils/attachments"; +// Router (`navigate(..., { state })`) payload carried from a case's "Create service request" +// action (case detail's Linked Items tab) to this page, so the form can prefill from the +// originating case and file the new SR as linked to it in one step. Mirrors the webapp's +// CreateServiceRequestFromCaseNavState: `projectId` locks the Project field read-only; +// `deploymentId`/`deployedProductId` are just starting values and stay fully editable. +export interface CreateServiceRequestFromCaseNavState { + projectId: string; + relatedCaseId: string; + relatedCaseNumber?: string; + deploymentId?: string; + deployedProductId?: string; +} + // Ports the webapp's CreateServiceRequestPage.tsx (features/csm-operations/pages/): the same // cascading Project → Deployment → Deployed product → Catalog → Catalog item picker, driving a // dynamic form built from the chosen catalog item's ServiceNow variables. Layout follows this -// app's own NewCasePage.tsx (single-column Stack, no locked-project entry point) rather than the -// webapp's Grid/Card, and — like NewCasePage — the Description variable renders as a plain -// multiline field rather than the rich-text editor (this app has no rich-text component). +// app's own NewCasePage.tsx (single-column Stack) rather than the webapp's Grid/Card, and — like +// NewCasePage — the Description variable renders as a plain multiline field rather than the +// rich-text editor (this app has no rich-text component). export default function NewServiceRequestPage() { const navigate = useNavigate(); + const fromCaseState = useLocation().state as CreateServiceRequestFromCaseNavState | undefined; const [project, setProject] = useState(null); - const [deploymentId, setDeploymentId] = useState(""); - const [deployedProductId, setDeployedProductId] = useState(""); + const [deploymentId, setDeploymentId] = useState(fromCaseState?.deploymentId ?? ""); + const [deployedProductId, setDeployedProductId] = useState(fromCaseState?.deployedProductId ?? ""); const [catalogId, setCatalogId] = useState(""); const [catalogItemId, setCatalogItemId] = useState(""); // Variable answers, keyed by variable id. @@ -59,6 +74,16 @@ export default function NewServiceRequestPage() { // NewCasePage.tsx. const [isSubmitting, setIsSubmitting] = useState(false); + // Resolves the full Project (ProjectSelect needs more than the nav state's bare id) once, to + // seed the locked field below — never re-runs once `project` is set, so it doesn't fight a + // user's own pick on a page that arrived without a related case. + const lockedProjectId = fromCaseState?.projectId; + const lockedProjectQuery = useQuery({ ...projects.get(lockedProjectId ?? ""), enabled: !!lockedProjectId }); + useEffect(() => { + if (lockedProjectQuery.data && !project) setProject(lockedProjectQuery.data); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [lockedProjectQuery.data]); + const deploymentsQuery = useQuery(deployments.byProject(project?.id ?? "")); const productsQuery = useQuery(deployments.productsByDeployment(deploymentId)); const catalogsQuery = useQuery(catalogs.search(deployedProductId)); @@ -151,6 +176,7 @@ export default function NewServiceRequestPage() { catalogId, catalogItemId, variables: variablePayload, + ...(fromCaseState?.relatedCaseId ? { relatedCaseId: fromCaseState.relatedCaseId } : {}), }); // The create endpoint doesn't attach files for service requests, so upload them to the new @@ -183,9 +209,26 @@ export default function NewServiceRequestPage() { return ( New Service Request + {fromCaseState && ( + + Creating from case {fromCaseState.relatedCaseNumber ?? fromCaseState.relatedCaseId} + + )} + {lockedProjectQuery.isError && ( + + Could not load the case's project. Pick one below to continue. + + )} - + => { + const result = await getAllCases({ + filters: { types: ALL_CASE_TYPES, parentId: parentCaseId }, + pagination: { offset: 0, limit: CHILD_CASES_LIMIT }, + }); + return { + cases: result.items.map((c) => ({ + id: c.id, + number: c.number, + subject: c.subject, + severity: c.severity, + state: c.state, + assigneeName: c.assignedEngineer?.name ?? null, + })), + total: result.total, + }; +}; + +// Don't fire LinkCaseDialog's search until the user has typed something searchable — mirrors the +// webapp's QUICK_CASE_MIN_QUERY_LEN. +export const QUICK_SEARCH_MIN_QUERY_LEN = 2; +const QUICK_SEARCH_LIMIT = 8; + +// Free-text case lookup for LinkCaseDialog's search-and-pick — the same `/cases/search` the cases +// list itself uses. Explicitly requests every case sub-type (mirrors the webapp's +// useQuickCaseSearch): entity-service defaults `filters.types` to `["case"]` only when the caller +// omits it, which would otherwise hide service requests/security reports/etc. from this search. +const quickSearchCases = async (query: string): Promise => { + const trimmed = query.trim(); + if (trimmed.length < QUICK_SEARCH_MIN_QUERY_LEN) return []; + const result = await getAllCases({ + filters: { types: ALL_CASE_TYPES, searchQuery: trimmed }, + pagination: { offset: 0, limit: QUICK_SEARCH_LIMIT }, + }); + return result.items; +}; + export const cases = { all: (payload: CaseSearchPayloadDto = {}) => queryOptions({ @@ -310,6 +365,26 @@ export const cases = { queryFn: () => getCaseComments(id), }), + // Linked Items tab: child cases (own `parentId` pointing at this one) — shared by both the + // Child cases card and Linked service requests' enrichment (same underlying relationship, see + // that widget's own comment), so both queries dedupe against this one cache entry. + searchChildren: (caseId: string | undefined) => + queryOptions({ + queryKey: ["cases", "children", caseId ?? ""], + queryFn: () => (caseId ? searchChildCases(caseId) : Promise.resolve({ cases: [], total: 0 })), + enabled: !!caseId, + staleTime: 30_000, + }), + + // Linked Items tab: LinkCaseDialog's search-and-pick. + quickSearch: (query: string) => + queryOptions({ + queryKey: ["cases", "quick-search", query.trim()], + queryFn: () => quickSearchCases(query), + enabled: query.trim().length >= QUICK_SEARCH_MIN_QUERY_LEN, + staleTime: 15_000, + }), + create: createCase, patch: patchCase, postComment, diff --git a/apps/csm-portal/microapp/src/types/case.dto.ts b/apps/csm-portal/microapp/src/types/case.dto.ts index 90fa94f869..22343c8a2c 100644 --- a/apps/csm-portal/microapp/src/types/case.dto.ts +++ b/apps/csm-portal/microapp/src/types/case.dto.ts @@ -103,6 +103,9 @@ export interface CaseSearchFiltersDto { engagementTypes?: EngagementType[]; /** Product family names (e.g. "API Manager"); matches all versions of each. */ productNames?: string[]; + /** UUID of the case whose children (their own `parentId` pointing here) to find — the + * hierarchical major-case/child-case relationship. Mirrors the webapp's useSearchChildCases. */ + parentId?: string; } export interface CaseSearchPayloadDto { @@ -170,6 +173,15 @@ export interface CaseSearchResponseDto { hasMore: boolean; } +// A linked case/service-request/change-request reference on the case-detail response — only +// id/number/name are ever carried (mirrors the webapp's BeLinkedServiceRequestRef/ +// BeLinkedChangeRequestRef); `name` is the target's subject, nullable on records without one. +export interface CaseLinkRefDto { + id: string; + number: string; + name: string | null; +} + export interface CaseViewDto { id: string; number: string; @@ -201,6 +213,8 @@ export interface CaseViewDto { relatedCase: CaseNumberRefDto | null; account: AccountRefDto | null; nextStates: CaseState[]; + linkedServiceRequests?: CaseLinkRefDto[] | null; + linkedChangeRequests?: CaseLinkRefDto[] | null; } export type CaseCommentType = "work_note" | "comment" | "activity"; @@ -248,9 +262,10 @@ export interface CaseCommentCreateResponseDto { }; } -// Backend's UpdateCaseRequest: exactly one of state/severity/workState/assigneeEmail must be -// provided per PATCH call (they're mutually exclusive `oneOf` branches in openapi.yaml) — -// resolutionCode/cause/closeNotes are the exception, allowed alongside `state` only. +// Backend's UpdateCaseRequest: exactly one of state/severity/workState/assigneeEmail/parentId/ +// relatedCaseId must be provided per PATCH call (they're mutually exclusive `oneOf` branches in +// openapi.yaml) — resolutionCode/cause/closeNotes are the exception, allowed alongside `state` +// only. export interface CasePatchPayloadDto { state?: CaseState; severity?: CaseSeverity; @@ -259,6 +274,12 @@ export interface CasePatchPayloadDto { resolutionCode?: CaseResolutionCode; cause?: CaseCause; closeNotes?: string; + /** Links this case to another as its parent (the hierarchical major-case/child-case + * relationship) — this case can't close while it has open children linked this way. */ + parentId?: string; + /** Cross-links this case to another as a related case — looser than `parentId`, not subject to + * the child-case close restriction. */ + relatedCaseId?: string; } export interface UpdateCaseResponseDto { @@ -353,6 +374,9 @@ export interface ServiceRequestCreatePayloadDto { catalogId: string; catalogItemId: string; variables: CaseVariableDto[]; + /** UUID of the case this service request is filed from — links the new request back to it in + * the same create call, mirroring the webapp's CreateServiceRequestFromCaseNavState flow. */ + relatedCaseId?: string; } export interface CreatedCaseDto { diff --git a/apps/csm-portal/microapp/src/types/case.model.ts b/apps/csm-portal/microapp/src/types/case.model.ts index 0126afcff4..e7d8634144 100644 --- a/apps/csm-portal/microapp/src/types/case.model.ts +++ b/apps/csm-portal/microapp/src/types/case.model.ts @@ -19,6 +19,7 @@ import type { AssignedEngineerRefDto, CaseCommentDto, CaseCommentType, + CaseLinkRefDto, CaseNumberRefDto, CaseSearchViewDto, CaseSeverity, @@ -106,6 +107,8 @@ export interface CaseDetail { parentCase: CaseNumberRefDto | null; relatedCase: CaseNumberRefDto | null; nextStates: CaseState[]; + linkedServiceRequests: CaseLinkRefDto[]; + linkedChangeRequests: CaseLinkRefDto[]; } export interface Comment { @@ -181,6 +184,8 @@ export function toCaseDetail(dto: CaseViewDto): CaseDetail { parentCase: dto.parentCase, relatedCase: dto.relatedCase, nextStates: dto.nextStates, + linkedServiceRequests: dto.linkedServiceRequests ?? [], + linkedChangeRequests: dto.linkedChangeRequests ?? [], }; } function commentAuthorLabel(createdBy: CaseCommentDto["createdBy"] | null | undefined): string {