Skip to content

Commit

Permalink
1544: Update columnconfig based on changes in parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben van Leeuwen committed Dec 3, 2024
1 parent 44a067c commit 91532ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-rules-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@orchestrator-ui/orchestrator-ui-components': minor
---

Adds resizable table columns
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const WfoDragHandler: FC<WfoDragHandlerProps> = ({
};

const { dragAndDropStyle } = useWithOrchestratorTheme(getWfoTableStyles);
let startWidth: number;

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

onUpdateColumWidth(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import type { CSSProperties, ReactNode } from 'react';

import { useTranslations } from 'next-intl';
Expand Down Expand Up @@ -117,6 +117,15 @@ export const WfoTable = <T extends object>({
onRowClick,
className,
}: WfoTableProps<T>) => {
const [localColumnConfig, setLocalColumnConfig] =
useState<WfoTableColumnConfig<T>>(columnConfig);

useEffect(() => {
if (!localColumnConfig || localColumnConfig !== columnConfig) {
setLocalColumnConfig(columnConfig);
}
}, [columnConfig]); // Dont add localColumnConfig to dependencies, it should trigger on local column changes

Check warning on line 127 in packages/orchestrator-ui-components/src/components/WfoTable/WfoTable/WfoTable.tsx

View workflow job for this annotation

GitHub Actions / linting-and-prettier

React Hook useEffect has a missing dependency: 'localColumnConfig'. Either include it or remove the dependency array

const {
tableContainerStyle,
tableStyle,
Expand All @@ -128,9 +137,6 @@ export const WfoTable = <T extends object>({
} = useWithOrchestratorTheme(getWfoTableStyles);
const t = useTranslations('common');

const [localColumnConfig, setLocalColumnConfig] =
useState<WfoTableColumnConfig<T>>(columnConfig);

const sortedVisibleColumns = getSortedVisibleColumns(
columnConfig,
columnOrder,
Expand Down

0 comments on commit 91532ff

Please sign in to comment.