diff --git a/src/components/Link.tsx b/src/components/Link.tsx index 5215595ad..bb77b0fea 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -3,6 +3,7 @@ import { TypographyProps } from "@material-ui/core/Typography"; import { makeStyles } from "@saleor/macaw-ui"; import classNames from "classnames"; import React from "react"; +import { Link as RouterLink } from "react-router-dom"; const useStyles = makeStyles( theme => ({ @@ -19,6 +20,9 @@ const useStyles = makeStyles( underline: { textDecoration: "underline" }, + noUnderline: { + textDecoration: "none" + }, disabled: { cursor: "default", color: theme.palette.textHighlighted.inactive @@ -27,11 +31,14 @@ const useStyles = makeStyles( { name: "Link" } ); +const isExternalURL = url => /^https?:\/\//.test(url); + interface LinkProps extends React.AnchorHTMLAttributes { + href?: string; color?: "primary" | "secondary"; underline?: boolean; typographyProps?: TypographyProps; - onClick: () => void; + onClick?: () => void; disabled?: boolean; } @@ -43,32 +50,47 @@ const Link: React.FC = props => { underline = false, onClick, disabled, + href, ...linkProps } = props; const classes = useStyles(props); - return ( - { - if (disabled) { - return; - } + const commonLinkProps = { + className: classNames(className, { + [classes.root]: true, + [classes[color]]: true, + [classes.underline]: underline, + [classes.noUnderline]: !underline, + [classes.disabled]: disabled + }), + onClick: event => { + if (disabled || !onClick) { + return; + } - event.preventDefault(); - onClick(); - }} - {...linkProps} - > - {children} - + event.preventDefault(); + onClick(); + }, + ...linkProps + }; + + return ( + <> + {!!href && !isExternalURL(href) ? ( + + {children} + + ) : ( + + {children} + + )} + ); }; Link.displayName = "Link"; diff --git a/src/config.ts b/src/config.ts index 05cf7f0ad..b5c15a0ce 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ import packageInfo from "../package.json"; import { SearchVariables } from "./hooks/makeSearch"; import { ListSettings, ListViews, Pagination } from "./types"; -export const APP_MOUNT_URI = process.env.APP_MOUNT_URI; +export const APP_MOUNT_URI = process.env.APP_MOUNT_URI || "/"; export const APP_DEFAULT_URI = "/"; export const API_URI = process.env.API_URI; export const SW_INTERVAL = parseInt(process.env.SW_INTERVAL, 0); diff --git a/src/products/components/ProductOrganization/ProductOrganization.tsx b/src/products/components/ProductOrganization/ProductOrganization.tsx index 9180c3d30..2548fa699 100644 --- a/src/products/components/ProductOrganization/ProductOrganization.tsx +++ b/src/products/components/ProductOrganization/ProductOrganization.tsx @@ -3,6 +3,7 @@ import CardSpacer from "@saleor/components/CardSpacer"; import CardTitle from "@saleor/components/CardTitle"; import { FormSpacer } from "@saleor/components/FormSpacer"; import Hr from "@saleor/components/Hr"; +import Link from "@saleor/components/Link"; import MultiAutocompleteSelectField, { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField"; @@ -12,7 +13,8 @@ import SingleAutocompleteSelectField, { import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; import { ChangeEvent } from "@saleor/hooks/useForm"; import { makeStyles } from "@saleor/macaw-ui"; -import { maybe } from "@saleor/misc"; +import { createHref, maybe } from "@saleor/misc"; +import { productTypeUrl } from "@saleor/productTypes/urls"; import { FetchMoreProps } from "@saleor/types"; import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors"; import React from "react"; @@ -130,7 +132,12 @@ const ProductOrganization: React.FC = props => { - {maybe(() => productType.name, "...")} + + {productType?.name ?? "..."} + diff --git a/src/products/components/ProductUpdatePage/ProductUpdatePage.test.tsx b/src/products/components/ProductUpdatePage/ProductUpdatePage.test.tsx index f6264e1f1..b14b74dd8 100644 --- a/src/products/components/ProductUpdatePage/ProductUpdatePage.test.tsx +++ b/src/products/components/ProductUpdatePage/ProductUpdatePage.test.tsx @@ -15,10 +15,14 @@ import ProductUpdatePage, { ProductUpdatePageProps } from "./ProductUpdatePage"; const product = productFixture(placeholderImage); const channels = createChannelsData(channelsList); +import * as _useNavigator from "@saleor/hooks/useNavigator"; import Adapter from "enzyme-adapter-react-16"; +import { MemoryRouter } from "react-router-dom"; + configure({ adapter: new Adapter() }); const onSubmit = jest.fn(); +const useNavigator = jest.spyOn(_useNavigator, "default"); const props: ProductUpdatePageProps = { ...listActionsProps, @@ -81,11 +85,14 @@ const selectors = { }; describe("Product details page", () => { + useNavigator.mockImplementation(); it("can select empty option on attribute", () => { const component = mount( - - - + + + + + ); expect(component.find(selectors.dropdown).exists()).toBeFalsy(); diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index e3a5a2e67..aae46639c 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -8805,7 +8805,7 @@ exports[`Storyshots Generics / Link with choices default 1`] = ` tabindex="0" > Ă…land Islands Jane Doe @@ -22951,7 +22951,7 @@ exports[`Storyshots Shipping zones card with no options selected 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -23169,7 +23169,7 @@ exports[`Storyshots Shipping zones card with options selected 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -45722,7 +45722,7 @@ exports[`Storyshots Views / Channels / Channel details default 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -46257,7 +46257,7 @@ exports[`Storyshots Views / Channels / Channel details disabled 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -46788,7 +46788,7 @@ exports[`Storyshots Views / Channels / Channel details loading 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -47319,7 +47319,7 @@ exports[`Storyshots Views / Channels / Channel details with data 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -47856,7 +47856,7 @@ exports[`Storyshots Views / Channels / Channel details with errors 1`] = ` class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -48338,7 +48338,7 @@ exports[`Storyshots Views / Channels / Channel details without editable currency class="CardAddItemsFooter-container-id" > Add Shipping Zones @@ -111673,7 +111673,7 @@ exports[`Storyshots Views / Orders / Order details cancelled 1`] = ` Products were refunded by Jane Doe @@ -113787,7 +113787,7 @@ exports[`Storyshots Views / Orders / Order details default 1`] = ` Products were refunded by Jane Doe @@ -115933,7 +115933,7 @@ exports[`Storyshots Views / Orders / Order details fulfilled 1`] = ` Products were refunded by Jane Doe @@ -118675,7 +118675,7 @@ exports[`Storyshots Views / Orders / Order details no customer note 1`] = ` Products were refunded by Jane Doe @@ -120819,7 +120819,7 @@ exports[`Storyshots Views / Orders / Order details no payment 1`] = ` Products were refunded by Jane Doe @@ -122965,7 +122965,7 @@ exports[`Storyshots Views / Orders / Order details no shipping address 1`] = ` Products were refunded by Jane Doe @@ -125103,7 +125103,7 @@ exports[`Storyshots Views / Orders / Order details partially fulfilled 1`] = ` Products were refunded by Jane Doe @@ -127249,7 +127249,7 @@ exports[`Storyshots Views / Orders / Order details payment confirmed 1`] = ` Products were refunded by Jane Doe @@ -129395,7 +129395,7 @@ exports[`Storyshots Views / Orders / Order details payment error 1`] = ` Products were refunded by Jane Doe @@ -131541,7 +131541,7 @@ exports[`Storyshots Views / Orders / Order details pending payment 1`] = ` Products were refunded by Jane Doe @@ -133687,7 +133687,7 @@ exports[`Storyshots Views / Orders / Order details refunded payment 1`] = ` Products were refunded by Jane Doe @@ -135833,7 +135833,7 @@ exports[`Storyshots Views / Orders / Order details rejected payment 1`] = ` Products were refunded by Jane Doe @@ -137979,7 +137979,7 @@ exports[`Storyshots Views / Orders / Order details unfulfilled 1`] = ` Products were refunded by Jane Doe @@ -138673,7 +138673,7 @@ exports[`Storyshots Views / Orders / Order draft default 1`] = ` class="MuiTableCell-root-id MuiTableCell-body-id OrderDraftDetailsProducts-colPrice-id" >
Add Discount @@ -139779,7 +139779,7 @@ exports[`Storyshots Views / Orders / Order draft no user permissions 1`] = ` class="MuiTableCell-root-id MuiTableCell-body-id OrderDraftDetailsProducts-colPrice-id" >
Add Discount @@ -185959,7 +185959,7 @@ exports[`Storyshots Views / Products / Create product variant no warehouses 1`] > There are no warehouses set up for your store. To add stock quantity to the variant please configure a warehouse @@ -188685,7 +188685,7 @@ exports[`Storyshots Views / Products / Product edit form errors 1`] = ` tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -190474,7 +190475,7 @@ exports[`Storyshots Views / Products / Product edit limits reached 1`] = ` tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -192180,7 +192182,7 @@ exports[`Storyshots Views / Products / Product edit no limits 1`] = ` tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -193628,7 +193631,7 @@ exports[`Storyshots Views / Products / Product edit no product attributes 1`] = tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -195896,11 +195900,12 @@ exports[`Storyshots Views / Products / Product edit no stock and no variants 1`] > Product Type
-
Versatile -
+
@@ -197476,11 +197481,12 @@ exports[`Storyshots Views / Products / Product edit no stock, no variants and no > Product Type
-
Versatile -
+
@@ -199056,11 +199062,12 @@ exports[`Storyshots Views / Products / Product edit no variants 1`] = ` > Product Type
-
Versatile -
+
@@ -200074,7 +200081,7 @@ exports[`Storyshots Views / Products / Product edit when data is fully loaded 1` tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -201885,11 +201893,12 @@ exports[`Storyshots Views / Products / Product edit when loading data 1`] = ` > Product Type
-
... -
+
@@ -202760,7 +202769,7 @@ exports[`Storyshots Views / Products / Product edit when product has no images 1 tabindex="0" > All Warehouses Product Type
-
Versatile -
+
@@ -205028,11 +205038,12 @@ exports[`Storyshots Views / Products / Product edit when product has no variants > Product Type
-
Versatile -
+
@@ -206046,7 +206057,7 @@ exports[`Storyshots Views / Products / Product edit with channels 1`] = ` tabindex="0" > All Warehouses Product Type
-
Versatile -
+