Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2095: Hot reload Table #2390

Merged
merged 7 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions packages/table/src/cell/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,14 @@ export class Cell extends React.Component<ICellProps, {}> {
// add width and height to the children, for use in shouldComponentUpdate in truncatedFormat
// note: these aren't actually used by truncated format, just in shouldComponentUpdate
const modifiedChildren = React.Children.map(this.props.children, child => {
if (style != null && React.isValidElement(child)) {
const childType = child.type;
// can't get prototype of "string" child, so treat those separately
if (typeof child === "string" || typeof childType === "string") {
return child;
} else {
const isTruncatedFormat =
childType.prototype === TruncatedFormat.prototype ||
TruncatedFormat.prototype.isPrototypeOf(childType) ||
childType.prototype === JSONFormat.prototype ||
JSONFormat.prototype.isPrototypeOf(childType);
// only add props if child is truncated format
if (isTruncatedFormat) {
return React.cloneElement(child as React.ReactElement<any>, {
parentCellHeight: parseInt(style.height, 10),
parentCellWidth: parseInt(style.width, 10),
});
}
}
if (
(style != null && React.isValidElement(child)) ||
(CoreUtils.isElementOfType(child, TruncatedFormat) || CoreUtils.isElementOfType(child, JSONFormat))
) {
return React.cloneElement(child as React.ReactElement<any>, {
parentCellHeight: parseInt(style.height, 10),
parentCellWidth: parseInt(style.width, 10),
});
}
return child;
});
Expand Down
13 changes: 1 addition & 12 deletions packages/table/src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -878,19 +878,8 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
throw new Error(Errors.TABLE_NUM_COLUMNS_COLUMN_WIDTHS_MISMATCH);
}
React.Children.forEach(children, (child: React.ReactElement<any>) => {
// save as a variable so that union type narrowing works
const childType = child.type;

// the second part of this conditional will never be true, but it
// informs the TS compiler that we won't be invoking
// childType.prototype on a "string" element.
if (typeof child === "string" || typeof childType === "string") {
if (!CoreUtils.isElementOfType(child, Column)) {
throw new Error(Errors.TABLE_NON_COLUMN_CHILDREN_WARNING);
} else {
const isColumn = childType.prototype === Column.prototype || Column.prototype.isPrototypeOf(childType);
if (!isColumn) {
throw new Error(Errors.TABLE_NON_COLUMN_CHILDREN_WARNING);
}
}
});

Expand Down