Skip to content

Commit 5c91fe5

Browse files
authored
[WC-3288][WC-3280][WC-3279] datagrid all the grid layouts (#2124)
2 parents ad30bbf + 3d596c7 commit 5c91fe5

11 files changed

Lines changed: 94 additions & 35 deletions

File tree

packages/modules/data-widgets/src/themesource/datawidgets/web/_datagrid-filters.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
flex-grow: 1;
2020
position: relative;
2121

22+
overflow: hidden;
23+
2224
.filter-input {
2325
border-start-start-radius: 0;
2426
border-end-start-radius: 0;

packages/modules/data-widgets/src/themesource/datawidgets/web/_datagrid.scss

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ $root: ".widget-datagrid";
129129
color: var(--gray-dark, $gray-dark);
130130
height: var(--btn-font-size, $btn-font-size);
131131
align-self: center;
132+
z-index: 1;
132133
}
133134

134135
&:focus:not(:focus-visible) {
@@ -493,6 +494,14 @@ $root: ".widget-datagrid";
493494
width: calc(var(--widgets-grid-width) - var(--widgets-grid-scrollbar-size));
494495
overflow-x: hidden;
495496
}
497+
498+
.widget-datagrid-grid-head {
499+
&[data-scrolled-x="true"],
500+
&[data-scrolled-y="true"] {
501+
z-index: 1;
502+
}
503+
}
504+
496505
.widget-datagrid-grid-head[data-scrolled-y="true"] {
497506
// add shadow under the header
498507
// implying that grid is scrolled vertically (there are rows hidden under header)
@@ -524,27 +533,54 @@ $root: ".widget-datagrid";
524533
}
525534
}
526535

536+
// styles for browsers that don't support subgrid
537+
// if the browser doesn't support subgrid
538+
// fall back header an body the contents and apply grid template to the table
539+
.widget-datagrid-grid.table {
540+
grid-template-columns: var(--widgets-grid-template-columns);
541+
}
542+
.widget-datagrid-grid-body,
527543
.widget-datagrid-grid-head {
528-
display: grid;
529-
min-width: 0;
530-
531-
// this head is not part of the grid, so it has dedicated column template --widgets-grid-template-columns-head
532-
// but it might not be available at the initial render, so we use template from the grid --widgets-grid-template-columns
533-
// using template from the grid might to misalignment from the grid itself,
534-
// but in practice:
535-
// - grid has no data at that moment, so misalignment is not visible.
536-
// - as soon as the grid itself gets rendered --widgets-grid-template-columns-head gets calculated
537-
// and everything looks like it should.
538-
grid-template-columns: var(--widgets-grid-template-columns-head, var(--widgets-grid-template-columns));
544+
display: contents;
539545
}
540546

