
* Update macaw to include Paginator changes * Add link support to TablePagination component * Rewrite usePaginator to use context and links instead of onClick * Refactor ProductList to use new usePaginator hook * Add decorator for PaginatorContext in ProductList stories * Refactor AppList to use new usePaginator hook * Refactor AttributeList to use new usePaginator hook * Add missing pagination props for local pagination to AttributeValues * Refactor CategoryList to use new usePaginator hook * Refactor CategoryDetails to use useLocalPaginator and context * Refactor CollectionList to use new usePaginator hook * Refactor CollectionProducts to use new usePaginator hook * Refactor CustomerList to use new usePaginator hook * Refactor VoucherDetailsPage to use PaginationContext * Refactor SaleDetails to use PaginatorContext * Refactor SaleList to use new usePaginator hook * Refactor VoucherList to use new usePaginator hook * Fix type error in paginatorContextValues fixture * Refactor GitfCardList to use new usePaginator hook * Remove unused imports * Refactor MenuList to use new usePaginator hook * Refactor OrderDraftList to use new usePaginator hook * Refactor OrderListPage to use new usePaginator hook * Refactor PageList to use new usePaginator hook * Refactor PageTypeList to use new usePaginator hook * Refactor PermissionGroupList to use new usePaginator hook * Refactor PluginsList to use new usePaginator hook * Refactor ProductTypeList to use new usePaginator hook * Refactor ShippingMethodProducts to use PaginationContext * Refactor ShippingZonesList to use new usePaginator hook * Refactor StaffList to use new usePaginator hook * Fix TS errors * Update TranslationEntities and TranslationFields to use new usePaginator * Refactor WarehouseList to use new usePaginator hook * Fix errors in stories that didn't use PaginationContextDecorator * Mention changes in changelog * Update to latest macaw version, update snapshots
207 lines
6 KiB
TypeScript
207 lines
6 KiB
TypeScript
import ChannelPickerDialog from "@saleor/channels/components/ChannelPickerDialog";
|
|
import useAppChannel from "@saleor/components/AppLayout/AppChannelContext";
|
|
import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
|
import SaveFilterTabDialog, {
|
|
SaveFilterTabDialogFormData
|
|
} from "@saleor/components/SaveFilterTabDialog";
|
|
import { useShopLimitsQuery } from "@saleor/components/Shop/queries";
|
|
import {
|
|
useOrderDraftCreateMutation,
|
|
useOrderListQuery
|
|
} from "@saleor/graphql";
|
|
import useListSettings from "@saleor/hooks/useListSettings";
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
import { usePaginationReset } from "@saleor/hooks/usePaginationReset";
|
|
import usePaginator, {
|
|
createPaginationState,
|
|
PaginatorContext
|
|
} from "@saleor/hooks/usePaginator";
|
|
import { getStringOrPlaceholder } from "@saleor/misc";
|
|
import { ListViews } from "@saleor/types";
|
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
|
import createFilterHandlers from "@saleor/utils/handlers/filterHandlers";
|
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
|
import { mapEdgesToItems, mapNodeToChoice } from "@saleor/utils/maps";
|
|
import { getSortParams } from "@saleor/utils/sort";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
|
|
import OrderListPage from "../../components/OrderListPage/OrderListPage";
|
|
import {
|
|
orderListUrl,
|
|
OrderListUrlDialog,
|
|
OrderListUrlQueryParams,
|
|
orderSettingsPath,
|
|
orderUrl
|
|
} from "../../urls";
|
|
import {
|
|
deleteFilterTab,
|
|
getActiveFilters,
|
|
getFilterOpts,
|
|
getFilterQueryParam,
|
|
getFiltersCurrentTab,
|
|
getFilterTabs,
|
|
getFilterVariables,
|
|
saveFilterTab
|
|
} from "./filters";
|
|
import { getSortQueryVariables } from "./sort";
|
|
|
|
interface OrderListProps {
|
|
params: OrderListUrlQueryParams;
|
|
}
|
|
|
|
export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
|
const navigate = useNavigator();
|
|
const notify = useNotifier();
|
|
const { updateListSettings, settings } = useListSettings(
|
|
ListViews.ORDER_LIST
|
|
);
|
|
|
|
usePaginationReset(orderListUrl, params, settings.rowNumber);
|
|
|
|
const intl = useIntl();
|
|
|
|
const [createOrder] = useOrderDraftCreateMutation({
|
|
onCompleted: data => {
|
|
notify({
|
|
status: "success",
|
|
text: intl.formatMessage({
|
|
id: "6udlH+",
|
|
defaultMessage: "Order draft successfully created"
|
|
})
|
|
});
|
|
navigate(orderUrl(data.draftOrderCreate.order.id));
|
|
}
|
|
});
|
|
|
|
const { channel, availableChannels } = useAppChannel(false);
|
|
const limitOpts = useShopLimitsQuery({
|
|
variables: {
|
|
orders: true
|
|
}
|
|
});
|
|
|
|
const noChannel = !channel && typeof channel !== "undefined";
|
|
const channelOpts = availableChannels
|
|
? mapNodeToChoice(availableChannels)
|
|
: null;
|
|
|
|
const tabs = getFilterTabs();
|
|
|
|
const currentTab = getFiltersCurrentTab(params, tabs);
|
|
|
|
const [
|
|
changeFilters,
|
|
resetFilters,
|
|
handleSearchChange
|
|
] = createFilterHandlers({
|
|
createUrl: orderListUrl,
|
|
getFilterQueryParam,
|
|
navigate,
|
|
params
|
|
});
|
|
|
|
const [openModal, closeModal] = createDialogActionHandlers<
|
|
OrderListUrlDialog,
|
|
OrderListUrlQueryParams
|
|
>(navigate, orderListUrl, params);
|
|
|
|
const handleTabChange = (tab: number) =>
|
|
navigate(
|
|
orderListUrl({
|
|
activeTab: tab.toString(),
|
|
...getFilterTabs()[tab - 1].data
|
|
})
|
|
);
|
|
|
|
const handleFilterTabDelete = () => {
|
|
deleteFilterTab(currentTab);
|
|
navigate(orderListUrl());
|
|
};
|
|
|
|
const handleFilterTabSave = (data: SaveFilterTabDialogFormData) => {
|
|
saveFilterTab(data.name, getActiveFilters(params));
|
|
handleTabChange(tabs.length + 1);
|
|
};
|
|
|
|
const paginationState = createPaginationState(settings.rowNumber, params);
|
|
|
|
const queryVariables = React.useMemo(
|
|
() => ({
|
|
...paginationState,
|
|
filter: getFilterVariables(params),
|
|
sort: getSortQueryVariables(params)
|
|
}),
|
|
[params, settings.rowNumber]
|
|
);
|
|
const { data, loading } = useOrderListQuery({
|
|
displayLoader: true,
|
|
variables: queryVariables
|
|
});
|
|
|
|
const paginationValues = usePaginator({
|
|
pageInfo: data?.orders?.pageInfo,
|
|
paginationState,
|
|
queryString: params
|
|
});
|
|
|
|
const handleSort = createSortHandler(navigate, orderListUrl, params);
|
|
|
|
return (
|
|
<PaginatorContext.Provider value={paginationValues}>
|
|
<OrderListPage
|
|
settings={settings}
|
|
currentTab={currentTab}
|
|
disabled={loading}
|
|
filterOpts={getFilterOpts(params, channelOpts)}
|
|
limits={limitOpts.data?.shop.limits}
|
|
orders={mapEdgesToItems(data?.orders)}
|
|
sort={getSortParams(params)}
|
|
onAdd={() => openModal("create-order")}
|
|
onUpdateListSettings={updateListSettings}
|
|
onSort={handleSort}
|
|
onSearchChange={handleSearchChange}
|
|
onFilterChange={changeFilters}
|
|
onTabSave={() => openModal("save-search")}
|
|
onTabDelete={() => openModal("delete-search")}
|
|
onTabChange={handleTabChange}
|
|
initialSearch={params.query || ""}
|
|
tabs={getFilterTabs().map(tab => tab.name)}
|
|
onAll={resetFilters}
|
|
onSettingsOpen={() => navigate(orderSettingsPath)}
|
|
/>
|
|
<SaveFilterTabDialog
|
|
open={params.action === "save-search"}
|
|
confirmButtonState="default"
|
|
onClose={closeModal}
|
|
onSubmit={handleFilterTabSave}
|
|
/>
|
|
<DeleteFilterTabDialog
|
|
open={params.action === "delete-search"}
|
|
confirmButtonState="default"
|
|
onClose={closeModal}
|
|
onSubmit={handleFilterTabDelete}
|
|
tabName={getStringOrPlaceholder(tabs[currentTab - 1]?.name)}
|
|
/>
|
|
{!noChannel && (
|
|
<ChannelPickerDialog
|
|
channelsChoices={channelOpts}
|
|
confirmButtonState="success"
|
|
defaultChoice={channel.id}
|
|
open={params.action === "create-order"}
|
|
onClose={closeModal}
|
|
onConfirm={channelId =>
|
|
createOrder({
|
|
variables: {
|
|
input: { channelId }
|
|
}
|
|
})
|
|
}
|
|
/>
|
|
)}
|
|
</PaginatorContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default OrderList;
|