Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions apps/csm-portal/microapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import TimeCardsPage from "@pages/TimeCardsPage";
import SecurityCenterPage from "@pages/SecurityCenterPage";
import UpdatesPage from "@pages/UpdatesPage";
import EngagementsPage from "@pages/EngagementsPage";
import SettingsPage from "@pages/SettingsPage";
import ProfilePage from "@pages/ProfilePage";

export default function App() {
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function App() {
<Route path="/more/security-center" element={<SecurityCenterPage />} />
<Route path="/more/updates" element={<UpdatesPage />} />
<Route path="/more/engagements" element={<EngagementsPage />} />
<Route path="/more/settings" element={<SettingsPage />} />
<Route path="/profile" element={<ProfilePage />} />
</Route>
</Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ import { Card, Chip, Stack, Typography } from "@wso2/oxygen-ui";
interface ComingSoonPageProps {
title: string;
description: string;
blockedOn?: string;
}

// Placeholder for microapp sections not yet built, mirroring the webapp's CsmComingSoonPage
// (apps/csm-portal/webapp/src/features/csm-coming-soon/pages/CsmComingSoonPage.tsx) — used
// deliberately so a reserved tab/route feels real instead of dead or missing.
export function ComingSoonPage({ title, description }: ComingSoonPageProps) {
export function ComingSoonPage({ title, description, blockedOn }: ComingSoonPageProps) {
return (
<Stack gap={3}>
<Stack direction="row" alignItems="center" gap={1.5}>
<Typography variant="h5">{title}</Typography>
<Chip size="small" label="Coming soon" color="warning" variant="outlined" />
</Stack>
<Card sx={{ p: 3 }}>
<Card sx={{ p: 3, display: "flex", flexDirection: "column", gap: 1.5 }}>
<Typography variant="body1">{description}</Typography>
{blockedOn && (
<Typography variant="body2" color="text.secondary">
Blocked on: {blockedOn}
</Typography>
)}
</Card>
</Stack>
);
Expand Down
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 { Button, Stack, Typography } from "@wso2/oxygen-ui";
import { useQuery } from "@tanstack/react-query";
import { Link } from "react-router-dom";
import { currentUser } from "@src/services/currentUser";
import { dashboard } from "@src/services/dashboard";
import { CaseCard, CaseCardSkeleton } from "@components/support/CaseCard";
import { EmptyState } from "@components/support/EmptyState";
import { ErrorState } from "@components/support/ErrorState";

// The signed-in user's own non-closed cases — mirrors the webapp's "Assigned to me" widget
// (apps/csm-portal/webapp/src/features/csm-dashboard/components/MyAssignedCases.tsx), capped to a
// short 5-item preview with a "View all" link out to Support, rather than paginated in place.
export function AssignedToMeSection() {
const { data: currentUserId } = useQuery(currentUser.id());
const { data, isLoading, isError, refetch } = useQuery(dashboard.assignedToMe(currentUserId ?? null));

const items = data?.items ?? [];
Comment thread
2003dinijay marked this conversation as resolved.
Resolved

return (
<Stack gap={1.5}>
<Stack direction="row" alignItems="center" justifyContent="space-between">
<Typography variant="subtitle1">Assigned to me</Typography>
<Button component={Link} to="/support" variant="text" size="small" disableRipple>
View all
</Button>
</Stack>

{isLoading ? (
<Stack gap={1.5}>
{Array.from({ length: 3 }).map((_, index) => (
<CaseCardSkeleton key={index} />
))}
</Stack>
) : isError ? (
<ErrorState onRetry={() => void refetch()} />
) : items.length === 0 ? (
<EmptyState message="No cases assigned to you." />
) : (
<Stack gap={1.5}>
{items.map((item) => (
<CaseCard key={item.id} item={item} />
))}
</Stack>
)}
</Stack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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 } from "react";
import { Stack, Typography } from "@wso2/oxygen-ui";
import { useQuery } from "@tanstack/react-query";
import { dashboard } from "@src/services/dashboard";
import { ALL_SEVERITIES, SEVERITY_LABELS, STATE_LABELS } from "@components/support/config";
import { COMPOSITION_STATES, SEVERITY_SLICE_COLOR, STATE_SLICE_COLOR } from "./config";
import { CompositionDonut, type CompositionSlice } from "./CompositionDonut";

// Two donuts — severity composition and state composition of active cases — mirrors the webapp's
// CaseCompositionCharts (apps/csm-portal/webapp/src/features/csm-dashboard/components/CaseCompositionCharts.tsx),
// stacked instead of side-by-side (the webapp's own grid already collapses to one column below its
// "md" breakpoint, which is every phone width anyway). Self-contained plain useQuery rather than
// Suspense, matching how TimeCardsPage.tsx already handles independent, non-blocking widgets in
// this app — one failed/slow widget shouldn't hold up the rest of the Home page.
export function CaseCompositionSection() {
const { data, isLoading, isError } = useQuery(dashboard.composition());

const severitySlices = useMemo<CompositionSlice[]>(
() =>
ALL_SEVERITIES.map((severity) => ({
id: severity,
name: SEVERITY_LABELS[severity],
value: data?.bySeverity[severity] ?? 0,
color: SEVERITY_SLICE_COLOR[severity],
})),
[data],
);

const stateSlices = useMemo<CompositionSlice[]>(
() =>
COMPOSITION_STATES.map((state) => ({
id: state,
name: STATE_LABELS[state],
value: data?.byState[state] ?? 0,
color: STATE_SLICE_COLOR[state],
})),
[data],
);

const closedTotal = data?.closedTotal ?? 0;

return (
<Stack gap={1.5}>
<Typography variant="subtitle1">Case composition</Typography>

<Stack gap={1.5}>
<CompositionDonut
title="Cases by severity"
description="Share of active cases at each severity level, excluding closed."
slices={severitySlices}
total={data?.severityTotal ?? 0}
isLoading={isLoading}
isError={isError}
/>
<CompositionDonut
title="Cases by state"
description="Share of active cases in each lifecycle state, excluding closed."
slices={stateSlices}
total={data?.stateTotal ?? 0}
isLoading={isLoading}
isError={isError}
/>
</Stack>

{/* Reconciles with the donuts: both show active cases only, so the closed count is called
out here rather than mixed into a slice — same as the webapp. */}
{!isLoading && !isError && closedTotal > 0 && (
<Typography variant="caption" color="text.secondary">
Excludes {closedTotal} closed {closedTotal === 1 ? "case" : "cases"}.
</Typography>
)}
</Stack>
);
}
153 changes: 153 additions & 0 deletions apps/csm-portal/microapp/src/components/home/CompositionDonut.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// 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 { Box, Card, Skeleton, Typography } from "@wso2/oxygen-ui";
import { PieChart } from "@wso2/oxygen-ui-charts-react";

// Donut sits in a fixed square; the legend fills the rest of the card width. Smaller than the
// webapp's 200px version (CompositionDonut.tsx) to fit a phone-width card comfortably.
const DONUT_SIZE = 160;

export interface CompositionSlice {
id: string;
name: string;
value: number;
color: string;
}

interface CompositionDonutProps {
title: string;
description: string;
slices: CompositionSlice[];
total: number;
isLoading: boolean;
isError: boolean;
/** Noun for the empty state, e.g. "cases". */
emptyNoun?: string;
}

// A donut chart with a value/percentage legend and a centred total — mirrors the webapp's
// CompositionDonut (apps/csm-portal/webapp/src/features/csm-dashboard/components/CompositionDonut.tsx).
// Zero-value slices drop from the ring but stay in the legend so every category remains visible.
// No slice-click drill-down here (unlike the webapp): the microapp's Support page doesn't support
// seeding filters from the URL, so there's nowhere to deep-link a click into yet.
export function CompositionDonut({
title,
description,
slices,
total,
isLoading,
isError,
emptyNoun = "cases",
}: CompositionDonutProps) {
const pieData = slices.filter((s) => s.value > 0);
const isEmpty = !isLoading && !isError && total === 0;

return (
<Card sx={{ p: 2 }}>
<Typography variant="subtitle1" fontWeight={600}>
{title}
</Typography>
<Typography variant="caption" color="text.secondary">
{description}
</Typography>

{isLoading ? (
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 2, mt: 2 }}>
<Skeleton variant="circular" width={DONUT_SIZE} height={DONUT_SIZE} />
<Box sx={{ width: "100%", display: "flex", flexDirection: "column", gap: 1 }}>
{slices.map((s) => (
<Skeleton key={s.id} variant="rounded" height={18} />
))}
</Box>
</Box>
) : isError ? (
<Box sx={{ height: DONUT_SIZE, display: "flex", alignItems: "center", justifyContent: "center" }}>
<Typography variant="body2" color="text.secondary">
Could not load {title.toLowerCase()}.
</Typography>
</Box>
) : isEmpty ? (
<Box sx={{ height: DONUT_SIZE, display: "flex", alignItems: "center", justifyContent: "center" }}>
<Typography variant="body2" color="text.disabled">
No {emptyNoun} to show.
</Typography>
</Box>
) : (
<Box sx={{ mt: 2, display: "flex", flexDirection: "column", alignItems: "center", gap: 2 }}>
<Box sx={{ position: "relative", width: DONUT_SIZE, height: DONUT_SIZE, flexShrink: 0 }}>
<PieChart
data={pieData}
colors={pieData.map((s) => s.color)}
legend={{ show: false }}
tooltip={{ show: true }}
width="100%"
height={DONUT_SIZE}
pies={[
{
dataKey: "value",
nameKey: "name",
innerRadius: "62%",
outerRadius: "100%",
paddingAngle: 1,
startAngle: 90,
endAngle: -270,
label: false,
labelLine: false,
},
]}
/>
<Box
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
textAlign: "center",
pointerEvents: "none",
}}
>
<Typography variant="h5">{total}</Typography>
<Typography variant="caption" color="text.secondary">
Total
</Typography>
</Box>
</Box>

{/* Legend: every category, with its count and share. */}
<Box sx={{ width: "100%", display: "flex", flexDirection: "column", gap: 1 }}>
{slices.map((s) => {
const pct = total > 0 ? Math.round((s.value / total) * 100) : 0;
return (
<Box key={s.id} sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 1 }}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1, minWidth: 0 }}>
<Box sx={{ width: 12, height: 12, borderRadius: "50%", bgcolor: s.color, flexShrink: 0 }} />
<Typography variant="body2" color="text.secondary" noWrap>
{s.name}
</Typography>
</Box>
<Typography variant="body2" fontWeight={600} sx={{ whiteSpace: "nowrap" }}>
{s.value} ({pct}%)
</Typography>
</Box>
);
})}
</Box>
</Box>
)}
</Card>
);
}
Loading