Skip to content

Commit

Permalink
Fix duplicated header/footer issue in the Table component
Browse files Browse the repository at this point in the history
issue #13
  • Loading branch information
PejmanNik committed Jul 8, 2023
1 parent 83744d4 commit ff51703
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [0.3.2]

### Fixed

- Fix duplicated header/footer issue in the Table component

## [0.3.1]
### Fixed

Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jikji/react",
"version": "0.3.1",
"version": "0.3.2",
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Table/TableHostComponentPulp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class TableHostComponentPulp extends HostComponentPulp {
super(id, elementType, props, domNode, domBoxInfo, rendered, version);
this.header = header;
this.footer = footer;
this.component = this.createComponent(props, props.children);
this.component = this.createComponent(props, rendered?.[0]?.component ?? props.children);
}

static FromPulp(pulp: HostComponentPulp, tableChildren: TableChildren) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export class TableHostComponentPulp extends HostComponentPulp {
this.domNode,
newProps.domBoxInfo ?? this.domBoxInfo,
merge(this.rendered, newProps.rendered),
newProps.version ?? this.version,
newProps.version ?? this.version,
this.header,
this.footer
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Table/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const tablePlugin: ReportPlugin = {
// to overate the split and layout behavior for HTML table component
return pulp.clone({
rendered: [TableHostComponentPulp.FromPulp(tablePulp, {
...children,
header: freezeColumnWidth(children.header),
body: children.body,
footer: children.footer,
})],
component: null,
});
Expand Down
16 changes: 9 additions & 7 deletions packages/react/src/core/pulp/pulpTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function makePulpTree(contentElement: HTMLDivElement, plugins: Readonly<R
);
}

const pageContentFiber = findPageContentFiber(contentElement, [fiberRoot]);
const pageContentFiber = findPageContentFiber(contentElement, [fiberRoot])
?? findPageContentFiber(contentElement, fiberRoot.alternate ? [fiberRoot.alternate] : []);

if (!pageContentFiber) {
throw Error(
"can't find the `PageContent` component, make sure you follow the documents.",
Expand All @@ -59,16 +61,16 @@ export function makePulpTree(contentElement: HTMLDivElement, plugins: Readonly<R
}

export function findPageContentFiber(contentElement: HTMLDivElement, fiber: Fiber[]): Fiber | null {
for (let i = 0; i < fiber.length; i++) {
if (fiber[i].elementType
&& isInstanceOfComponent(fiber[i].elementType, PageContent)
&& fiber[i].return?.stateNode == contentElement) {
return fiber[i];
for (let i = 0; i < fiber.length; i++) {
if (fiber[i].elementType
&& isInstanceOfComponent(fiber[i].elementType, PageContent)
&& fiber[i].return?.stateNode == contentElement) {
return fiber[i];
}

// find PageContent in the fiber children
const children = getChildren(fiber[i]);
if (!children) {
if (children.length === 0) {
continue;
}

Expand Down
11 changes: 4 additions & 7 deletions packages/react/src/core/pulp/treeHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Fiber} from 'react-reconciler';
import type { Fiber } from 'react-reconciler';

export function getSiblings(fiberRoot: Fiber | null) {
const result: Fiber[] = [];
Expand All @@ -12,12 +12,9 @@ export function getSiblings(fiberRoot: Fiber | null) {
return result;
}

export function getChildren(fiber: Fiber) {
if (!fiber.child) return null;

export function getChildren(fiber: Fiber): Fiber[] {
const siblings = getSiblings(fiber.child);
if (siblings.length === 0) {
return [fiber.child];
}
if (!fiber.child) return siblings;

return [fiber.child, ...siblings];
}

0 comments on commit ff51703

Please sign in to comment.