541-
.widget-datagrid-grid-body {
542-
// this element has to position their children (columns or headers)
543-
// as grid and have those aligned with the parent grid
544-
display: grid;
545-
// this property makes sure we align our own grid columns
546-
// to the columns defined in the global grid
547-
grid-template-columns: var(--widgets-grid-template-columns);
547+
// styles for modern browsers
548+
@supports (grid-template-rows: subgrid) {
549+
.widget-datagrid-grid.table:not([data-has-scroll-x="true"]) {
550+
grid-template-columns: var(--widgets-grid-template-columns);
551+
.widget-datagrid-grid-body,
552+
.widget-datagrid-grid-head {
553+
display: grid;
554+
min-width: 0;
555+
556+
// this property makes sure we align our own grid columns
557+
// to the columns defined in the global grid
558+
grid-template-columns: subgrid;
559+
560+
// ensure that we cover all columns of original top level grid
561+
// so our own columns get aligned with the parent
562+
grid-column: 1 / -1;
563+
}
564+
}
565+
566+
.widget-datagrid-grid.table[data-has-scroll-x="true"] {
567+
// reset the columns defined on table level
568+
// header and body will define their own instead
569+
// this is needed to make body horizontally scrollable
570+
grid-template-columns: initial;
571+
.widget-datagrid-grid-head {
572+
display: grid;
573+
min-width: 0;
574+
575+
grid-template-columns: var(--widgets-grid-template-columns-head, var(--widgets-grid-template-columns));
576+
}
577+
578+
.widget-datagrid-grid-body {
579+
display: grid;
580+
581+
grid-template-columns: var(--widgets-grid-template-columns);
582+
}
583+
}
548584
}
549585

550586
.grid-mock-header {
257 Bytes
Loading
Loading
Loading

packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ export function getProperties(values: DatagridPreviewProps, defaultProperties: P
5454
if (column.width !== "manual") {
5555
hidePropertyIn(defaultProperties, values, "columns", index, "size");
5656
}
57-
if (column.width !== "autoFit") {
58-
hidePropertyIn(defaultProperties, values, "columns", index, "minWidth");
59-
}
6057
if (column.minWidth !== "manual") {
6158
hidePropertyIn(defaultProperties, values, "columns", index, "minWidthLimit");
6259
}

packages/pluggableWidgets/datagrid-web/src/components/MockHeader.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ export function MockHeader(): ReactNode {
88
const resizeCallback = useCallback<ResizeObserverCallback>(
99
entries => {
1010
const container = entries[0].target.parentElement!;
11+
12+
const gridContainer = container.closest<HTMLDivElement>(".table");
13+
const gridBody = container.closest<HTMLDivElement>(".table-content");
14+
if (gridContainer && gridBody) {
15+
if (gridContainer.dataset.hasScrollX === "true") {
16+
if (gridBody.scrollWidth <= gridBody.clientWidth) {
17+
delete gridContainer.dataset.hasScrollX;
18+
}
19+
} else {
20+
if (gridContainer.scrollWidth > gridContainer.clientWidth) {
21+
gridContainer.dataset.hasScrollX = "true";
22+
}
23+
}
24+
}
25+
1126
const sizes = new Map<string, number>();
1227
container.querySelectorAll<HTMLDivElement>("[data-column-id]").forEach(c => {
1328
const columnId = c.dataset.columnId;

packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export function Widget(props: { onExportCancel?: () => void }): ReactElement {
2626
<SelectAllBar />
2727
<RefreshStatus />
2828
<GridBody>
29-
<MockHeader />
3029
<RowsRenderer />
30+
<MockHeader />
3131
<EmptyPlaceholder />
3232
</GridBody>
3333
</Grid>

packages/pluggableWidgets/datagrid-web/src/components/__tests__/__snapshots__/Grid.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`Grid renders without crashing 1`] = `
55
<div
66
class="widget-datagrid-grid table"
77
role="grid"
8-
style="--widgets-grid-template-columns: 1fr 1fr 54px;"
8+
style="--widgets-grid-template-columns: minmax(auto, 1fr) minmax(auto, 1fr) 54px;"
99
>
1010
Test
1111
</div>
@@ -17,7 +17,7 @@ exports[`Grid renders without selector column 1`] = `
1717
<div
1818
class="widget-datagrid-grid table"
1919
role="grid"
20-
style="--widgets-grid-template-columns: 1fr 1fr;"
20+
style="--widgets-grid-template-columns: minmax(auto, 1fr) minmax(auto, 1fr);"
2121
>
2222
Test
2323
</div>

packages/pluggableWidgets/datagrid-web/src/helpers/state/column/BaseColumnInfo.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,30 @@ export class BaseColumnInfo {
5656
this.allowEventPropagation = props.allowEventPropagation;
5757
}
5858

59+
get minColumnWidth(): "auto" | "min-content" | `${number}px` {
60+
switch (this.minWidth) {
61+
case "auto": {
62+
return "auto";
63+
}
64+
case "minContent": {
65+
return "min-content";
66+
}
67+
case "manual": {
68+
return `${this.minWidthLimit}px`;
69+
}
70+
}
71+
}
72+
5973
get columnWidth(): string {
6074
switch (this.width) {
75+
case "autoFill": {
76+
return `minmax(${this.minColumnWidth}, 1fr)`;
77+
}
6178
case "autoFit": {
62-
const min =
63-
this.minWidth === "manual"
64-
? `${this.minWidthLimit}px`
65-
: this.minWidth === "minContent"
66-
? "min-content"
67-
: "auto";
68-
return `minmax(${min}, auto)`;
79+
return `minmax(${this.minColumnWidth}, auto)`;
6980
}
7081
case "manual":
71-
return `${this.weight}fr`;
72-
default:
73-
return "1fr";
82+
return `minmax(${this.minColumnWidth}, ${this.weight}fr)`;
7483
}
7584
}
7685
}

0 commit comments

Comments
 (0)