saleor-dashboard/src/types.ts

176 lines
4.4 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import { MutationResult } from "react-apollo";
2019-10-08 14:19:14 +00:00
import { User_permissions } from "./auth/types/User";
2019-06-19 14:40:52 +00:00
import { FilterContentSubmitData } from "./components/Filter";
import { Filter } from "./components/TableFilter";
2019-12-06 17:11:28 +00:00
import { ConfirmButtonTransitionState } from "./components/ConfirmButton";
2019-06-19 14:40:52 +00:00
export interface UserError {
field: string;
message: string;
}
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",
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",
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
}
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-09-12 14:22:42 +00:00
export interface FilterPageProps<TKeys = string>
extends SearchPageProps,
TabPageProps {
2019-09-10 15:14:11 +00:00
currencySymbol: string;
filtersList: Filter[];
2019-09-12 14:22:42 +00:00
onFilterAdd: (filter: FilterContentSubmitData<TKeys>) => void;
2019-09-10 15:14:11 +00:00
}
export interface SearchProps {
searchPlaceholder: string;
}
2019-09-12 14:22:42 +00:00
export interface FilterProps<TKeys = string>
extends FilterPageProps<TKeys>,
SearchProps {
2019-06-19 14:40:52 +00:00
allTabLabel: string;
filterLabel: string;
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 FormErrors<TKeys extends string> = Partial<Record<TKeys, 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<
Record<TFilters, string | 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_permissions[];
}
2019-12-06 17:14:19 +00:00
export interface MutationResultAdditionalProps {
state: ConfirmButtonTransitionState;
}