Skip to content

Commit 21c2886

Browse files
authored
Added blank column to take 100% width (#1840)
* Added blank column to take 100% width * Fix cell separator resets to previous width, code refactor * linted * Add changeset
1 parent 3aff782 commit 21c2886

File tree

7 files changed

+78
-46
lines changed

7 files changed

+78
-46
lines changed

.changeset/green-planets-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': minor
3+
---
4+
5+
1825 Update WfoDragHandler, make WfoTable 100% width

packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/WfoDragHandler.tsx

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,62 @@ export const WfoDragHandler: FC<WfoDragHandlerProps> = ({
2222
onUpdateColumWidth,
2323
}) => {
2424
const [position, setPosition] = useState({ x: 0, y: 0 });
25+
const [isDragging, setIsDragging] = useState(false);
26+
const { dragAndDropStyle } = useWithOrchestratorTheme(getWfoTableStyles);
27+
28+
const resetPosition = () => {
29+
setPosition({ x: 0, y: 0 });
30+
};
31+
32+
const onStart: DraggableEventHandler = () => {
33+
setIsDragging(false);
34+
};
2535

2636
const onDrag: DraggableEventHandler = (_, data) => {
37+
setIsDragging(true);
2738
setPosition({ x: data.x, y: data.y });
2839
};
2940

30-
const resetPosition = () => {
31-
setPosition({ x: 0, y: 0 });
32-
};
41+
const onStop: DraggableEventHandler = (_, data) => {
42+
if (headerRowRef.current && isDragging) {
43+
const newWidth = startWidth + data.x;
3344

34-
const { dragAndDropStyle } = useWithOrchestratorTheme(getWfoTableStyles);
45+
onUpdateColumWidth(
46+
fieldName,
47+
newWidth > MINIMUM_COLUMN_WIDTH
48+
? newWidth
49+
: MINIMUM_COLUMN_WIDTH,
50+
);
51+
resetPosition();
52+
setIsDragging(false);
53+
}
54+
};
3555

3656
const thElement =
3757
headerRowRef.current &&
3858
(headerRowRef.current.querySelector(
3959
`th[data-field-name="${fieldName}"]`,
4060
) as HTMLTableCellElement);
61+
4162
const startWidth =
4263
thElement?.getBoundingClientRect().width ?? MINIMUM_COLUMN_WIDTH;
4364

65+
const bounds = {
66+
left: MINIMUM_COLUMN_WIDTH - startWidth,
67+
top: 0,
68+
bottom: 0,
69+
};
70+
4471
return (
4572
<div>
4673
<Draggable
74+
allowAnyClick={false}
4775
axis="x"
4876
position={position}
77+
onStart={onStart}
4978
onDrag={onDrag}
50-
bounds={{
51-
left: MINIMUM_COLUMN_WIDTH - startWidth,
52-
top: 0,
53-
bottom: 0,
54-
}}
55-
onStop={(_, data) => {
56-
if (headerRowRef.current) {
57-
const newWidth = startWidth + data.x;
58-
59-
onUpdateColumWidth(
60-
fieldName,
61-
newWidth > MINIMUM_COLUMN_WIDTH
62-
? newWidth
63-
: MINIMUM_COLUMN_WIDTH,
64-
);
65-
resetPosition();
66-
}
67-
}}
79+
bounds={bounds}
80+
onStop={onStop}
6881
>
6982
<div css={dragAndDropStyle} />
7083
</Draggable>

packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoGroupedTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const WfoGroupedTable = <T extends object>({
102102
uniqueRowIdToExpandedRowMap,
103103
}}
104104
onRowClick={({ groupName }) => toggleExpandedRow(groupName)}
105+
appendFillerColumn={false}
105106
/>
106107
</>
107108
);

packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/WfoTable.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { DEFAULT_PAGE_SIZES } from '../utils/constants';
1616
import { WfoTableDataRows } from './WfoTableDataRows';
1717
import { WfoTableHeaderRow } from './WfoTableHeaderRow';
1818
import { getWfoTableStyles } from './styles';
19-
import { getSortedVisibleColumns } from './utils';
19+
import { getColumnWidthsFromConfig, getSortedVisibleColumns } from './utils';
2020

2121
export type Pagination = {
2222
pageSize: number;
@@ -99,10 +99,11 @@ export type WfoTableProps<T extends object> = {
9999
onRowClick?: (row: T) => void;
100100
onUpdateDataSorting?: (updatedDataSorting: WfoDataSorting<T>) => void;
101101
onUpdateDataSearch?: (updatedDataSearch: WfoDataSearch<T>) => void;
102+
appendFillerColumn?: boolean;
102103
className?: string;
103104
};
104105

105-
type LocalColumnWidths = {
106+
export type LocalColumnWidths = {
106107
[key: string]: string;
107108
};
108109

@@ -119,25 +120,24 @@ export const WfoTable = <T extends object>({
119120
onUpdateDataSorting,
120121
onUpdateDataSearch,
121122
onRowClick,
123+
appendFillerColumn = true,
122124
className,
123125
}: WfoTableProps<T>) => {
124-
const getColumnWidthsFromConfig = (
125-
columnConfig: WfoTableColumnConfig<T>,
126-
): LocalColumnWidths => {
127-
return Object.entries(columnConfig).reduce(
128-
(columnWidths, [key, config]) => {
129-
if (config.columnType === ColumnType.DATA) {
130-
columnWidths[key] = config.width ?? 'auto';
131-
}
132-
return columnWidths;
133-
},
134-
{} as LocalColumnWidths,
135-
);
136-
};
137-
138126
const [localColumnWidths, setLocalColumnWidths] =
139127
useState<LocalColumnWidths>(getColumnWidthsFromConfig(columnConfig));
140128

129+
const columnConfigWithFiller: WfoTableColumnConfig<T> = appendFillerColumn
130+
? {
131+
...columnConfig,
132+
filler: {
133+
columnType: ColumnType.CONTROL,
134+
label: '',
135+
width: '100%',
136+
renderControl: () => null,
137+
},
138+
}
139+
: columnConfig;
140+
141141
const {
142142
tableContainerStyle,
143143
tableStyle,
@@ -151,7 +151,7 @@ export const WfoTable = <T extends object>({
151151
const t = useTranslations('common');
152152

153153
const sortedVisibleColumns = getSortedVisibleColumns(
154-
columnConfig,
154+
columnConfigWithFiller,
155155
columnOrder,
156156
hiddenColumns,
157157
);
@@ -166,7 +166,7 @@ export const WfoTable = <T extends object>({
166166
};
167167

168168
const configWithLocalWidths: WfoTableColumnConfig<T> = Object.entries(
169-
columnConfig,
169+
columnConfigWithFiller,
170170
).reduce((mergedConfig, [fieldName, fieldConfig]) => {
171171
const key = fieldName as keyof WfoTableColumnConfig<T>;
172172
if (fieldConfig.columnType === ColumnType.DATA) {

packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/styles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const getWfoTableStyles = ({ theme, isDarkThemeActive }: WfoTheme) => {
3737
});
3838

3939
const tableStyle = css({
40-
width: 'auto',
40+
width: '100%',
4141
});
4242

4343
const headerStyle = css({
@@ -136,7 +136,7 @@ export const getWfoTableStyles = ({ theme, isDarkThemeActive }: WfoTheme) => {
136136
position: 'absolute',
137137
height: '100%',
138138
zIndex: theme.levels.menu,
139-
'&:hover, &:active': {
139+
'&:active, &:focus': {
140140
transition: 'background-color 0.15s',
141141
backgroundColor: isDarkThemeActive
142142
? theme.colors.mediumShade
@@ -152,7 +152,7 @@ export const getWfoTableStyles = ({ theme, isDarkThemeActive }: WfoTheme) => {
152152
opacity: 0.6,
153153
zIndex: theme.levels.navigation,
154154
},
155-
'&:hover::after, &:active::after': {
155+
'&:active::after': {
156156
transition: 'opacity 0.15s',
157157
opacity: 0,
158158
},

packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TableColumnKeys } from '@/components';
1+
import { LocalColumnWidths, TableColumnKeys } from '@/components';
22
import { SortOrder } from '@/types';
33
import { toObjectWithSortedKeys } from '@/utils';
44

@@ -80,3 +80,16 @@ export function mapSortableAndFilterableValuesToTableColumnConfig<
8080

8181
return Object.fromEntries(tableColumnConfigUpdatedEntries);
8282
}
83+
84+
export const getColumnWidthsFromConfig = <T extends object>(
85+
columnConfig: WfoTableColumnConfig<T>,
86+
): LocalColumnWidths => {
87+
const columnEntries = Object.entries(columnConfig);
88+
89+
return columnEntries.reduce((columnWidths, [key, config]) => {
90+
if (config.columnType === ColumnType.DATA) {
91+
columnWidths[key] = config.width ?? 'auto';
92+
}
93+
return columnWidths;
94+
}, {} as LocalColumnWidths);
95+
};

packages/orchestrator-ui-components/src/icons/WfoQuestionCircle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const WfoQuestionCircle: FC<WfoIconProps> = ({
2424
>
2525
<g id="icon/play-circle" fill="none" fillRule="nonzero">
2626
<path
27-
stroke-linecap="round"
28-
stroke-linejoin="round"
27+
strokeLinecap="round"
28+
strokeLinejoin="round"
2929
d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z"
3030
/>
3131
</g>

0 commit comments

Comments
 (0)