Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Issue 280 - Refactor cell content #281

Merged
merged 42 commits into from
Dec 6, 2018
Merged

Conversation

Marc-Andre-Rivet
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet commented Dec 4, 2018

Closes #280 in preparation for #166.

Breaks up the existing CellInput component into all its flavors (label, input, dropdown) and moving the choice into the derived/cell/contents calculation. Separating the logic from the flavors implementation details will make it easier to support the additional data types and scenarios that pop up in the data types epic.

This is all prep work for the data types. There's no additional feature here -- additional sanity may be needed but the tests cover a pretty broad range of cases already.

Not rebasing as there are not that many changes despite the large amount of commits (this branch is a child of the virtualization branch -- that's why!)

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-281 December 4, 2018 21:13 Inactive
value: any;
}

export default class CellDropdown extends PureComponent<IProps> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standalone Dropdown component pulled out of pre-existing CellInput comp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it still uses react-select in the end :(

conditionalDropdowns: [],
type: ColumnType.Text
};
export default class CellInput extends PureComponent<ICellProps, ICellState> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standalone Input component -- what's left after removing Label and Dropdown from the existing implementation

value: any;
}

export default class CellLabel extends PureComponent<IProps> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standalone Label component pulled out of pre-existing CellInput comp -- as before we use this to display non-editable fields, fallback dropdown fields and to optimize inputs while cell is not active.

default:
return CellType.Label;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of cell content

...['dash-cell-value']
].join(' ');

switch (getCellType(active, isEditable, dropdown, column.type)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the type of cell content is decided, apply the right one

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-281 December 4, 2018 21:21 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-281 December 5, 2018 14:51 Inactive
Copy link
Contributor

@valentijnnieman valentijnnieman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good refactor to me. Couple of tiny comments - not going to approve just yet to see what you think of them.

value: any;
}

export default class CellDropdown extends PureComponent<IProps> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

const dropdown = this.refs.dropdown as any;

if (dropdown && document.activeElement !== dropdown) {
// Limitation. If React >= 16 --> Use React.createRef instead to pass parent ref to child
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be possible to pass a ref down from the parent, regardless of React >= 16?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I have in mind: ref forwarding (added in React 16.3)
https://reactjs.org/docs/forwarding-refs.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha. Yeah that would be nice!

case ColumnType.Numeric:
return (!active || !editable) ? CellType.Label : CellType.Input;
case ColumnType.Dropdown:
return (!dropdown || !editable) ? CellType.Label : CellType.Dropdown;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because dropdown is of type any, it's not immediately obvious what this is (for me at least). As I'm reading it, I'd think that if case ColumnType.Dropdown, then dropdown should be true too, in other words, when would the type be ColumnType.Dropdown but dropdown would be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll see if I can tighten the typing here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved typing so we know we have either dropdown values (array) or undefined -- there were two sets of independent interfaces used to define dropdown labels and values -- removed one, kept the other. Lots of small additional changes all over the place for that consolidation.

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-281 December 6, 2018 18:34 Inactive
Copy link
Contributor

@valentijnnieman valentijnnieman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot more sense. Lgtm! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants