Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/table/analytics-metadata/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export interface GeneratedAnalyticsMetadataTableComponent {
sortingColumnId?: string;
sortingDescending?: string;
variant: string;
columnsLabel?: string[] | LabelIdentifier[];
selectedItemsLabel?: string | Array<Array<string | LabelIdentifier>>;
selectedItems?: string[];
};
innerContext?: {
position: string;
Expand Down
4 changes: 4 additions & 0 deletions src/table/analytics-metadata/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
.header-cell-text {
/* used in analytics metadata */
}

.body-cell-content {
/* used in analytics metadata */
}
11 changes: 10 additions & 1 deletion src/table/body-cell/td-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { StickyColumnsModel, useStickyCellStyles } from '../sticky-columns';
import { getTableCellRoleProps, TableRole } from '../table-role';
import { getStickyClassNames } from '../utils';

import analyticsSelectors from '../analytics-metadata/styles.css.js';
import tableStyles from '../styles.css.js';
import styles from './styles.css.js';

Expand Down Expand Up @@ -165,7 +166,15 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
</div>
)}

<div className={clsx(styles['body-cell-content'], wrapLines && styles['body-cell-wrap'])}>{children}</div>
<div
className={clsx(
styles['body-cell-content'],
analyticsSelectors['body-cell-content'],
wrapLines && styles['body-cell-wrap']
)}
>
{children}
</div>
</Element>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/table/header-cell/th-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getTableColHeaderRoleProps, TableRole } from '../table-role';
import { getStickyClassNames } from '../utils';
import { SortingStatus } from './utils';

import analyticsSelectors from '../analytics-metadata/styles.css.js';
import tableStyles from '../styles.css.js';
import styles from './styles.css.js';

Expand Down Expand Up @@ -80,6 +81,7 @@ export function TableThElement({
className={clsx(
styles['header-cell'],
styles[`header-cell-variant-${variant}`],
analyticsSelectors['body-cell-content'],
sticky && styles['header-cell-sticky'],
resizable && styles['header-cell-resizable'],
stuck && styles['header-cell-stuck'],
Expand Down
48 changes: 48 additions & 0 deletions src/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import useBaseComponent from '../internal/hooks/use-base-component';
import { applyDisplayName } from '../internal/utils/apply-display-name';
import { GeneratedAnalyticsMetadataTableComponent } from './analytics-metadata/interfaces';
import { useExpandableTableProps } from './expandable-rows/expandable-rows-utils';
import { getSortingColumnId } from './header-cell/utils';
import { TableForwardRefType, TableProps } from './interfaces';
import InternalTable, { InternalTableAsSubstep } from './internal';
import { getItemKey } from './utils';

import analyticsSelectors from './analytics-metadata/styles.css.js';

export { TableProps };
const Table = React.forwardRef(
Expand All @@ -34,6 +38,15 @@
(props.visibleColumns && props.visibleColumns.length < props.columnDefinitions.length) ||
props.columnDisplay?.some(col => !col.visible);
const hasStickyColumns = !!props.stickyColumns?.first || !!props.stickyColumns?.last;

// Process expandable rows to get allItems (including expanded children)
const { allItems } = useExpandableTableProps({
items,
expandableRows: props.expandableRows,
trackBy: props.trackBy,
ariaLabels: props.ariaLabels,
});

const baseComponentProps = useBaseComponent(
'Table',
{
Expand Down Expand Up @@ -84,6 +97,41 @@
},
};

const columns = props.columnDefinitions.map((colDef, colIndex) => {
const headerPosition = colIndex + (props.selectionType ? 2 : 1);

return {
selector: `thead th:nth-child(${headerPosition}) .${analyticsSelectors['header-cell-text']}`,
root: 'self' as const,
};
});

analyticsComponentMetadata.properties.columnsLabel = columns;

if (props.trackBy && selectedItems.length > 0) {
analyticsComponentMetadata.properties.selectedItems = selectedItems.map(
(item, index) => `${getItemKey(props.trackBy, item, index)}`
);

const selectedItemsLabel = selectedItems.map((item, itemIndex) => {
const rowIndexInItems = allItems.findIndex(
i => getItemKey(props.trackBy, i, allItems.indexOf(i)) === getItemKey(props.trackBy, item, itemIndex)
);
const rowNumber = rowIndexInItems + 1; // CSS nth-child is 1-based

return props.columnDefinitions.map((colDef, colIndex) => {
const cellPosition = colIndex + (props.selectionType ? 2 : 1);

return {
selector: `tbody tr:nth-child(${rowNumber}) > :nth-child(${cellPosition}) .${analyticsSelectors['body-cell-content']}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible here instead to do something based on tr:has(input:checked) so that we don't have to loop through all selected items here? I'm a little worried about the potential performance impact of doing it this way

root: 'self' as const,
};
});
});

analyticsComponentMetadata.properties.selectedItemsLabel = selectedItemsLabel;
}

const sortingColumnId = getSortingColumnId(props.columnDefinitions, props.sortingColumn);
if (sortingColumnId) {
analyticsComponentMetadata.properties.sortingColumnId = sortingColumnId;
Expand All @@ -100,7 +148,7 @@
...props,
...baseComponentProps,
ref,
...getAnalyticsMetadataAttribute({ component: analyticsComponentMetadata }),

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / build / build

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / build (React 18) / build

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 4/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components motion tests (React 18)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 3/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (5/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (6/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 2/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Build components

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (3/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Build components (React 18)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 1/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 4/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 3/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (2/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components motion tests (React 16)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 2/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (1/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 1/4)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.

Check failure on line 151 in src/table/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (4/6)

Type 'GeneratedAnalyticsMetadataTableComponent' is not assignable to type 'Omit<Partial<GeneratedAnalyticsMetadataComponent>, "label" | "innerContext"> & { label?: string | LabelIdentifier | undefined; innerContext?: Record<...> | undefined; }'.
};

const collectionPreferencesMetadata = {
Expand Down
Loading