From ab982eb83066e922a4d1475704b1182a6256bcd6 Mon Sep 17 00:00:00 2001 From: Lisa Kim Date: Thu, 1 Aug 2024 23:01:57 -0700 Subject: [PATCH] Table add ons and remove ellipsis and re-order - Allow on row click handler - Allow custom row styler (func to conditionally apply styles) --- web/packages/design/src/DataTable/Table.tsx | 11 +++++++- web/packages/design/src/DataTable/types.ts | 10 ++++++++ .../src/Integrations/IntegrationList.tsx | 25 ++++++++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/web/packages/design/src/DataTable/Table.tsx b/web/packages/design/src/DataTable/Table.tsx index 493e36fcaf419..385db10e504f0 100644 --- a/web/packages/design/src/DataTable/Table.tsx +++ b/web/packages/design/src/DataTable/Table.tsx @@ -56,6 +56,7 @@ export function Table({ style, serversideProps, customSort, + row, }: State) { const renderHeaders = () => { const headers = columns.flatMap(column => { @@ -126,7 +127,15 @@ export function Table({ ); }); - rows.push({cells}); + rows.push( + row.onClick(item) : undefined} + style={row?.onStyle ? row.onStyle(item) : undefined} + > + {cells} + + ); }); if (rows.length) { diff --git a/web/packages/design/src/DataTable/types.ts b/web/packages/design/src/DataTable/types.ts index 2adb81e31f0db..61e99b61a8a0d 100644 --- a/web/packages/design/src/DataTable/types.ts +++ b/web/packages/design/src/DataTable/types.ts @@ -54,6 +54,16 @@ export type TableProps = { // any client table filtering supplied by default. // Use case: filtering is done on the caller side e.g. server side. disableFilter?: boolean; + /** + * row configuration + */ + row: { + onClick?(row: T): void; + /** + * conditionally style a row (eg: cursor: pointer, disabled) + */ + onStyle?(row: T): React.CSSProperties; + }; }; type TableColumnBase = { diff --git a/web/packages/teleport/src/Integrations/IntegrationList.tsx b/web/packages/teleport/src/Integrations/IntegrationList.tsx index 565874094ba27..896d3e8c247ca 100644 --- a/web/packages/teleport/src/Integrations/IntegrationList.tsx +++ b/web/packages/teleport/src/Integrations/IntegrationList.tsx @@ -18,6 +18,7 @@ import React from 'react'; import styled from 'styled-components'; +import { useHistory } from 'react-router'; import { Link as InternalRouteLink } from 'react-router-dom'; import { Box, Flex, Image } from 'design'; @@ -65,11 +66,27 @@ type Props = { type IntegrationLike = Integration | Plugin | ExternalAuditStorageIntegration; export function IntegrationList(props: Props) { + const history = useHistory(); + + function handleOnRowClick(row: IntegrationLike) { + if (row.kind !== 'okta') return; + history.push(cfg.getIntegrationStatusRoute(row.kind, row.name)); + } + + function handleOnRowStyle(row: IntegrationLike): React.CSSProperties { + if (row.kind !== 'okta') return; + return { cursor: 'pointer' }; + } + return ( ) { return ( - props.onDeletePlugin(item)}> - Delete... - {/* Currently, only okta supports status pages */} {item.kind === 'okta' && ( - View Status... + View Status )} + props.onDeletePlugin(item)}> + Delete... + );