diff --git a/ts/components/SectionStatus/StatusContent.tsx b/ts/components/SectionStatus/StatusContent.tsx index 9c215701cd5..cdf2963cffe 100644 --- a/ts/components/SectionStatus/StatusContent.tsx +++ b/ts/components/SectionStatus/StatusContent.tsx @@ -8,6 +8,7 @@ import { } from "@pagopa/io-app-design-system"; import { WithTestID } from "../../types/WithTestID"; import { Label } from "../core/typography/Label"; +import { LevelEnum } from "../../../definitions/content/SectionStatus"; const iconSize = 24; @@ -38,6 +39,24 @@ type Props = WithTestID<{ labelPaddingVertical?: number; }>; +export const statusColorMap: Record = { + [LevelEnum.normal]: "aqua", + [LevelEnum.critical]: "red", + [LevelEnum.warning]: "orange" +}; + +export const statusIconMap: Record = { + [LevelEnum.normal]: "ok", + [LevelEnum.critical]: "notice", + [LevelEnum.warning]: "info" +}; + +// map the text background color with the relative text color +export const getStatusTextColor = ( + level: LevelEnum +): "bluegreyDark" | "white" => + level === LevelEnum.normal ? "bluegreyDark" : "white"; + const StatusContent = forwardRef>( ( { diff --git a/ts/components/SectionStatus/__tests__/SectionStatusComponent.test.tsx b/ts/components/SectionStatus/__tests__/SectionStatusComponent.test.tsx index bbd2ba6ae1d..24f1a353b33 100644 --- a/ts/components/SectionStatus/__tests__/SectionStatusComponent.test.tsx +++ b/ts/components/SectionStatus/__tests__/SectionStatusComponent.test.tsx @@ -68,21 +68,22 @@ describe("SectionStatusComponent", () => { }); [ - [LevelEnum.normal, IOColors.aqua], - [LevelEnum.warning, IOColors.orange], - [LevelEnum.critical, IOColors.red] + [LevelEnum.normal, IOColors["info-100"]], + [LevelEnum.warning, IOColors["warning-100"]], + [LevelEnum.critical, IOColors["error-100"]] ].forEach(([level, color]) => { describe(`given the level ${level}`, () => { const store = mockStore( mockSectionStatusState("messages", { ...sectionStatus, + web_url: undefined, level: level as LevelEnum }) ); it(`should apply background color ${color} to the status content`, () => { const component = getComponent("messages", store); - const view = component.getByTestId("SectionStatusContent"); + const view = component.getByTestId("SectionStatusComponentContent"); expect(view).toHaveStyle({ backgroundColor: color }); }); }); @@ -101,15 +102,7 @@ describe("SectionStatusComponent", () => { const component = getComponent("messages"); const view = component.getByTestId("SectionStatusComponentPressable"); expect(view.props.accessible).toBe(true); - expect(view.props.accessibilityLabel).toMatch( - `${sectionStatus.message["it-IT"]}, ${I18n.t( - "global.sectionStatus.moreInfo" - )}` - ); - expect(view.props.accessibilityHint).toMatch( - I18n.t("global.accessibility.linkHint") - ); - expect(view.props.accessibilityRole).toBe("link"); + expect(view.props.accessibilityRole).toBe("button"); }); it("should render the touchable wrapper which opens the correct url", () => { @@ -135,14 +128,9 @@ describe("SectionStatusComponent", () => { it("should set the correct a11y properties to the status content", () => { setLocale("it"); const component = getComponent("messages", store); - const view = component.getByTestId("SectionStatusContent"); - expect(view.props.accessible).toBe(true); - expect(view.props.accessibilityRole).toBeUndefined(); - expect(view.props.accessibilityLabel).toMatch( - `${sectionStatus.message["it-IT"]}, ${I18n.t( - "global.accessibility.alert" - )}` - ); + const view = component.getByTestId("SectionStatusComponentContent"); + expect(view.props.accessible).toBe(false); + expect(view.props.accessibilityRole).toBe("alert"); }); it("should display the accessibility alert text", () => { diff --git a/ts/components/SectionStatus/index.tsx b/ts/components/SectionStatus/index.tsx index 7a274ed3efa..33252078a54 100644 --- a/ts/components/SectionStatus/index.tsx +++ b/ts/components/SectionStatus/index.tsx @@ -2,10 +2,10 @@ import { useNavigation } from "@react-navigation/native"; import { pipe } from "fp-ts/lib/function"; import * as O from "fp-ts/lib/Option"; import _ from "lodash"; -import React, { useCallback } from "react"; -import { Pressable, View } from "react-native"; +import React, { ComponentProps, useCallback } from "react"; +import { View } from "react-native"; import { connect } from "react-redux"; -import type { IOColors, IOIcons } from "@pagopa/io-app-design-system"; +import { Alert } from "@pagopa/io-app-design-system"; import { LevelEnum } from "../../../definitions/content/SectionStatus"; import I18n from "../../i18n"; import { @@ -16,8 +16,6 @@ import { GlobalState } from "../../store/reducers/types"; import { getFullLocale } from "../../utils/locale"; import { maybeNotNullyString } from "../../utils/strings"; import { openWebUrl } from "../../utils/url"; -import { Link } from "../core/typography/Link"; -import StatusContent from "./StatusContent"; type OwnProps = { sectionKey: SectionStatusKey; @@ -26,24 +24,15 @@ type OwnProps = { type Props = OwnProps & ReturnType; -export const statusColorMap: Record = { - [LevelEnum.normal]: "aqua", - [LevelEnum.critical]: "red", - [LevelEnum.warning]: "orange" +export const statusVariantMap: Record< + LevelEnum, + ComponentProps["variant"] +> = { + [LevelEnum.normal]: "info", + [LevelEnum.critical]: "error", + [LevelEnum.warning]: "warning" }; -export const statusIconMap: Record = { - [LevelEnum.normal]: "ok", - [LevelEnum.critical]: "notice", - [LevelEnum.warning]: "info" -}; - -// map the text background color with the relative text color -export const getStatusTextColor = ( - level: LevelEnum -): "bluegreyDark" | "white" => - level === LevelEnum.normal ? "bluegreyDark" : "white"; - export const InnerSectionStatus = ( props: Omit & { sectionStatus: NonNullable; @@ -51,16 +40,12 @@ export const InnerSectionStatus = ( ) => { const viewRef = React.createRef(); const { sectionStatus, onSectionRef } = props; - const iconName = statusIconMap[sectionStatus.level]; - const backgroundColor = statusColorMap[sectionStatus.level]; const locale = getFullLocale(); const maybeWebUrl = maybeNotNullyString( sectionStatus.web_url && sectionStatus.web_url[locale] ); const navigation = useNavigation(); - const color = getStatusTextColor(sectionStatus.level); - const handleOnSectionRef = useCallback(() => { if (viewRef.current) { onSectionRef?.(viewRef); @@ -78,49 +63,25 @@ export const InnerSectionStatus = ( O.fold( () => ( // render text only - - {`${sectionStatus.message[locale]} `} - + fullWidth + content={`${sectionStatus.message[locale]}`} + variant={statusVariantMap[sectionStatus.level]} + viewRef={viewRef} + /> ), - - // render a pressable element with the link webUrl => ( - openWebUrl(webUrl)} + // render a pressable element with the link + - - {`${sectionStatus.message[locale]} `} - - {I18n.t("global.sectionStatus.moreInfo")} - - - + fullWidth + content={`${sectionStatus.message[locale]} `} + variant={statusVariantMap[sectionStatus.level]} + action={I18n.t("global.sectionStatus.moreInfo")} + onPress={() => openWebUrl(webUrl)} + viewRef={viewRef} + /> ) ) ); diff --git a/ts/features/design-system/core/DSLegacyAlert.tsx b/ts/features/design-system/core/DSLegacyAlert.tsx index 509a367d6ba..03a49f1daa8 100644 --- a/ts/features/design-system/core/DSLegacyAlert.tsx +++ b/ts/features/design-system/core/DSLegacyAlert.tsx @@ -1,11 +1,10 @@ import { VSpacer } from "@pagopa/io-app-design-system"; import * as React from "react"; -import SectionStatusComponent, { - getStatusTextColor, +import StatusContent, { statusColorMap, + getStatusTextColor, statusIconMap -} from "../../../components/SectionStatus"; -import StatusContent from "../../../components/SectionStatus/StatusContent"; +} from "../../../components/SectionStatus/StatusContent"; import { DSFullWidthComponent } from "../components/DSFullWidthComponent"; /* Types */ @@ -28,10 +27,6 @@ export const DSLegacyAlert = () => ( - - - -