saleor-dashboard/src/types.ts

197 lines
5 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import { MutationResult } from "react-apollo";
import { User_userPermissions } from "./auth/types/User";
2019-12-06 17:11:28 +00:00
import { ConfirmButtonTransitionState } from "./components/ConfirmButton";
2019-12-19 15:54:52 +00:00
import { IFilter } from "./components/Filter";
2020-01-15 15:36:45 +00:00
import { MultiAutocompleteChoiceType } from "./components/MultiAutocompleteSelectField";
2019-06-19 14:40:52 +00:00
export interface UserError {
2020-02-24 14:14:48 +00:00
field: string | null;
2020-03-24 14:05:26 +00:00
message?: string;
2019-06-19 14:40:52 +00:00
}
2019-11-08 10:25:17 +00:00
export interface DialogProps {
open: boolean;
onClose: () => void;
}
2019-08-09 11:14:35 +00:00
export interface ListSettings<TColumn extends string = string> {
columns?: TColumn[];
rowNumber: number;
}
export enum ListViews {
ATTRIBUTE_LIST = "ATTRIBUTE_LIST",
CATEGORY_LIST = "CATEGORY_LIST",
COLLECTION_LIST = "COLLECTION_LIST",
CUSTOMER_LIST = "CUSTOMER_LIST",
DRAFT_LIST = "DRAFT_LIST",
NAVIGATION_LIST = "NAVIGATION_LIST",
ORDER_LIST = "ORDER_LIST",
PAGES_LIST = "PAGES_LIST",
2019-08-27 12:36:19 +00:00
PLUGINS_LIST = "PLUGIN_LIST",
2019-08-09 11:14:35 +00:00
PRODUCT_LIST = "PRODUCT_LIST",
PERMISSION_GROUP_LIST = "PERMISSION_GROUP_LIST",
2019-09-12 13:00:25 +00:00
PRODUCT_TYPE_LIST = "PRODUCT_TYPE_LIST",
2019-08-09 11:14:35 +00:00
SALES_LIST = "SALES_LIST",
SHIPPING_METHODS_LIST = "SHIPPING_METHODS_LIST",
STAFF_MEMBERS_LIST = "STAFF_MEMBERS_LIST",
2019-10-09 06:56:46 +00:00
VOUCHER_LIST = "VOUCHER_LIST",
2020-01-30 11:46:35 +00:00
WAREHOUSE_LIST = "WAREHOUSE_LIST",
2019-10-09 06:56:46 +00:00
WEBHOOK_LIST = "WEBHOOK_LIST"
2019-08-09 11:14:35 +00:00
}
export interface ListProps<TColumns extends string = string> {
2019-06-19 14:40:52 +00:00
disabled: boolean;
pageInfo?: {
hasNextPage: boolean;
hasPreviousPage: boolean;
};
2019-08-09 11:14:35 +00:00
settings?: ListSettings<TColumns>;
2019-06-19 14:40:52 +00:00
onNextPage: () => void;
onPreviousPage: () => void;
onRowClick: (id: string) => () => void;
2019-08-09 11:14:35 +00:00
onUpdateListSettings?: (
key: keyof ListSettings<TColumns>,
value: any
) => void;
onListSettingsReset?: () => void;
2019-06-19 14:40:52 +00:00
}
2019-09-13 11:33:42 +00:00
export interface SortPage<TSortKey extends string> {
2019-09-13 14:17:12 +00:00
sort: Sort<TSortKey>;
2019-09-26 10:14:07 +00:00
onSort: (field: TSortKey, id?: string) => void;
2019-09-13 11:33:42 +00:00
}
/**
* @param toggle Will be use to change status of item
* @param isChecked Returns true for ids of chosen items
* @param selected Number of chosen items.
*/
2019-06-19 14:40:52 +00:00
export interface ListActionsWithoutToolbar {
toggle: (id: string) => void;
toggleAll: (items: React.ReactNodeArray, selected: number) => void;
isChecked: (id: string) => boolean;
selected: number;
}
export type TabListActions<
TToolbars extends string
> = ListActionsWithoutToolbar &
Record<TToolbars, React.ReactNode | React.ReactNodeArray>;
export interface ListActions extends ListActionsWithoutToolbar {
toolbar: React.ReactNode | React.ReactNodeArray;
}
2019-08-09 11:14:35 +00:00
export interface PageListProps<TColumns extends string = string>
extends ListProps<TColumns> {
defaultSettings?: ListSettings<TColumns>;
2019-06-19 14:40:52 +00:00
onAdd: () => void;
}
2019-09-10 15:14:11 +00:00
export interface SearchPageProps {
2019-06-19 14:40:52 +00:00
initialSearch: string;
onSearchChange: (value: string) => void;
}
2019-12-20 15:53:03 +00:00
export interface FilterPageProps<TKeys extends string, TOpts extends object>
extends FilterProps<TKeys>,
SearchPageProps,
2019-09-12 14:22:42 +00:00
TabPageProps {
2019-12-20 15:53:03 +00:00
filterOpts: TOpts;
2019-09-10 15:14:11 +00:00
}
2019-12-20 15:53:03 +00:00
export interface FilterProps<TKeys extends string> {
2019-12-19 15:54:52 +00:00
currencySymbol: string;
2019-12-20 15:53:03 +00:00
onFilterChange: (filter: IFilter<TKeys>) => void;
2019-09-10 15:14:11 +00:00
}
export interface TabPageProps {
currentTab: number;
tabs: string[];
onAll: () => void;
onTabChange: (tab: number) => void;
onTabDelete: () => void;
onTabSave: () => void;
2019-06-19 14:40:52 +00:00
}
export interface PartialMutationProviderOutput<
TData extends {} = {},
TVariables extends {} = {}
> {
2019-12-06 17:14:19 +00:00
opts: MutationResult<TData> & MutationResultAdditionalProps;
2019-06-19 14:40:52 +00:00
mutate: (variables: TVariables) => void;
}
export interface Node {
id: string;
}
export type Pagination = Partial<{
after: string;
before: string;
}>;
export type Dialog<TDialog extends string> = Partial<{
action: TDialog;
}>;
export type ActiveTab<TTab extends string = string> = Partial<{
activeTab: TTab;
}>;
export type Filters<TFilters extends string> = Partial<
Record<TFilters, string>
>;
2019-09-05 13:05:12 +00:00
export type FiltersWithMultipleValues<TFilters extends string> = Partial<
2019-12-20 10:44:41 +00:00
Record<TFilters, string[]>
2019-09-05 13:05:12 +00:00
>;
2020-01-17 14:25:50 +00:00
export type FiltersAsDictWithMultipleValues<TFilters extends string> = Partial<
Record<TFilters, Record<string, string[]>>
>;
2020-01-09 13:38:04 +00:00
export type Search = Partial<{
query: string;
}>;
2019-06-19 14:40:52 +00:00
export type SingleAction = Partial<{
id: string;
}>;
2019-09-13 11:33:42 +00:00
export type Sort<TSort extends string = string> = Partial<{
asc: boolean;
sort: TSort;
}>;
2019-06-19 14:40:52 +00:00
export type BulkAction = Partial<{
ids: string[];
}>;
2019-08-09 11:14:35 +00:00
export interface ReorderEvent {
oldIndex: number;
newIndex: number;
}
export type ReorderAction = (event: ReorderEvent) => void;
2019-08-12 14:11:10 +00:00
export interface FetchMoreProps {
2019-08-09 11:14:35 +00:00
loading: boolean;
hasMore: boolean;
onFetchMore: () => void;
}
2019-09-10 15:14:11 +00:00
export type TabActionDialog = "save-search" | "delete-search";
2019-10-08 14:19:14 +00:00
export interface UserPermissionProps {
userPermissions: User_userPermissions[];
2019-10-08 14:19:14 +00:00
}
2019-12-06 17:14:19 +00:00
export interface MutationResultAdditionalProps {
2019-12-06 17:17:44 +00:00
status: ConfirmButtonTransitionState;
2019-12-06 17:14:19 +00:00
}
2019-12-20 15:53:03 +00:00
export type MinMax = Record<"min" | "max", string>;
export interface FilterOpts<T> {
active: boolean;
value: T;
}
2020-01-15 15:36:45 +00:00
export interface AutocompleteFilterOpts
extends FetchMoreProps,
SearchPageProps {
choices: MultiAutocompleteChoiceType[];
displayValues: MultiAutocompleteChoiceType[];
}