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

Refactor to React 16.3+ lifecycle methods #3702

Merged
merged 53 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
66545e7
Refactor abstract components for new lifecycle methods
Aug 14, 2019
d1f576a
Update numericInput component to new lifecycle methods
Aug 15, 2019
c636c23
Update multi-slider to new lifecycle methods
Aug 15, 2019
aab8cf3
Update alert to new lifecycle methods
Aug 15, 2019
e76e438
Update collapse to new lifecycle methods
Aug 15, 2019
8c437bd
Update hotkeys to new lifecycle methods
Aug 15, 2019
4b187f6
Increase timeout to fix flakyness of test
Aug 15, 2019
53eb7f7
Update tagInput to new lifecycle methods
Aug 15, 2019
b038062
Update popover to new lifecycle methods
Aug 15, 2019
9d4b6f9
Lint changed files
Aug 15, 2019
cbb823c
Refactor dateInput to new lifeccycle methods
Aug 15, 2019
5bc4d67
Refactor datePicker to new lifeccycle methods
Aug 15, 2019
67d17d7
Refactor dateRangeInput to new lifeccycle methods
Aug 15, 2019
c2efafc
Refactor dateRangePicker to new lifeccycle methods
Aug 15, 2019
8d7bccd
Update dom in dateTimePicker tests after changing props
Aug 15, 2019
b2f7512
Fix signature of componentDidUpdate to allow to receive args
Aug 15, 2019
211cc8f
Only set hotkey if events are already registered
Aug 15, 2019
545a81e
Fix Table component to correctly extend AbstractComponent
Aug 15, 2019
c7a2f56
Refactor timezonePicker to use new lifecycle methods
Aug 15, 2019
73d8763
Add lifecycle polyfill to core package
Aug 15, 2019
76bf418
Refactor lifecycle method in timePicker component
Aug 15, 2019
54979cb
Refactor lifecycle method in Resizable component
Aug 15, 2019
469cd65
Refactor lifecycle method in EditableCell component
Aug 15, 2019
28daf23
Refactor lifecycle method in EditableNane component
Aug 15, 2019
73fdeec
Refactor lifecycle method in LoadableContent component
Aug 15, 2019
ca99bf1
Refactor lifecycle method in Header component
Aug 15, 2019
77438a1
Refactor lifecycle method in Suggest component
Aug 15, 2019
80dabc4
Remove remaining old lifecycle methods in core package
Aug 15, 2019
e7eefc3
Refactor example component to new lifecycle method
Aug 15, 2019
51192c0
Refactor dateTimePicker component to new lifecycle methods
Aug 15, 2019
b74069d
Fix jsdocs
Aug 15, 2019
7323f55
Count items rendered instead of render method calls to account for ad…
Aug 15, 2019
f4c796c
Refactor QueryList to use new lifecycle methods
Aug 15, 2019
0bf9ff8
Refactor Table to use new lifecycle methods
Aug 15, 2019
cb94e0c
Merge branch 'develop' of https://github.com/palantir/blueprint into …
Sep 21, 2019
ea315c5
Incorporate changes from different PR
Sep 20, 2019
a7cbd2b
Remove unneeded code
Sep 21, 2019
42df21b
Polyfill tabs component
Sep 21, 2019
e6755a2
Fix DateRangeInput tests
Sep 21, 2019
24f937e
Pass forceValidation parameter in constructor to use by implementations
Sep 21, 2019
bc21f72
Use abstractComponent implementation of validateProps invocations
Sep 21, 2019
97bd162
Add comment to explain validateProps change in table component
Sep 21, 2019
7a523f4
Rename new abstract components to keep name for legacy components
Sep 21, 2019
631be23
Fix up abstract components, rename to "v2"
adidahiya Sep 24, 2019
e7fb9bb
update usage, make sure everything is polyfilled
adidahiya Sep 24, 2019
cb6d630
Fix some argument names
adidahiya Sep 24, 2019
f79460f
remove unnecessary test logic
adidahiya Sep 30, 2019
3f6e21e
Clean up resizable.tsx
adidahiya Sep 30, 2019
32eb87c
remove forceValidate param, simplify Table#validateProps
adidahiya Sep 30, 2019
fa76c0a
skip some tests
adidahiya Sep 30, 2019
b2483d5
Remove unused import
adidahiya Sep 30, 2019
7c5251c
Revert some semantic changes in Table#validateProps
adidahiya Sep 30, 2019
6504b65
Swap order of Table decorators
adidahiya Sep 30, 2019
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
Prev Previous commit
Next Next commit
Fix Table component to correctly extend AbstractComponent
  • Loading branch information
