Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add row number to discounts

Krzysztof Bialoglowicz3446bb97dac3
diff --git a/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx b/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx
index 42169f3d67..9494343d7a 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx
@@ -19,10 +19,10 @@ import Percent from "@saleor/components/Percent";
import Skeleton from "@saleor/components/Skeleton";
import TableHead from "@saleor/components/TableHead";
import TablePagination from "@saleor/components/TablePagination";
-import i18n from "../../../i18n";
-import { maybe, renderCollection } from "../../../misc";
-import { ListActions, ListProps } from "../../../types";
-import { SaleType } from "../../../types/globalTypes";
+import i18n from "@saleor/i18n";
+import { maybe, renderCollection } from "@saleor/misc";
+import { ListActions, ListProps } from "@saleor/types";
+import { SaleType } from "@saleor/types/globalTypes";
import { SaleList_sales_edges_node } from "../../types/SaleList";
export interface SaleListProps extends ListProps, ListActions {
@@ -64,10 +64,12 @@ const SaleList = withStyles(styles, {
})(
({
classes,
+ listSettings,
defaultCurrency,
disabled,
onNextPage,
onPreviousPage,
+ onUpdateListSettings,
onRowClick,
pageInfo,
sales,
@@ -111,8 +113,10 @@ const SaleList = withStyles(styles, {
<TableRow>
<TablePagination
colSpan={5}
+ listSettings={listSettings}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
+ onUpdateListSettings={onUpdateListSettings}
hasPreviousPage={
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
}
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherList/VoucherList.tsx b/saleor/static/dashboard-next/discounts/components/VoucherList/VoucherList.tsx
index d1c4633f62..7dc2e6b93d 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherList/VoucherList.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherList/VoucherList.tsx
@@ -19,10 +19,10 @@ import Percent from "@saleor/components/Percent";
import Skeleton from "@saleor/components/Skeleton";
import TableHead from "@saleor/components/TableHead";
import TablePagination from "@saleor/components/TablePagination";
-import i18n from "../../../i18n";
-import { maybe, renderCollection } from "../../../misc";
-import { ListActions, ListProps } from "../../../types";
-import { DiscountValueTypeEnum } from "../../../types/globalTypes";
+import i18n from "@saleor/i18n";
+import { maybe, renderCollection } from "@saleor/misc";
+import { ListActions, ListProps } from "@saleor/types";
+import { DiscountValueTypeEnum } from "@saleor/types/globalTypes";
import { VoucherList_vouchers_edges_node } from "../../types/VoucherList";
export interface VoucherListProps extends ListProps, ListActions {
@@ -79,10 +79,12 @@ const VoucherList = withStyles(styles, {
})(
({
classes,
+ listSettings,
defaultCurrency,
disabled,
onNextPage,
onPreviousPage,
+ onUpdateListSettings,
onRowClick,
pageInfo,
vouchers,
@@ -136,8 +138,10 @@ const VoucherList = withStyles(styles, {
<TableRow>
<TablePagination
colSpan={7}
+ listSettings={listSettings}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
+ onUpdateListSettings={onUpdateListSettings}
hasPreviousPage={
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
}
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherListPage/VoucherListPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherListPage/VoucherListPage.tsx
index 72cc4f4f2f..698b88d2dd 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherListPage/VoucherListPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherListPage/VoucherListPage.tsx
@@ -4,8 +4,8 @@ import React from "react";
import Container from "@saleor/components/Container";
import PageHeader from "@saleor/components/PageHeader";
-import i18n from "../../../i18n";
-import { ListActions, PageListProps } from "../../../types";
+import i18n from "@saleor/i18n";
+import { ListActions, PageListProps } from "@saleor/types";
import { VoucherList_vouchers_edges_node } from "../../types/VoucherList";
import VoucherList from "../VoucherList";
@@ -17,9 +17,11 @@ export interface VoucherListPageProps extends PageListProps, ListActions {
const VoucherListPage: React.StatelessComponent<VoucherListPageProps> = ({
defaultCurrency,
disabled,
+ listSettings,
onAdd,
onNextPage,
onPreviousPage,
+ onUpdateListSettings,
onRowClick,
pageInfo,
vouchers,
@@ -38,9 +40,11 @@ const VoucherListPage: React.StatelessComponent<VoucherListPageProps> = ({
</PageHeader>
<VoucherList
defaultCurrency={defaultCurrency}
+ listSettings={listSettings}
disabled={disabled}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
+ onUpdateListSettings={onUpdateListSettings}
onRowClick={onRowClick}
pageInfo={pageInfo}
vouchers={vouchers}
diff --git a/saleor/static/dashboard-next/discounts/views/SaleList.tsx b/saleor/static/dashboard-next/discounts/views/SaleList.tsx
index b51ba16f92..456f8737c2 100644
--- a/saleor/static/dashboard-next/discounts/views/SaleList.tsx
+++ b/saleor/static/dashboard-next/discounts/views/SaleList.tsx
@@ -6,15 +6,16 @@ import React from "react";
import ActionDialog from "@saleor/components/ActionDialog";
import { WindowTitle } from "@saleor/components/WindowTitle";
import useBulkActions from "@saleor/hooks/useBulkActions";
+import useListSettings from "@saleor/hooks/useListSettings";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import usePaginator, {
createPaginationState
} from "@saleor/hooks/usePaginator";
import useShop from "@saleor/hooks/useShop";
-import { PAGINATE_BY } from "../../config";
-import i18n from "../../i18n";
-import { getMutationState, maybe } from "../../misc";
+import i18n from "@saleor/i18n";
+import { getMutationState, maybe } from "@saleor/misc";
+import { Lists } from "@saleor/types";
import SaleListPage from "../components/SaleListPage";
import { TypedSaleBulkDelete } from "../mutations";
import { TypedSaleList } from "../queries";
@@ -41,9 +42,16 @@ export const SaleList: React.StatelessComponent<SaleListProps> = ({
params.ids
);
+ const { updateListSettings, listSettings } = useListSettings(
+ Lists.SALES_LIST
+ );
+
const closeModal = () => navigate(saleListUrl(), true);
- const paginationState = createPaginationState(PAGINATE_BY, params);
+ const paginationState = createPaginationState(
+ listSettings.SALES_LIST.rowNumber,
+ params
+ );
return (
<TypedSaleList displayLoader variables={paginationState}>
@@ -86,11 +94,13 @@ export const SaleList: React.StatelessComponent<SaleListProps> = ({
<SaleListPage
defaultCurrency={maybe(() => shop.defaultCurrency)}
sales={maybe(() => data.sales.edges.map(edge => edge.node))}
+ listSettings={listSettings.SALES_LIST}
disabled={loading}
pageInfo={pageInfo}
onAdd={() => navigate(saleAddUrl)}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
+ onUpdateListSettings={updateListSettings}
onRowClick={id => () => navigate(saleUrl(id))}
isChecked={isSelected}
selected={listElements.length}
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherList.tsx b/saleor/static/dashboard-next/discounts/views/VoucherList.tsx
index 8d5949a302..e78ddca5a1 100644
--- a/saleor/static/dashboard-next/discounts/views/VoucherList.tsx
+++ b/saleor/static/dashboard-next/discounts/views/VoucherList.tsx
@@ -6,15 +6,16 @@ import React from "react";
import ActionDialog from "@saleor/components/ActionDialog";
import { WindowTitle } from "@saleor/components/WindowTitle";
import useBulkActions from "@saleor/hooks/useBulkActions";
+import useListSettings from "@saleor/hooks/useListSettings";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import usePaginator, {
createPaginationState
} from "@saleor/hooks/usePaginator";
import useShop from "@saleor/hooks/useShop";
-import { PAGINATE_BY } from "../../config";
-import i18n from "../../i18n";
-import { getMutationState, maybe } from "../../misc";
+import i18n from "@saleor/i18n";
+import { getMutationState, maybe } from "@saleor/misc";
+import { Lists } from "@saleor/types";
import VoucherListPage from "../components/VoucherListPage";
import { TypedVoucherBulkDelete } from "../mutations";
import { TypedVoucherList } from "../queries";
@@ -41,9 +42,16 @@ export const VoucherList: React.StatelessComponent<VoucherListProps> = ({
params.ids
);
+ const { updateListSettings, listSettings } = useListSettings(
+ Lists.VOUCHER_LIST
+ );
+
const closeModal = () => navigate(voucherListUrl(), true);
- const paginationState = createPaginationState(PAGINATE_BY, params);
+ const paginationState = createPaginationState(
+ listSettings.VOUCHER_LIST.rowNumber,
+ params
+ );
return (
<TypedVoucherList displayLoader variables={paginationState}>
@@ -84,6 +92,7 @@ export const VoucherList: React.StatelessComponent<VoucherListProps> = ({
<WindowTitle title={i18n.t("Vouchers")} />
<VoucherListPage
defaultCurrency={maybe(() => shop.defaultCurrency)}
+ listSettings={listSettings.VOUCHER_LIST}
vouchers={maybe(() =>
data.vouchers.edges.map(edge => edge.node)
)}
@@ -92,6 +101,7 @@ export const VoucherList: React.StatelessComponent<VoucherListProps> = ({
onAdd={() => navigate(voucherAddUrl)}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
+ onUpdateListSettings={updateListSettings}
onRowClick={id => () => navigate(voucherUrl(id))}
isChecked={isSelected}
selected={listElements.length}