Repository navigation
[CSM Portal] mobile-device banner + fix {{currentTeam}} token in section headings #1363
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
rksk
merged 3 commits into
wso2-open-operations:main
from
rksk:csm-portal-mobile-app-banner
Aug 4, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
144 changes: 144 additions & 0 deletions
144
apps/csm-portal/webapp/src/components/mobile-app-banner/MobileAppBanner.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,144 @@ | ||
| // 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 "@testing-library/jest-dom/vitest"; | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { DeviceType, MobileOs } from "@/types/mobileDevice"; | ||
|
|
||
| const mockConfig = { | ||
| enabled: true, | ||
| iosStoreUrl: "https://apps.apple.com/app/example", | ||
| androidStoreUrl: "https://play.google.com/store/apps/details?id=example", | ||
| includeTablets: false, | ||
| }; | ||
|
|
||
| vi.mock("@utils/deviceDetection", () => ({ | ||
| detectMobileDevice: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@config/mobileAppConfig", () => ({ | ||
| getMobileAppConfig: vi.fn(() => mockConfig), | ||
| getMobileAppStoreUrl: (os: string) => | ||
| os === "ios" ? mockConfig.iosStoreUrl : mockConfig.androidStoreUrl, | ||
| })); | ||
|
|
||
| import { detectMobileDevice } from "@utils/deviceDetection"; | ||
| import MobileAppBanner from "@components/mobile-app-banner/MobileAppBanner"; | ||
|
|
||
| describe("MobileAppBanner", () => { | ||
| beforeEach(() => { | ||
| mockConfig.enabled = true; | ||
| mockConfig.iosStoreUrl = "https://apps.apple.com/app/example"; | ||
| mockConfig.androidStoreUrl = | ||
| "https://play.google.com/store/apps/details?id=example"; | ||
| mockConfig.includeTablets = false; | ||
| vi.stubGlobal("open", vi.fn()); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("renders nothing on desktop (no device detected)", () => { | ||
| vi.mocked(detectMobileDevice).mockReturnValue(null); | ||
|
|
||
| render(<MobileAppBanner />); | ||
|
|
||
| expect(screen.queryByText("Get the WSO2 Super App")).toBeNull(); | ||
| }); | ||
|
|
||
| it("renders nothing when the prompt is disabled even on a mobile device", () => { | ||
| mockConfig.enabled = false; | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Ios, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
|
|
||
| expect(screen.queryByText("Get the WSO2 Super App")).toBeNull(); | ||
| }); | ||
|
|
||
| it("renders nothing when no store URL is configured for the detected OS", () => { | ||
| mockConfig.iosStoreUrl = undefined as unknown as string; | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Ios, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
|
|
||
| expect(screen.queryByText("Get the WSO2 Super App")).toBeNull(); | ||
| }); | ||
|
|
||
| it("shows the banner on a detected mobile phone", () => { | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Android, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
|
|
||
| expect(screen.getByText("Get the WSO2 Super App")).toBeInTheDocument(); | ||
| expect(screen.getByRole("button", { name: /download/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("dismisses on close and stays hidden until re-mounted with a new visible state", () => { | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Ios, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
| expect(screen.getByText("Get the WSO2 Super App")).toBeInTheDocument(); | ||
|
|
||
| const dismissButton = screen.getByRole("button", { name: /close/i }); | ||
| fireEvent.click(dismissButton); | ||
|
|
||
| expect(screen.queryByText("Get the WSO2 Super App")).toBeNull(); | ||
| }); | ||
|
|
||
| it("opens the store URL via window.open when the download action is used", () => { | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Ios, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
| fireEvent.click(screen.getByRole("button", { name: /download/i })); | ||
|
|
||
| expect(window.open).toHaveBeenCalledWith( | ||
| "https://apps.apple.com/app/example", | ||
| "_blank", | ||
| "noopener,noreferrer", | ||
| ); | ||
| }); | ||
|
|
||
| it("blocks a javascript: store URL instead of opening it", () => { | ||
| mockConfig.iosStoreUrl = "javascript:alert('xss')"; | ||
| vi.mocked(detectMobileDevice).mockReturnValue({ | ||
| os: MobileOs.Ios, | ||
| deviceType: DeviceType.Phone, | ||
| }); | ||
|
|
||
| render(<MobileAppBanner />); | ||
| fireEvent.click(screen.getByRole("button", { name: /download/i })); | ||
|
|
||
| expect(window.open).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
131 changes: 131 additions & 0 deletions
131
apps/csm-portal/webapp/src/components/mobile-app-banner/MobileAppBanner.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,131 @@ | ||
| // 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 { | ||
| Alert, | ||
| AlertTitle, | ||
| Box, | ||
| Button, | ||
| Collapse, | ||
| IconButton, | ||
| Stack, | ||
| } from "@wso2/oxygen-ui"; | ||
| import { X } from "@wso2/oxygen-ui-icons-react"; | ||
| import { useEffect, useMemo, useState, type JSX } from "react"; | ||
| import { | ||
| getMobileAppConfig, | ||
| getMobileAppStoreUrl, | ||
| } from "@config/mobileAppConfig"; | ||
| import { MobileOs, type MobileDeviceInfo } from "@/types/mobileDevice"; | ||
| import { detectMobileDevice } from "@utils/deviceDetection"; | ||
|
|
||
| const OS_LABELS: Record<MobileOs, string> = { | ||
| [MobileOs.Ios]: "iOS", | ||
| [MobileOs.Android]: "Android", | ||
| }; | ||
|
|
||
| /** | ||
| * MobileAppBanner component. | ||
| * | ||
| * Dismissible banner nudging CS engineers on a detected mobile phone (and | ||
| * optionally tablet) browser toward the WSO2 Super App micro-app, without | ||
| * blocking access -- engineers can dismiss it and keep using the web portal | ||
| * on a phone, unlike the customer portal's full-page mobile gate. | ||
| * | ||
| * Built directly on `Alert` (not the higher-level `NotificationBanner`): | ||
| * `NotificationBanner`/MUI `Alert` only auto-renders its own close icon when | ||
| * no custom `action` node is supplied, so a banner that also needs a | ||
| * "Download" action button must pack both into `action` itself -- see | ||
| * `ErrorBanner.tsx` for the same pattern already established in this app. | ||
| * | ||
| * @returns {JSX.Element | null} The MobileAppBanner component. | ||
| */ | ||
| export default function MobileAppBanner(): JSX.Element | null { | ||
| const mobileAppConfig = useMemo(() => getMobileAppConfig(), []); | ||
| const device = useMemo<MobileDeviceInfo | null>( | ||
| () => | ||
| detectMobileDevice({ includeTablets: mobileAppConfig.includeTablets }), | ||
| [mobileAppConfig.includeTablets], | ||
| ); | ||
|
|
||
| const storeUrl = device | ||
| ? getMobileAppStoreUrl(device.os, mobileAppConfig) | ||
| : undefined; | ||
|
|
||
| const visible = mobileAppConfig.enabled && device !== null && !!storeUrl; | ||
|
|
||
| // State for the banner dismissal. | ||
| const [dismissed, setDismissed] = useState<boolean>(false); | ||
|
|
||
| // Reset the dismissed state when the visibility configuration changes to true. | ||
| useEffect(() => { | ||
| if (visible) { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect -- reset dismissal when banner is re-shown | ||
| setDismissed(false); | ||
| } | ||
| }, [visible]); | ||
|
|
||
| if (!visible || dismissed || !device || !storeUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| const osLabel = OS_LABELS[device.os]; | ||
|
|
||
| const handleDownload = (): void => { | ||
| try { | ||
| const parsed = new URL(storeUrl, window.location.origin); | ||
| // Allowlist http(s) only to block javascript:/data: URIs. | ||
| if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return; | ||
| window.open(parsed.toString(), "_blank", "noopener,noreferrer"); | ||
| } catch { | ||
| // ignore invalid URLs | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Collapse in> | ||
| <Alert | ||
| severity="info" | ||
| variant="filled" | ||
| action={ | ||
| <Stack direction="row" spacing={0.5} alignItems="center"> | ||
| <Button | ||
| color="inherit" | ||
| size="small" | ||
| onClick={handleDownload} | ||
| sx={{ fontWeight: 600, textDecoration: "underline" }} | ||
| > | ||
| Download | ||
| </Button> | ||
| <IconButton | ||
| size="small" | ||
| color="inherit" | ||
| onClick={() => setDismissed(true)} | ||
| aria-label="Close" | ||
| > | ||
| <X size={16} /> | ||
| </IconButton> | ||
| </Stack> | ||
| } | ||
| > | ||
| <AlertTitle sx={{ mb: 0 }}>Get the WSO2 Super App</AlertTitle> | ||
| <Box component="span"> | ||
| {`This portal isn't optimized for ${osLabel} browsers. CSM Portal is also available as a micro-app inside the WSO2 Super App for a better mobile experience.`} | ||
| </Box> | ||
| </Alert> | ||
| </Collapse> | ||
| ); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // 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 { MobileOs } from "@/types/mobileDevice"; | ||
|
|
||
| export interface MobileAppConfig { | ||
| enabled: boolean; | ||
| iosStoreUrl?: string; | ||
| androidStoreUrl?: string; | ||
| includeTablets: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Reads mobile-app banner settings from window.config. | ||
| * | ||
| * @returns {MobileAppConfig} Resolved mobile app configuration. | ||
| */ | ||
| export function getMobileAppConfig(): MobileAppConfig { | ||
| const config = window.config; | ||
|
|
||
| return { | ||
| enabled: config?.CSM_PORTAL_MOBILE_APP_PROMPT_ENABLED ?? false, | ||
| iosStoreUrl: config?.CSM_PORTAL_MOBILE_APP_IOS_STORE_URL, | ||
| androidStoreUrl: config?.CSM_PORTAL_MOBILE_APP_ANDROID_STORE_URL, | ||
| includeTablets: config?.CSM_PORTAL_MOBILE_APP_INCLUDE_TABLETS ?? false, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the app-store URL for the given mobile OS. | ||
| * | ||
| * @param {MobileOs} os - Target mobile operating system. | ||
| * @param {MobileAppConfig} mobileAppConfig - Mobile app configuration. | ||
| * @returns {string | undefined} Store URL when configured. | ||
| */ | ||
| export function getMobileAppStoreUrl( | ||
| os: MobileOs, | ||
| mobileAppConfig: MobileAppConfig = getMobileAppConfig(), | ||
| ): string | undefined { | ||
| return os === MobileOs.Ios | ||
| ? mobileAppConfig.iosStoreUrl | ||
| : mobileAppConfig.androidStoreUrl; | ||
| } |
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.