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

Adds editing options for progress and rating columns in react demo. #9935

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from

Conversation

bulaj
Copy link

@bulaj bulaj commented Sep 21, 2022

Context

Adds editing options for progress and rating columns in react demo.

How has this been tested?

Manually in browser.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

  1. Progress and Rating columns should be editable in the main demo #9581

Affected project(s):

  • handsontable
  • @handsontable/angular
  • @handsontable/react
  • @handsontable/vue
  • @handsontable/vue3

Checklist:

[skip changelog]

@bulaj bulaj added the Docs: Tools Issues related to Handsontable's documentation tools (VuePress, deployment, scripts etc.) label Sep 21, 2022
@github-actions
Copy link

github-actions bot commented Sep 21, 2022

Launch the local version of documentation by running:

npm run docs:review fd074cddfcb0b92de89da80948dc700fd758b490

@bulaj bulaj changed the title Feature/issue 9581 demo Adds editing options for progress and rating columns in react demo. Sep 22, 2022
@warpech
Copy link
Member

warpech commented Sep 23, 2022

@krzysztofspilka to run the project, run the following commands in the repo root:

git fetch
git checkout feature/issue-9581-demo
git pull
cd examples/12.1.2/docs/react/demo
npm i
npm run start

And open http://localhost:8080/ in your web browser

@krzysztofspilka
Copy link
Member

@warpech thanks for help, I'm on it.

@krzysztofspilka
Copy link
Member

@bulaj I can't tell much about the quality of the code, but from the UX/UI standpoint, there are some issues that we should fix before rolling this out. See the list below.

  • An empty cell in the column "Progress" is represented by a 100% stacked bar chart. Test: click on any cell in the column "Progress" and then press DELETE. Alternatively, open the column menu and choose the option "Clear column".
  • All keyboard shortcuts from this list: https://handsontable.com/docs/keyboard-shortcuts/#edition-keyboard-shortcuts should be available for both the "Progress" and "Rating" columns.
  • I can paste non-numeric values to both the "Progress" and "Rating" columns, and apparently the renderer will try to handle them. Try pasting 12394-3841-34. When you open the editor of such a cell it is empty.

@bulaj
Copy link
Author

bulaj commented Sep 28, 2022

@krzysztofspilka 1 and 3 should be fixed now.

Copy link
Member

@warpech warpech left a comment

Choose a reason for hiding this comment

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

