Skip to content

Commit

Permalink
Merge branch 'master' into IOPAE-1100-1282-1285
Browse files Browse the repository at this point in the history
  • Loading branch information
adelloste committed Jul 8, 2024
2 parents 5641cc1 + 153b621 commit 6d957fa
Show file tree
Hide file tree
Showing 54 changed files with 11,822 additions and 432 deletions.
42 changes: 0 additions & 42 deletions ts/boot/__tests__/__snapshots__/persistedStore.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,6 @@ Object {
"calendarEvents": Object {
"byMessageId": Object {},
},
"messages": Object {
"allPaginated": Object {
"archive": Object {
"data": Object {
"kind": "PotNone",
},
"lastRequest": Object {
"_tag": "None",
},
},
"inbox": Object {
"data": Object {
"kind": "PotNone",
},
"lastRequest": Object {
"_tag": "None",
},
},
"migration": Object {
"_tag": "None",
},
"shownCategory": "INBOX",
},
"detailsById": Object {},
"downloads": Object {},
"messageGetStatus": Object {
"status": "idle",
},
"messagePrecondition": Object {
"content": Object {
"kind": "undefined",
},
"messageId": Object {
"_tag": "None",
},
},
"paginatedById": Object {},
"payments": Object {
"userSelectedPayments": Set {},
},
"thirdPartyById": Object {},
},
"messagesStatus": Object {},
"organizations": Object {
"all": Array [],
Expand Down
4 changes: 3 additions & 1 deletion ts/boot/__tests__/persistedStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash";
import { applicationChangeState } from "../../store/actions/application";
import { appReducer } from "../../store/reducers";
import { GlobalState } from "../../store/reducers/types";
Expand Down Expand Up @@ -43,7 +44,8 @@ describe("Check the addition for new fields to the persisted store. If one of th
expect(globalState.crossSessions).toMatchSnapshot();
});
it("Freeze 'entities' state", () => {
expect(globalState.entities).toMatchSnapshot();
const entitiesWithoutMessages = _.omit(globalState.entities, "messages");
expect(entitiesWithoutMessages).toMatchSnapshot();
});
it("Freeze 'authentication' state", () => {
expect(globalState.authentication).toMatchSnapshot();
Expand Down
19 changes: 19 additions & 0 deletions ts/components/SectionStatus/StatusContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,6 +39,24 @@ type Props = WithTestID<{
labelPaddingVertical?: number;
}>;

export const statusColorMap: Record<LevelEnum, IOColors> = {
[LevelEnum.normal]: "aqua",
[LevelEnum.critical]: "red",
[LevelEnum.warning]: "orange"
};

export const statusIconMap: Record<LevelEnum, IOIcons> = {
[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<View, React.PropsWithChildren<Props>>(
(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand Down
89 changes: 25 additions & 64 deletions ts/components/SectionStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -26,41 +24,28 @@ type OwnProps = {

type Props = OwnProps & ReturnType<typeof mapStateToProps>;

export const statusColorMap: Record<LevelEnum, IOColors> = {
[LevelEnum.normal]: "aqua",
[LevelEnum.critical]: "red",
[LevelEnum.warning]: "orange"
export const statusVariantMap: Record<
LevelEnum,
ComponentProps<typeof Alert>["variant"]
> = {
[LevelEnum.normal]: "info",
[LevelEnum.critical]: "error",
[LevelEnum.warning]: "warning"
};

export const statusIconMap: Record<LevelEnum, IOIcons> = {
[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<Props, "sectionStatus"> & {
sectionStatus: NonNullable<Props["sectionStatus"]>;
}
) => {
const viewRef = React.createRef<View>();
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);
Expand All @@ -78,49 +63,25 @@ export const InnerSectionStatus = (
O.fold(
() => (
// render text only
<StatusContent
accessibilityLabel={`${sectionStatus.message[locale]}, ${I18n.t(
"global.accessibility.alert"
)}`}
backgroundColor={backgroundColor}
iconName={iconName}
<Alert
testID={"SectionStatusComponentContent"}
ref={viewRef}
foregroundColor={color}
>
{`${sectionStatus.message[locale]} `}
</StatusContent>
fullWidth
content={`${sectionStatus.message[locale]}`}
variant={statusVariantMap[sectionStatus.level]}
viewRef={viewRef}
/>
),

// render a pressable element with the link
webUrl => (
<Pressable
accessibilityHint={I18n.t("global.accessibility.linkHint")}
accessibilityLabel={`${sectionStatus.message[locale]}, ${I18n.t(
"global.sectionStatus.moreInfo"
)}`}
accessibilityRole={"link"}
onPress={() => openWebUrl(webUrl)}
// render a pressable element with the link
<Alert
testID={"SectionStatusComponentPressable"}
>
<StatusContent
// disable accessibility to prevent the override of the container
accessible={false}
backgroundColor={backgroundColor}
iconName={iconName}
ref={viewRef}
foregroundColor={color}
>
{`${sectionStatus.message[locale]} `}
<Link
testID={"SectionStatusComponentMoreInfo"}
color={backgroundColor === "aqua" ? "bluegreyDark" : "white"}
weight={"Bold"}
>
{I18n.t("global.sectionStatus.moreInfo")}
</Link>
</StatusContent>
</Pressable>
fullWidth
content={`${sectionStatus.message[locale]} `}
variant={statusVariantMap[sectionStatus.level]}
action={I18n.t("global.sectionStatus.moreInfo")}
onPress={() => openWebUrl(webUrl)}
viewRef={viewRef}
/>
)
)
);
Expand Down
11 changes: 3 additions & 8 deletions ts/features/design-system/core/DSLegacyAlert.tsx
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -28,10 +27,6 @@ export const DSLegacyAlert = () => (
</StatusContent>
</DSFullWidthComponent>
<VSpacer size={16} />
<DSFullWidthComponent>
<SectionStatusComponent sectionKey={"favourite_language"} />
</DSFullWidthComponent>
<VSpacer size={16} />
<DSFullWidthComponent>
<StatusContent
accessibilityLabel={`Accessibility text for the advice component`}
Expand Down
Loading

0 comments on commit 6d957fa

Please sign in to comment.