Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve Tab component
dominik-zeglen92bda82d963a
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsxindex 9ac10c51cf..845dd879f3 100644--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx@@ -1,4 +1,3 @@-import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";import * as React from "react";import { CardSpacer } from "../../../components/CardSpacer";@@ -9,6 +8,7 @@ import PageHeader from "../../../components/PageHeader";import SaveButtonBar from "../../../components/SaveButtonBar/SaveButtonBar";import SeoForm from "../../../components/SeoForm";import { Tab } from "../../../components/Tab";+import TabContainer from "../../../components/Tab/TabContainer";import i18n from "../../../i18n";import { maybe } from "../../../misc";import { UserError } from "../../../types";@@ -30,18 +30,12 @@ export interface FormData {seoDescription: string;}-const styles = createStyles({- tabsBorder: {- borderBottom: "1px solid #eeeeee"- }-});-export enum CategoryPageTab {categories = "categories",products = "products"}-export interface CategoryUpdatePageProps extends WithStyles<typeof styles> {+export interface CategoryUpdatePageProps {changeTab: (index: CategoryPageTab) => void;currentTab: CategoryPageTab;errors: UserError[];@@ -70,142 +64,139 @@ export interface CategoryUpdatePageProps extends WithStyles<typeof styles> {const CategoriesTab = Tab(CategoryPageTab.categories);const ProductsTab = Tab(CategoryPageTab.products);-export const CategoryUpdatePage = withStyles(styles, {- name: "CategoryUpdatePage"-})(- ({- changeTab,- currentTab,- category,- classes,- disabled,- errors: userErrors,- pageInfo,- products,- saveButtonBarState,- subcategories,- onAddCategory,- onAddProduct,- onBack,- onCategoryClick,- onDelete,- onNextPage,- onPreviousPage,- onProductClick,- onSubmit,- onImageDelete,- onImageUpload- }: CategoryUpdatePageProps) => {- const initialData: FormData = category- ? {- backgroundImageAlt: maybe(() => category.backgroundImage.alt, ""),- description: category.description || "",- name: category.name || "",- seoDescription: category.seoDescription || "",- seoTitle: category.seoTitle || ""- }- : {- backgroundImageAlt: "",- description: "",- name: "",- seoDescription: "",- seoTitle: ""- };- return (- <Form- onSubmit={onSubmit}- initial={initialData}- errors={userErrors}- confirmLeave- >- {({ data, change, errors, submit, hasChanged }) => (- <Container width="md">- <PageHeader- title={category ? category.name : undefined}- onBack={onBack}- />- <CategoryDetailsForm- data={data}+export const CategoryUpdatePage: React.StatelessComponent<+ CategoryUpdatePageProps+> = ({+ changeTab,+ currentTab,+ category,+ disabled,+ errors: userErrors,+ pageInfo,+ products,+ saveButtonBarState,+ subcategories,+ onAddCategory,+ onAddProduct,+ onBack,+ onCategoryClick,+ onDelete,+ onNextPage,+ onPreviousPage,+ onProductClick,+ onSubmit,+ onImageDelete,+ onImageUpload+}: CategoryUpdatePageProps) => {+ const initialData: FormData = category+ ? {+ backgroundImageAlt: maybe(() => category.backgroundImage.alt, ""),+ description: category.description || "",+ name: category.name || "",+ seoDescription: category.seoDescription || "",+ seoTitle: category.seoTitle || ""+ }+ : {+ backgroundImageAlt: "",+ description: "",+ name: "",+ seoDescription: "",+ seoTitle: ""+ };+ return (+ <Form+ onSubmit={onSubmit}+ initial={initialData}+ errors={userErrors}+ confirmLeave+ >+ {({ data, change, errors, submit, hasChanged }) => (+ <Container width="md">+ <PageHeader+ title={category ? category.name : undefined}+ onBack={onBack}+ />+ <CategoryDetailsForm+ data={data}+ disabled={disabled}+ errors={errors}+ onChange={change}+ />+ <CardSpacer />+ <CategoryBackground+ data={data}+ onImageUpload={onImageUpload}+ onImageDelete={onImageDelete}+ image={maybe(() => category.backgroundImage)}+ onChange={change}+ />+ <CardSpacer />+ <SeoForm+ helperText={i18n.t(+ "Add search engine title and description to make this category easier to find"+ )}+ title={data.seoTitle}+ titlePlaceholder={data.name}+ description={data.seoDescription}+ descriptionPlaceholder={data.description}+ loading={!category}+ onChange={change}+ disabled={disabled}+ />+ <CardSpacer />+ <TabContainer>+ <CategoriesTab+ isActive={currentTab === CategoryPageTab.categories}+ changeTab={changeTab}+ >+ {i18n.t("Subcategories")}+ </CategoriesTab>+ <ProductsTab+ isActive={currentTab === CategoryPageTab.products}+ changeTab={changeTab}+ >+ {i18n.t("Products")}+ </ProductsTab>+ </TabContainer>+ <CardSpacer />+ {currentTab === CategoryPageTab.categories && (+ <CategoryListdisabled={disabled}- errors={errors}- onChange={change}- />- <CardSpacer />- <CategoryBackground- data={data}- onImageUpload={onImageUpload}- onImageDelete={onImageDelete}- image={maybe(() => category.backgroundImage)}- onChange={change}+ isRoot={false}+ categories={subcategories}+ onAdd={onAddCategory}+ onRowClick={onCategoryClick}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ pageInfo={pageInfo}/>- <CardSpacer />- <SeoForm- helperText={i18n.t(- "Add search engine title and description to make this category easier to find"- )}- title={data.seoTitle}- titlePlaceholder={data.name}- description={data.seoDescription}- descriptionPlaceholder={data.description}- loading={!category}- onChange={change}+ )}+ {currentTab === CategoryPageTab.products && (+ <CategoryProductsCard+ categoryName={maybe(() => category.name)}+ products={products}disabled={disabled}+ pageInfo={pageInfo}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ onRowClick={onProductClick}+ onAdd={onAddProduct}/>- <CardSpacer />- <div className={classes.tabsBorder}>- <CategoriesTab- isActive={currentTab === CategoryPageTab.categories}- changeTab={changeTab}- >- {i18n.t("Subcategories")}- </CategoriesTab>- <ProductsTab- isActive={currentTab === CategoryPageTab.products}- changeTab={changeTab}- >- {i18n.t("Products")}- </ProductsTab>- </div>- <CardSpacer />- {currentTab === CategoryPageTab.categories && (- <CategoryList- disabled={disabled}- isRoot={false}- categories={subcategories}- onAdd={onAddCategory}- onRowClick={onCategoryClick}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- pageInfo={pageInfo}- />- )}- {currentTab === CategoryPageTab.products && (- <CategoryProductsCard- categoryName={maybe(() => category.name)}- products={products}- disabled={disabled}- pageInfo={pageInfo}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- onRowClick={onProductClick}- onAdd={onAddProduct}- />- )}- <SaveButtonBar- onCancel={onBack}- onDelete={onDelete}- onSave={submit}- labels={{- delete: i18n.t("Delete category")- }}- state={saveButtonBarState}- disabled={disabled || !hasChanged}- />- </Container>- )}- </Form>- );- }-);+ )}+ <SaveButtonBar+ onCancel={onBack}+ onDelete={onDelete}+ onSave={submit}+ labels={{+ delete: i18n.t("Delete category")+ }}+ state={saveButtonBarState}+ disabled={disabled || !hasChanged}+ />+ </Container>+ )}+ </Form>+ );+};CategoryUpdatePage.displayName = "CategoryUpdatePage";export default CategoryUpdatePage;diff --git a/saleor/static/dashboard-next/components/Tab/Tab.tsx b/saleor/static/dashboard-next/components/Tab/Tab.tsxindex 36963cbe32..dce784d43a 100644--- a/saleor/static/dashboard-next/components/Tab/Tab.tsx+++ b/saleor/static/dashboard-next/components/Tab/Tab.tsx@@ -26,7 +26,8 @@ const styles = (theme: Theme) =>display: "inline-block",fontWeight: theme.typography.fontWeightRegular,marginRight: theme.spacing.unit * 4,- minWidth: 40+ minWidth: 40,+ transition: theme.transitions.duration.short + "ms"}});diff --git a/saleor/static/dashboard-next/components/Tab/TabContainer.tsx b/saleor/static/dashboard-next/components/Tab/TabContainer.tsxnew file mode 100644index 0000000000..31cf6bfdc4--- /dev/null+++ b/saleor/static/dashboard-next/components/Tab/TabContainer.tsx@@ -0,0 +1,21 @@+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";+import * as React from "react";++export interface TabContainerProps {+ children: React.ReactNode | React.ReactNodeArray;+}++const styles = createStyles({+ root: {+ borderBottom: "1px solid #eeeeee"+ }+});++const TabContainer = withStyles(styles, {+ name: "TabContainer"+})(({ classes, children }: TabContainerProps & WithStyles<typeof styles>) => (+ <div className={classes.root}>{children}</div>+));+TabContainer.displayName = "TabContainer";++export default TabContainer;