Partial review. @jansiegel we will need to finish this.

]
];
export const data = [{
0: false,
Copy link
Member

Choose a reason for hiding this comment

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

This entry is super confusing, I think we need to refactor it or remove it (is it even used)?

@@ -46,24 +47,25 @@ const App = () => {
beforeRenderer={addClassesToRows}
afterGetRowHeader={drawCheckboxInRowHeaders}
afterOnCellMouseDown={changeCheckboxCell}
beforePaste={omitNonNumericPaste}
Copy link
Member

Choose a reason for hiding this comment

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

This is to achieve the following requirement:

I can paste non-numeric values to both the "Progress" and "Rating" columns, and apparently the renderer will try to handle them. Try pasting 12394-3841-34. When you open the editor of such a cell it is empty.

I think that this implementation is not as good as it could be. The best way to disallow certain inputs is to use a validator function and allowInvalid: false configuration option. This is how e.g. date picker does it.

@krzysztofspilka krzysztofspilka removed their request for review October 24, 2022 19:20
Copy link
Member

@jansiegel jansiegel left a comment

Choose a reason for hiding this comment

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

@maciejbo-handsontable
I'm not sure what is the exact scope of this PR. Could you list the requirements that are supposed to be met here?
The PR description mentions only making the progress and rating columns editable, but the PR you previously used to make changes was described vaguely as improve React demo.

That being said, I've looked at the demo after the modifications introduced by the PR and found these:

  1. This PR modifies the data used in the example. After the changes, the dataset consists of list of 5 items duplicated five times. I don't think demos in other frameworks do that. Was this change intentional?
  2. The Progress column allows entering non-numeric data, which results in the progress bar being displayed as 100%. Works the same with pasted data.
  3. The Rating column doesn't accept non-numeric data when editing but does accept pasted non-numeric data, which results in the cell being cleared.
  4. The demo contains some logic which I'm assuming was meant to horizontally align the header contents, but it targets only columns 9, 10 and 12 and there are no such columns in this example.
  5. The state of the row header checkboxes is stored at (row, "0") coordinates, which I find a bit weird.

If any of them is outside this task's scope, let me know.

@maciejbo-handsontable
Copy link
Contributor

maciejbo-handsontable commented Feb 4, 2023

There are still some unanswered questions, @adamu-handsontable, could you clarify the scope of this task?

Hey, what I can say is I was asked to "finish this PR which title says >editing options for prgress and rating<" and with that being said I was trying not to touch what was not necessary.

1. This PR modifies the data used in the example. After the changes, the dataset consists of 5 items duplicated five times. This changes the way the table looks, and if it was ever synchronized to the `visual-tests` demo sets (which I'm guessing it will at some point?) will break the test scenarios. [[original comment](https://github.com/handsontable/handsontable/pull/9935#pullrequestreview-1277235908)]

With first paragraph being said - normally I wouldn't touch this thing, but I needed to implement some related stuff, so I changed this entire file cause in my opinion it would be easier to change in future 5 places instead of 50 - but now, cause of your next points, I brought previous version back.

2. The demo contains some logic which I'm assuming was meant to align the header contents horizontally, but it targets only columns 9, 10, and 12 - and there are no such columns in this example. [[original comment](https://github.com/handsontable/handsontable/pull/9935#pullrequestreview-1277235908)]

If I understand your message correctly, the same thing exists in rest of demos also and was brought here by guy who started this thing before me - I wouldn't know what was the reason, maybe some hidden functionality. Without this part what I see still works, but need confirmation if I have to do something with that in this PR.

3. The state of the row header checkboxes is stored at (row, "0") coordinates, which I find a bit weird. [[original comment](https://github.com/handsontable/handsontable/pull/9935#pullrequestreview-1277235908)]

As above - If I understand your message correctly, the same thing exists in rest of demos also. Need confirmation if I have to do something with that in this PR.

4. When comparing the demo from this PR and the demo from `develop`, they're different not only because of the modified dataset, but also:
   
   * The `develop` demo has some rows pre-selected
   * The `develop` demo has some checkboxes from the column `In stock` unchecked by default
   
   Should they be unified?

Hey, that's true - I think they should be and they are unified already.

5. We could work on the progress bar and star renderers/editors further, for example, limit the input to a specific range etc (currently, entering a value of 10000 will successfully save it to the edited cell), but, again, I don't know how much detailed are they supposed to be.

this need to be confirmed by @adamu-handsontable , but what I can say is that @krzysztofspilka tested this thing before pushing here and didn't raise this point.

@adamu-handsontable
Copy link

As a result of this task I'd like to have a ready-to-use example with editable Progress and Rating. I see that there are some changes which are not required to achieve it. The original PR was done some time ago and got probably outdated. Our basis is the current example.

  1. Keep the array of object type structure, but make data equivalent to current example from develop. Change order of columns to match the current example from develop.
  2. If there no such columns, then it seems not necessary, please check if it is not required and if so, remove it.
  3. Yes this is strange, please change it to something more meaningful like: isChecked and adjust drawCheckboxInRowHeaders and changeCheckboxCell and any other function that uses it.
  4. Yes, they should be unified and adjusted to match current develop
  5. Progress bar should accept the range of Floats from 0 to 100. Ratings should accept Integers from 1 to 5.

Copy link
Member

@jansiegel jansiegel left a comment

Choose a reason for hiding this comment

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

I think all my previous points have been addressed, but one of @adamu-handsontable's points is missing:

Progress bar should accept the range of Floats from 0 to 100. Ratings should accept Integers from 1 to 5.

So I'm approving this PR and passing the review of that one point to @adamu-handsontable .

Comment on lines 8 to 9
export const ProgressBarRenderer = (props: HandsontableProps) => {
if (props.cellProperties.valid !== false) {
Copy link
Member

@jansiegel jansiegel Feb 16, 2023

Choose a reason for hiding this comment

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

@maciejbo-handsontable
I found one additional issue with the demo - when you pass invalid data for the progress bar or stars columns, they're not marked as invalid.
That happens because Handsontable doesn't trigger validation by default when loading data.
To get around it it, you can manually trigger the validator if it wasn't triggered already.

Take a look at my suggestion, and if you think it works all right, could you implement it for the stars renderer as well?

Suggested change
export const ProgressBarRenderer = (props: HandsontableProps) => {
if (props.cellProperties.valid !== false) {
export const ProgressBarRenderer = (props: HandsontableProps) => {
let isValid = props.cellProperties.valid;
// Run the validator for the cell at initialization.
if (isValid === void 0) {
(props.cellProperties.validator as Function)(props.value, (isValueValid: boolean) => {
isValid = isValueValid;
});
}
if (isValid === true) {

@jansiegel jansiegel mentioned this pull request Feb 16, 2023
12 tasks
@adamu-handsontable
Copy link

Let's skip the validation of stars and progress for now. We'll do that in a separate PR later if necessary.

jansiegel
jansiegel previously approved these changes Feb 16, 2023
Copy link
Contributor

@wszymanski wszymanski left a comment

Choose a reason for hiding this comment

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

I have some suggestions. I'll test example after changes in code.

if (cellProperties.instance.getDataAtRowProp(row, "0")) {
const rowData = cellProperties.instance.getSourceDataAtRow(row) as RowObject;

if (!!rowData?.checked) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!!rowData?.checked) {
if (rowData?.checked !== true) {

const rowData = this.getSourceDataAtRow(row) as RowObject;

input.type = 'checkbox';
input.checked = !!rowData?.checked;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
input.checked = !!rowData?.checked;
input.checked = rowData?.checked === true;

Comment on lines +1106 to +1108
export const MESSAGE = {
BAD_VALUE: '#bad-value#'
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to introduce this variable using object?

Suggested change
export const MESSAGE = {
BAD_VALUE: '#bad-value#'
};
export const BAD_VALUE_MESSAGE = '#bad-value#';

Comment on lines +22 to +27
// Run the validator for the cell at initialization.
if (isValid === void 0) {
(props.cellProperties.validator as Function)(props.value, (isValueValid: boolean) => {
isValid = isValueValid;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as in ProgressBar.tsx.

Comment on lines +22 to +27
// Run the validator for the cell at initialization.
if (isValid === void 0) {
(cellProperties.validator as Function)(value, (isValueValid: boolean) => {
isValid = isValueValid;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe its worth to move up method, beyond the renderer declaration, to not repeat function creation and make it more clear by naming it. Suggestion up to you.

@krzysztofspilka
Copy link
Member

@wszymanski as discussed, you will be assigned to this task with someone else from the Dev team as reviewer. Please accept all your remarks to the code. Let's treat this as a work in progress, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs: Tools Issues related to Handsontable's documentation tools (VuePress, deployment, scripts etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Progress and Rating columns should be editable in the main demo
7 participants