From 48e21068c41831d7a1efebb309caa6e16d636ebd Mon Sep 17 00:00:00 2001 From: luciob Date: Mon, 13 Sep 2021 11:04:26 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[Table]=20Added=20option?= =?UTF-8?q?=20to=20sort=20toolbar=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: 103 --- src/components/Table/index.tsx | 16 +++++++++++++--- src/types/Table.ts | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 91366d50..2b773e8a 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -57,6 +57,7 @@ export const SUBPARTS_MAP = { const Table: FC = ({ actions = [], + actionsOrder = "list", columns: externalColumns, dataCy = DATA_CY_DEFAULT, emptyState, @@ -200,13 +201,22 @@ const Table: FC = ({ ]; } - const defaultActions = toolbarActions.sort( - ({ position }, { position: another }) => -1 * position!.localeCompare(another!) - ); + let defaultActions = toolbarActions; + switch (actionsOrder) { + case "buttons-first": + defaultActions.sort(({ position }, { position: another }) => -1 * position!.localeCompare(another!)); + break; + case "icons-first": + defaultActions.sort(({ position }, { position: another }) => position!.localeCompare(another!)); + break; + default: + break; + } return { defaultActions, columns, rowActions, selectionActions }; }, [ actions, + actionsOrder, externalColumns, dataCy, loading, diff --git a/src/types/Table.ts b/src/types/Table.ts index 5ed5fc38..5596328c 100644 --- a/src/types/Table.ts +++ b/src/types/Table.ts @@ -19,6 +19,8 @@ export interface ITableAction extends IPartialIconUtilizer { position?: TableActionPosition; } +export type ITableActionsOrder = "buttons-first" | "icons-first" | "list"; + export interface ITableToolbarAction extends ISubpartItem, ITableAction { data: object | object[]; index: number; @@ -65,6 +67,7 @@ export type ITablePaginationActions = MUITablePaginationProps & ISubpartItem; export type ITable = ILocalizable & Partial & { actions?: ITableAction[]; + actionsOrder?: "list" | "buttons-first" | "icons-first"; columns: ITableColumn[]; emptyState?: ReactNode; getRowStyle?: (data: any) => CSSProperties;