Skip to content

Commit 0172be2

Browse files
Ruben van LeeuwenDutchBen
authored andcommitted
1544: Update columnconfig based on changes in parent
1 parent 51d26ed commit 0172be2

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/metal-rules-sell.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+
Adds resizable table columns

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const WfoDragHandler: FC<WfoDragHandlerProps> = ({
3030
};
3131

3232
const { dragAndDropStyle } = useWithOrchestratorTheme(getWfoTableStyles);
33-
let startWidth: number;
3433

3534
return (
3635
<div>
@@ -44,7 +43,8 @@ export const WfoDragHandler: FC<WfoDragHandlerProps> = ({
4443
const thElement = headerRowRef.current.querySelector(
4544
`th[data-field-name="${fieldName}"]`,
4645
) as HTMLTableCellElement;
47-
startWidth = thElement.getBoundingClientRect().width;
46+
const startWidth =
47+
thElement.getBoundingClientRect().width;
4848
const newWidth = startWidth + data.x;
4949

5050
onUpdateColumWidth(

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import type { CSSProperties, ReactNode } from 'react';
33

44
import { useTranslations } from 'next-intl';
@@ -117,6 +117,15 @@ export const WfoTable = <T extends object>({
117117
onRowClick,
118118
className,
119119
}: WfoTableProps<T>) => {
120+
const [localColumnConfig, setLocalColumnConfig] =
121+
useState<WfoTableColumnConfig<T>>(columnConfig);
122+
123+
useEffect(() => {
124+
if (!localColumnConfig || localColumnConfig !== columnConfig) {
125+
setLocalColumnConfig(columnConfig);
126+
}
127+
}, [columnConfig]); // Dont add localColumnConfig to dependencies, it should trigger on local column changes
128+
120129
const {
121130
tableContainerStyle,
122131
tableStyle,
@@ -128,9 +137,6 @@ export const WfoTable = <T extends object>({
128137
} = useWithOrchestratorTheme(getWfoTableStyles);
129138
const t = useTranslations('common');
130139

131-
const [localColumnConfig, setLocalColumnConfig] =
132-
useState<WfoTableColumnConfig<T>>(columnConfig);
133-
134140
const sortedVisibleColumns = getSortedVisibleColumns(
135141
columnConfig,
136142
columnOrder,

0 commit comments

Comments
 (0)