Tobias committed Aug 15, 2019
commit 545a81e6a9ca2d11dab690f7bdf9008ad239858c
8 changes: 6 additions & 2 deletions packages/core/src/components/hotkeys/hotkeysTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ export function HotkeysTarget<T extends IConstructor<IHotkeysTargetComponent>>(W

if (isFunction(this.renderHotkeys)) {
const hotkeys = this.renderHotkeys();
if (this.localHotkeysEvents) { this.localHotkeysEvents.setHotkeys(hotkeys.props); }
if (this.globalHotkeysEvents) { this.globalHotkeysEvents.setHotkeys(hotkeys.props); }
if (this.localHotkeysEvents) {
this.localHotkeysEvents.setHotkeys(hotkeys.props);
}
if (this.globalHotkeysEvents) {
this.globalHotkeysEvents.setHotkeys(hotkeys.props);
}

if (this.localHotkeysEvents.count() > 0) {
const tabIndex = hotkeys.props.tabIndex === undefined ? 0 : hotkeys.props.tabIndex;
Expand Down
33 changes: 20 additions & 13 deletions packages/table/src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,6 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
}

public componentWillReceiveProps(nextProps: ITableProps) {
// calls validateProps
super.componentWillReceiveProps(nextProps);

const {
children,
columnWidths,
Expand Down Expand Up @@ -883,6 +880,7 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
* ClientRects.
*/
public componentDidMount() {
this.validateProps(this.props, true);
tobilen marked this conversation as resolved.
Show resolved Hide resolved
this.validateGrid();

this.locator = new Locator(this.rootTableElement, this.scrollContainerElement, this.cellContainerElement);
Expand All @@ -904,7 +902,8 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
this.didCompletelyMount = false;
}

public componentDidUpdate() {
public componentDidUpdate(prevProps: ITableProps, __: ITableState, ___: {}) {
this.validateProps(prevProps);
if (this.locator != null) {
this.validateGrid();
this.updateLocator();
Expand All @@ -918,24 +917,30 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
this.maybeScrollTableIntoView();
}

protected validateProps(props: ITableProps & { children: React.ReactNode }) {
const { children, columnWidths, numFrozenColumns, numFrozenRows, numRows, rowHeights } = props;
protected validateProps(prevProps: ITableProps, forceValidation: boolean = false) {
const { children, columnWidths, numFrozenColumns, numFrozenRows, numRows, rowHeights } = this.props;
const numColumns = React.Children.count(children);

const shouldValidate =
tobilen marked this conversation as resolved.
Show resolved Hide resolved
numFrozenRows !== prevProps.numFrozenRows ||
numFrozenColumns !== prevProps.numFrozenColumns ||
numRows !== prevProps.numRows ||
forceValidation;

// do cheap error-checking first.
if (numRows != null && numRows < 0) {
if (shouldValidate && numRows != null && numRows < 0) {
throw new Error(Errors.TABLE_NUM_ROWS_NEGATIVE);
}
if (numFrozenRows != null && numFrozenRows < 0) {
if (shouldValidate && numFrozenRows != null && numFrozenRows < 0) {
throw new Error(Errors.TABLE_NUM_FROZEN_ROWS_NEGATIVE);
}
if (numFrozenColumns != null && numFrozenColumns < 0) {
if (shouldValidate && numFrozenColumns != null && numFrozenColumns < 0) {
throw new Error(Errors.TABLE_NUM_FROZEN_COLUMNS_NEGATIVE);
}
if (numRows != null && rowHeights != null && rowHeights.length !== numRows) {
if (shouldValidate && numRows != null && rowHeights != null && rowHeights.length !== numRows) {
throw new Error(Errors.TABLE_NUM_ROWS_ROW_HEIGHTS_MISMATCH);
}
if (numColumns != null && columnWidths != null && columnWidths.length !== numColumns) {
if (shouldValidate && numColumns != null && columnWidths != null && columnWidths.length !== numColumns) {
throw new Error(Errors.TABLE_NUM_COLUMNS_COLUMN_WIDTHS_MISMATCH);
}
React.Children.forEach(children, child => {
Expand All @@ -945,10 +950,12 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
});

// these are recoverable scenarios, so just print a warning.
if (numFrozenRows != null && numRows != null && numFrozenRows > numRows) {
if (shouldValidate && numFrozenRows != null && numRows != null && numFrozenRows > numRows) {
console.warn(Errors.TABLE_NUM_FROZEN_ROWS_BOUND_WARNING);
}
if (numFrozenColumns != null && numFrozenColumns > numColumns) {

const propsOrColsChanged = shouldValidate || numColumns !== React.Children.count(prevProps.children);
if (propsOrColsChanged && numFrozenColumns != null && numFrozenColumns > numColumns) {
console.warn(Errors.TABLE_NUM_FROZEN_COLUMNS_BOUND_WARNING);
}
}
Expand Down