From 51326e52c4fd719ec053d0cc3496f0c45d5039d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dro=C5=84?= Date: Fri, 17 Mar 2023 10:38:51 +0100 Subject: [PATCH] Refactor apps UI (#3363) * Bump macaw-ui * Add grouping util * Refactor App cards UI using CSS Grid * Rename AppListCard to AppListRow * Fix unit tests * Bump macaw-ui * Remove inline styling * Fix app installtion for second pair * Add keys to grid rows * Change grid template rows to repeat(4, auto) * Replace groupIntoPairs with chunk method from lodash * Fix borders on safari * Add paddings to section names --- package-lock.json | 14 +-- package.json | 2 +- src/apps/components/AllAppList/AllAppList.tsx | 29 ++--- .../components/AppListCard/AppListCard.tsx | 70 ----------- src/apps/components/AppListCard/index.ts | 3 - .../components/AppListPage/AppListPage.tsx | 16 ++- .../AppListCardActions.tsx | 13 +- .../AppListCardDescription.tsx | 10 +- .../AppListCardIntegrations.tsx | 25 +++- .../AppListCardLinks.tsx | 10 +- .../AppListRow.test.tsx} | 94 +++++++++------ src/apps/components/AppListRow/AppListRow.tsx | 113 ++++++++++++++++++ .../{AppListCard => AppListRow}/AppLogo.tsx | 0 .../ErrorInstallAction.tsx | 0 src/apps/components/AppListRow/index.ts | 3 + .../{AppListCard => AppListRow}/messages.ts | 0 .../{AppListCard => AppListRow}/styles.ts | 0 src/apps/fixtures.ts | 6 +- 18 files changed, 254 insertions(+), 154 deletions(-) delete mode 100644 src/apps/components/AppListCard/AppListCard.tsx delete mode 100644 src/apps/components/AppListCard/index.ts rename src/apps/components/{AppListCard => AppListRow}/AppListCardActions.tsx (91%) rename src/apps/components/{AppListCard => AppListRow}/AppListCardDescription.tsx (87%) rename src/apps/components/{AppListCard => AppListRow}/AppListCardIntegrations.tsx (73%) rename src/apps/components/{AppListCard => AppListRow}/AppListCardLinks.tsx (81%) rename src/apps/components/{AppListCard/AppListCard.test.tsx => AppListRow/AppListRow.test.tsx} (68%) create mode 100644 src/apps/components/AppListRow/AppListRow.tsx rename src/apps/components/{AppListCard => AppListRow}/AppLogo.tsx (100%) rename src/apps/components/{AppListCard => AppListRow}/ErrorInstallAction.tsx (100%) create mode 100644 src/apps/components/AppListRow/index.ts rename src/apps/components/{AppListCard => AppListRow}/messages.ts (100%) rename src/apps/components/{AppListCard => AppListRow}/styles.ts (100%) diff --git a/package-lock.json b/package-lock.json index 47859894d..a0446d6f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@material-ui/lab": "^4.0.0-alpha.61", "@material-ui/styles": "^4.11.4", "@reach/auto-id": "^0.16.0", - "@saleor/macaw-ui": "^0.8.0-pre.43", + "@saleor/macaw-ui": "^0.8.0-pre.49", "@saleor/sdk": "^0.4.4", "@sentry/react": "^6.0.0", "@types/faker": "^5.1.6", @@ -7271,9 +7271,9 @@ } }, "node_modules/@saleor/macaw-ui": { - "version": "0.8.0-pre.44", - "resolved": "https://registry.npmjs.org/@saleor/macaw-ui/-/macaw-ui-0.8.0-pre.44.tgz", - "integrity": "sha512-iSygNhSfMxJrmnbXKKmE/iKc7dMq/m996Hqfl5ZFcZ6KpurmI0940AjJcYDMnDXUl+Md6OJyRxv7PKKy8nU+Mg==", + "version": "0.8.0-pre.49", + "resolved": "https://registry.npmjs.org/@saleor/macaw-ui/-/macaw-ui-0.8.0-pre.49.tgz", + "integrity": "sha512-SHUfBE1AaDsam/K3ZcotDtUH6/jcyRR9Gi/Zpvw/cTcwoosq09WcewMWZNdHgY5Fkbgve7HTKb+wCyah+sBO8w==", "dependencies": { "@floating-ui/react-dom-interactions": "^0.5.0", "@radix-ui/react-radio-group": "^1.1.1", @@ -41431,9 +41431,9 @@ } }, "@saleor/macaw-ui": { - "version": "0.8.0-pre.44", - "resolved": "https://registry.npmjs.org/@saleor/macaw-ui/-/macaw-ui-0.8.0-pre.44.tgz", - "integrity": "sha512-iSygNhSfMxJrmnbXKKmE/iKc7dMq/m996Hqfl5ZFcZ6KpurmI0940AjJcYDMnDXUl+Md6OJyRxv7PKKy8nU+Mg==", + "version": "0.8.0-pre.49", + "resolved": "https://registry.npmjs.org/@saleor/macaw-ui/-/macaw-ui-0.8.0-pre.49.tgz", + "integrity": "sha512-SHUfBE1AaDsam/K3ZcotDtUH6/jcyRR9Gi/Zpvw/cTcwoosq09WcewMWZNdHgY5Fkbgve7HTKb+wCyah+sBO8w==", "requires": { "@floating-ui/react-dom-interactions": "^0.5.0", "@radix-ui/react-radio-group": "^1.1.1", diff --git a/package.json b/package.json index 0b825ce71..92c67698b 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@material-ui/lab": "^4.0.0-alpha.61", "@material-ui/styles": "^4.11.4", "@reach/auto-id": "^0.16.0", - "@saleor/macaw-ui": "^0.8.0-pre.43", + "@saleor/macaw-ui": "^0.8.0-pre.49", "@saleor/sdk": "^0.4.4", "@sentry/react": "^6.0.0", "@types/faker": "^5.1.6", diff --git a/src/apps/components/AllAppList/AllAppList.tsx b/src/apps/components/AllAppList/AllAppList.tsx index 5efed94b9..cbf7fcaf6 100644 --- a/src/apps/components/AllAppList/AllAppList.tsx +++ b/src/apps/components/AllAppList/AllAppList.tsx @@ -1,11 +1,11 @@ import { GetV2SaleorAppsResponse } from "@dashboard/apps/marketplace.types"; -import { resolveInstallationOfMarketplaceApp } from "@dashboard/apps/utils"; import { AppInstallationFragment } from "@dashboard/graphql"; import { Skeleton } from "@material-ui/lab"; import { Box } from "@saleor/macaw-ui/next"; +import chunk from "lodash/chunk"; import React from "react"; -import AppListCard from "../AppListCard"; +import AppListRow from "../AppListRow"; interface AllAppListProps { appList?: GetV2SaleorAppsResponse.SaleorApp[]; @@ -20,28 +20,19 @@ const AllAppList: React.FC = ({ navigateToAppInstallPage, navigateToGithubForkPage, }) => { + const appsPairs = React.useMemo(() => chunk(appList, 2), [appList]); + if (!appList) { return ; } return ( - - {appList.map(app => ( - + {appsPairs.map(appPair => ( + diff --git a/src/apps/components/AppListCard/AppListCard.tsx b/src/apps/components/AppListCard/AppListCard.tsx deleted file mode 100644 index 4b3f80638..000000000 --- a/src/apps/components/AppListCard/AppListCard.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import { useAppListContext } from "@dashboard/apps/context"; -import { GetV2SaleorAppsResponse } from "@dashboard/apps/marketplace.types"; -import { getAppDetails } from "@dashboard/apps/utils"; -import { AppInstallationFragment } from "@dashboard/graphql"; -import { Box } from "@saleor/macaw-ui/next"; -import React from "react"; -import { useIntl } from "react-intl"; - -import AppListCardActions from "./AppListCardActions"; -import AppListCardDescription from "./AppListCardDescription"; -import AppListCardIntegrations from "./AppListCardIntegrations"; -import AppListCardLinks from "./AppListCardLinks"; - -interface AppListCardProps { - app: GetV2SaleorAppsResponse.SaleorApp; - appInstallation?: AppInstallationFragment; - navigateToAppInstallPage?: (manifestUrl: string) => void; - navigateToGithubForkPage?: (githubForkUrl: string) => void; -} - -const AppListCard: React.FC = ({ - app, - appInstallation, - navigateToAppInstallPage, - navigateToGithubForkPage, -}) => { - const intl = useIntl(); - const { retryAppInstallation, removeAppInstallation } = useAppListContext(); - - const details = getAppDetails({ - intl, - app, - appInstallation, - navigateToAppInstallPage, - navigateToGithubForkPage, - retryAppInstallation, - removeAppInstallation, - }); - - return ( - - - - - - - - - - - ); -}; -AppListCard.displayName = "AppListCard"; -export default AppListCard; diff --git a/src/apps/components/AppListCard/index.ts b/src/apps/components/AppListCard/index.ts deleted file mode 100644 index 9e1a6429b..000000000 --- a/src/apps/components/AppListCard/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./AppListCard"; -export { default } from "./AppListCard"; -export * from "./AppLogo"; diff --git a/src/apps/components/AppListPage/AppListPage.tsx b/src/apps/components/AppListPage/AppListPage.tsx index 32e785189..c810ba865 100644 --- a/src/apps/components/AppListPage/AppListPage.tsx +++ b/src/apps/components/AppListPage/AppListPage.tsx @@ -3,7 +3,7 @@ import { TopNav } from "@dashboard/components/AppLayout/TopNav"; import useNavigator from "@dashboard/hooks/useNavigator"; import { sectionNames } from "@dashboard/intl"; import { ListProps } from "@dashboard/types"; -import { Box, Text } from "@saleor/macaw-ui/next"; +import { Box, sprinkles, Text } from "@saleor/macaw-ui/next"; import React, { useCallback } from "react"; import { FormattedMessage, useIntl } from "react-intl"; @@ -114,7 +114,12 @@ export const AppListPage: React.FC = props => { {sectionsAvailability.all && !marketplaceError && ( - + = props => { )} {sectionsAvailability.comingSoon && !marketplaceError && ( - + {intl.formatMessage(messages.comingSoonApps)} = ({ } return ( - + {githubForkHandler && (