Skip to content

Commit

Permalink
Adjust datatable last column (#2307)
Browse files Browse the repository at this point in the history
OKTA-790884 fix: fixed the column resizing
fix: update active color of resize handle
Merge branch 'main' into jk-datatable-last-column
fix: add waitBeforeCapture to applitools
Merge branch 'main' into jk-datatable-last-column
Update packages/odyssey-react-mui/src/DataTable/DataTable.tsx

Co-authored-by: Kevin Ghadyani <[email protected]>
fix: remove unnecessary TEST comment
fix: update const name
Merge branch 'main' into jk-datatable-last-column
fix: address linter error
  • Loading branch information
jordankoschei-okta and KevinGhadyani-Okta authored Aug 7, 2024
1 parent c42ca4a commit 6b98b1d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
21 changes: 15 additions & 6 deletions packages/odyssey-react-mui/src/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ const DataTable = ({
[columnIds],
) as string[];

const shouldDisplayRowActions = useMemo(
() =>
(hasRowReordering === true && onReorderRows) ||
rowActionButtons ||
rowActionMenuItems
? true
: false,
[hasRowReordering, onReorderRows, rowActionButtons, rowActionMenuItems],
);

const dataTable = useMaterialReactTable({
columns: columns,
data: data,
Expand Down Expand Up @@ -723,12 +733,7 @@ const DataTable = ({
}),

// Row actions
enableRowActions:
(hasRowReordering === true && onReorderRows) ||
rowActionButtons ||
rowActionMenuItems
? true
: false,
enableRowActions: shouldDisplayRowActions,
positionActionsColumn:
"last" as MRT_TableOptions<DataTableRowData>["positionActionsColumn"],
renderRowActions: ({ row }) => renderRowActions({ row }),
Expand Down Expand Up @@ -763,6 +768,10 @@ const DataTable = ({
// Refs
muiTableProps: {
ref: tableContentRef,
className:
!shouldDisplayRowActions && hasColumnResizing
? "ods-hide-spacer-column"
: "",
},

muiTableContainerProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ const TableContent = ({
[innerWidthStyle, emptyState],
);

const shouldDisplayRowActions = useMemo(
() =>
(hasRowReordering === true && onReorderRows) ||
tableOptions.rowActionButtons ||
tableOptions.rowActionMenuItems
? true
: false,
[
hasRowReordering,
onReorderRows,
tableOptions.rowActionButtons,
tableOptions.rowActionMenuItems,
],
);

const dataTable = useMaterialReactTable({
data: !isEmpty && !isNoResults ? data : [],
columns,
Expand Down Expand Up @@ -329,6 +344,10 @@ const TableContent = ({
},
muiTableProps: {
ref: tableContentRef,
className:
!shouldDisplayRowActions && tableOptions.hasColumnResizing
? "ods-hide-spacer-column"
: "",
},
muiTableContainerProps: {
ref: tableInnerContainerRef,
Expand All @@ -340,12 +359,7 @@ const TableContent = ({
defaultColumn: {
Cell: defaultCell,
},
enableRowActions:
(hasRowReordering === true && onReorderRows) ||
tableOptions.rowActionButtons ||
tableOptions.rowActionMenuItems
? true
: false,
enableRowActions: shouldDisplayRowActions,
renderRowActions: ({ row }) => renderRowActions({ row }),
enableRowOrdering: hasRowReordering && Boolean(onReorderRows),
enableRowDragging: hasRowReordering && Boolean(onReorderRows),
Expand Down
27 changes: 23 additions & 4 deletions packages/odyssey-react-mui/src/theme/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2566,10 +2566,6 @@ export const components = ({
borderLeft: `none !important`,
},

["&::after"]: {
background: "transparent !important",
},

[`.${tableBodyClasses.root} &.${tableCellClasses.root}`]: {
borderRight: `none !important`,
},
Expand Down Expand Up @@ -2633,7 +2629,25 @@ export const components = ({
flexGrow: 0,
width: odysseyTokens.Spacing2,
},
[`.ods-hide-spacer-column .${tableHeadClasses.root} &:last-of-type, .ods-hide-spacer-column .${tableBodyClasses.root} &:last-of-type`]:
{
display: "none",
},

[`.ods-hide-spacer-column .${tableHeadClasses.root} &:nth-last-of-type(2), .ods-hide-spacer-column .${tableBodyClasses.root} &:nth-last-of-type(2)`]:
{
borderTopRightRadius: odysseyTokens.Spacing2,
borderBottomRightRadius: odysseyTokens.Spacing2,
flexGrow: 1,

[`& .Mui-TableHeadCell-ResizeHandle-Wrapper`]: {
display: "none",
},
},

[`&::after`]: {
display: "none",
},
...(ownerState.variant === "number" && {
textAlign: "end",
fontFeatureSettings: '"lnum", "tnum"',
Expand Down Expand Up @@ -2672,6 +2686,11 @@ export const components = ({

[`& .Mui-TableHeadCell-ResizeHandle-Wrapper`]: {
marginInlineEnd: `-${odysseyTokens.Spacing3}`,

[`&:active .${dividerClasses.vertical}`]: {
borderColor: odysseyTokens.HueNeutral400,
opacity: 1,
},
},

[`& .Mui-TableHeadCell-Content-Wrapper`]: {
Expand Down

0 comments on commit 6b98b1d

Please sign in to comment.