From 44a8a1c182126c643cf743f555dee4d06157dc45 Mon Sep 17 00:00:00 2001 From: Wojciech Mista Date: Tue, 1 Feb 2022 14:28:30 +0100 Subject: [PATCH] Shipping zones button fix (#1804) * update tests * wip * Post-rebase fix * Revert "wip" This reverts commit 225276edb5c0730ab0cefba0f98a663d6e4fb37a. * Post-rebase fixes * Update tests, messages and stories * Fixes * Update messages * Update tests and messages --- locale/defaultMessages.json | 8 ++- .../ShippingZonesCard.stories.tsx | 3 +- .../ShippingZonesCard/ShippingZonesCard.tsx | 32 +++++++++- .../ShippingZonesListHeader.tsx | 9 ++- .../ChannelDetailsPage.stories.tsx | 3 +- .../__snapshots__/Stories.test.ts.snap | 59 ++++++------------- 6 files changed, 63 insertions(+), 51 deletions(-) diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index daba7e90e..2f6714e25 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -1584,13 +1584,17 @@ "context": "add shipping zone title", "string": "Add Shipping Zones" }, + "src_dot_channels_dot_components_dot_ShippingZonesCard_dot_allSelectedMessage": { + "context": "all selected zones card message", + "string": "All available shipping zones have been selected" + }, "src_dot_channels_dot_components_dot_ShippingZonesCard_dot_subtitle": { "context": "card subtitle", - "string": "Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels." + "string": "Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels." }, "src_dot_channels_dot_components_dot_ShippingZonesCard_dot_title": { "context": "title", - "string": "{zonesCount} Shipping Zones" + "string": "{zonesCount} / {totalCount} shipping zones" }, "src_dot_channels_dot_pages_dot_ChannelsListPage_dot_2754800034": { "context": "alert", diff --git a/src/channels/components/ShippingZonesCard/ShippingZonesCard.stories.tsx b/src/channels/components/ShippingZonesCard/ShippingZonesCard.stories.tsx index b4c3f488e..ce9d99367 100644 --- a/src/channels/components/ShippingZonesCard/ShippingZonesCard.stories.tsx +++ b/src/channels/components/ShippingZonesCard/ShippingZonesCard.stories.tsx @@ -25,7 +25,8 @@ const baseProps = { fetchMoreShippingZones: { loading: false, hasMore: false, - onFetchMore: () => undefined + onFetchMore: () => undefined, + totalCount: 0 }, shippingZones: [], shippingZonesChoices: shippingZones as ChannelShippingZones diff --git a/src/channels/components/ShippingZonesCard/ShippingZonesCard.tsx b/src/channels/components/ShippingZonesCard/ShippingZonesCard.tsx index 8967468ba..836be74b5 100644 --- a/src/channels/components/ShippingZonesCard/ShippingZonesCard.tsx +++ b/src/channels/components/ShippingZonesCard/ShippingZonesCard.tsx @@ -3,6 +3,7 @@ import { Card, CardContent, Divider, + makeStyles, Typography } from "@material-ui/core"; import CardTitle from "@saleor/components/CardTitle"; @@ -22,11 +23,24 @@ const messages = defineMessages({ }, subtitle: { defaultMessage: - "Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels.", + "Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.", description: "card subtitle" + }, + allSelectedMessage: { + defaultMessage: "All available shipping zones have been selected", + description: "all selected zones card message" } }); +const useStyles = makeStyles( + theme => ({ + infoMessage: { + padding: theme.spacing(3) + } + }), + { name: "ShippingZonesCard" } +); + type ShippingZonesCardProps = ShippingZonesProps; const ShippingZonesCard: React.FC = props => { @@ -37,6 +51,7 @@ const ShippingZonesCard: React.FC = props => { } = props; const expanderClasses = useExpanderStyles({}); + const classes = useStyles(); const intl = useIntl(); const hasMoreZonesToBeSelected = totalCount !== shippingZones.length; @@ -48,14 +63,25 @@ const ShippingZonesCard: React.FC = props => { {intl.formatMessage(messages.subtitle)} - + {shippingZones.map(zone => ( ))} {hasMoreZonesToBeSelected ? ( - ) : null} + ) : ( + + {intl.formatMessage(messages.allSelectedMessage)} + + )} ); diff --git a/src/channels/components/ShippingZonesCard/ShippingZonesListHeader.tsx b/src/channels/components/ShippingZonesCard/ShippingZonesListHeader.tsx index a75fbfa89..59a811124 100644 --- a/src/channels/components/ShippingZonesCard/ShippingZonesListHeader.tsx +++ b/src/channels/components/ShippingZonesCard/ShippingZonesListHeader.tsx @@ -41,17 +41,19 @@ const useStyles = makeStyles( const messages = defineMessages({ title: { - defaultMessage: "{zonesCount} Shipping Zones", + defaultMessage: "{zonesCount} / {totalCount} shipping zones", description: "title" } }); interface ShippingZonesListHeaderProps { shippingZones: ChannelShippingZones; + totalCount: number; } const ShippingZonesListHeader: React.FC = ({ - shippingZones + shippingZones, + totalCount }) => { const classes = useStyles({}); const intl = useIntl(); @@ -61,7 +63,8 @@ const ShippingZonesListHeader: React.FC = ({ } classes={classes}> {intl.formatMessage(messages.title, { - zonesCount: shippingZones.length + zonesCount: shippingZones.length, + totalCount })} diff --git a/src/channels/pages/ChannelDetailsPage/ChannelDetailsPage.stories.tsx b/src/channels/pages/ChannelDetailsPage/ChannelDetailsPage.stories.tsx index d401781b1..02db72c4d 100644 --- a/src/channels/pages/ChannelDetailsPage/ChannelDetailsPage.stories.tsx +++ b/src/channels/pages/ChannelDetailsPage/ChannelDetailsPage.stories.tsx @@ -43,7 +43,8 @@ const props: ChannelDetailsPageProps = { fetchMoreShippingZones: { loading: false, hasMore: false, - onFetchMore: () => undefined + onFetchMore: () => undefined, + totalCount: 0 } }; diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index c87a2aba5..ccc598531 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -23138,7 +23138,7 @@ exports[`Storyshots Shipping zones card with no options selected 1`] = `
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 0 Shipping Zones + 0 / 0 shipping zones
- - Add Shipping Zones - - + All available shipping zones have been selected
@@ -23272,7 +23249,7 @@ exports[`Storyshots Shipping zones card with options selected 1`] = `
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones
- Select Shipping Zones that will be supplied via this channel. You can assign Shipping Zones to multiple channels. + Select shipping zones that will be supplied via this channel. You can assign shipping zones to multiple channels.
- 2 Shipping Zones + 2 / 0 shipping zones