Repository navigation
feat: rating question type - #3637
global-prog wants to merge 31 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@global-prog thanks for the PR :) please add the AI section to the description if you used AI to generate this PR 👍🏻 some comments on the code itself: as this uses mostly the same logic as linear scale questions, we should re-use the existing extraSettings (especially Perhaps you could also add a screenshot/recording of how it works to the description so that the @nextcloud/designers could have a look at it without having to build it 👍🏻 |
|
Thanks! Done in the latest commit:
I've added the AI declaration to the description, and I'll add a screenshot of the editor and the filled-in form there as well. |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
|
@global-prog are you still working on this (and the other PRs) ? |
29ea986 to
4286aff
Compare
53cdd63 to
ac8fdb6
Compare
|
@Chartman123 I rebased this onto current main and added two fixes on top of your review commit:
I also checked the icon colours in the light, dark and both high contrast themes: stars use |
oh, my bad... I confused the two there 🙈 |
86c7ff1 to
018092d
Compare
018092d to
3a34498
Compare
d61940d to
d8cbf79
Compare
Moving the check of linear scale answers into validateScaleQuestion left out the check that an answer is a single value and not a boolean, so true was accepted as the answer 1 again. The shared check now has it back, for linear scales and ratings alike. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Every option of a rating was announced as "undefined of 5": t() fills in %n only when it is given a count, and the label passed none. Each option is now named by its own value, e.g. "3 of 5". Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The radios of a rating used the server's hidden-visually class, which moves them 10000px above and beside the question. Clicking an icon or tabbing to it focuses that radio, so the browser scrolled the form to its top and the rating left the screen. The radios now stay in place inside their icon, invisible and ignoring the pointer, the same way NcRadioGroupButton hides its own. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
A rating counts as predefined on the front end, so the results draw it as a chart, but it has no options. When answers were restored from a draft or loaded to edit a response, Submit kept only those values of a predefined question that match one of its options, which dropped every rating. Submitting such an edited response again then deleted an optional rating from it. Answer types now say whether they are answered on a scale. Restoring answers keeps the values of a scale question within its bounds, as it already did for the linear scale, and the results summary uses the same flag instead of naming both types. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The editor focuses the title of a question once it is added, copied or inserted, and offers a menu below each question to insert another one after it. A rating did neither: it gave the shared question code no root element to scroll to and focus, so focus was lost, and it did not pass on the insert slot, so the menu below it was missing. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
A required rating left empty failed the browser's own validation, which stops the submit before Forms checks the answers. Its message was tied to a radio placed off screen, and the rating's error note never showed. The rating now handles the invalid event like the other questions, so it shows "You must answer this question" and marks its radios invalid, pointing to that note. The radios also stay required once one is picked, so screen readers keep announcing the question as required, and the rating is described by the question's description. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Enter on a question moves the focus on through the form, and only Enter on the submit button sends it. A rating did not handle Enter itself, so the browser submitted the whole form as soon as Enter was pressed on one of its options, with any later questions still unanswered. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The picker for the highest rating in the question's menu had no accessible name: NcActionInput ties its label to an input of its own, not to the combobox it shows. It now gets the name the same way as the pickers of the linear scale. The radios for stars, hearts and thumbs up followed it without saying what they choose. A caption now names them as the icon of the rating. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
…ookup The clear button is gone, so a rating is only ever picked with a value from 1 up: onPick no longer handles 0, and the comments that still mentioned clearing are removed. The chosen icon set was checked against a list derived from the icon choices and then looked up in those choices again. It is now looked up once, with stars as the fallback, which also drops a cast and a non-null assertion. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Moving ANSWER_TYPES_DATETIME left a line holding only a tab and indented its entries one tab too deep, which the PHP coding standard rejects. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
An answer such as "05" passed the check of scale answers and was stored as sent. The results then counted it as a value of its own next to 5, and exports showed it as written. Answers to a linear scale or a rating now have to be the plain number. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The server took any text as the icon of a rating, while the editor only offers stars, hearts and thumbs up and draws stars for anything else, so an API client could store an icon that no one ever sees. The icon is now checked against the three choices, and the API description lists them. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The API documentation listed neither the rating question type nor its icon setting, and showed the highest value of a scale as a setting of the linear scale only. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The rating repeated its question title in a hidden legend. Like every other question, it now points to the title itself, which also announces the asterisk of a required question. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Checks the accessible names of a rating, that its answer comes back from a draft and when a response is edited, that Enter moves on instead of submitting, that a required rating left empty shows its error, and that a new rating question gets focus and an insert menu. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The translation tool reads a hint in a template only from the line of
the string or the line right above it, so the hint on "{value} of {max}"
never reached translators. The name is now built in the script, with
the hint right above the string.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
In the editor a rating is a disabled preview, so its cursor stays the default arrow, yet its icons still grew on hover as if one could be picked. They now keep their size there. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Clicking an icon focuses its radio, so :focus-within drew the focus ring around the clicked icon as well and kept it there until the focus moved on. The ring now follows :focus-visible, as in the actions and list items of @nextcloud/vue, so it shows when a rating is reached or changed with the keyboard. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Some comments added with the rating explained why the code is written the way it is. The check of the scale settings gets back the comment it has on main, the docblocks of validateScaleQuestion() and of the rating's validate() now say what they check, and the comments on the size of an icon and on the test case for optionsLowest are dropped. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Enter in a question moves the focus on through the form, but only the inputs that opted in got that behaviour, and only for a plain Enter. Shift+Enter or Alt+Enter on a rating, and any Enter in a grid cell or in the field of the answer "Other", still sent the whole form with later questions unanswered. The form now handles Enter itself for every input that would submit it. Ctrl+Enter still submits, and Enter keeps its default on buttons, text areas and inputs that already handled it. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Enter focused the next element of the form. When the next question was a rating, a linear scale or a multiple choice, that element is the fieldset of the question, which cannot take focus, so the focus stayed where it was. Inside a radio group, Enter moved to the next option of the same group instead of leaving the question. Enter now skips the other options of the same radio group and every element that does not take focus. Like Tab, it enters a radio group that already has a checked option at that option. It also skips the button that clears the form, which comes first among the buttons, so Enter in the last answer reaches the button that sends it instead of opening the dialog to clear all answers. Ctrl+Enter in any input submits the form, as browsers do not do so themselves. A held Enter acts only once. Its repeats walked the focus on to the button that sends the form and then pressed it, sending a half-filled form, so outside text areas they now do nothing. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The editor stores null for an extra setting that is back at its default, for example stars as the icon of a rating, and the API returned it as null. The API documentation does not allow null for these settings, so a client generated from it rejected such a question. Null values are now left out like false ones, so the setting reads as unset. The documented question types also lacked the rating. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The check of a linear scale or rating answer repeated the reading of normalizeNumericOptionId() clause by clause, and the two copies already disagreed: a JSON number such as 4.0 passed the scale check. The check now uses the helper, so such an answer is rejected like any other value that is not a whole number. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Since the rating points at its question title for its name, the preview in the editor had no name at all: the title and description it points at are only rendered in the answer view. In the editor the rating is named by the question text again. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The hover scale was set for every icon and then undone twice: once for the preview in the editor and once for reduced motion. Each override only won by specificity or by source order. The scale now applies only to an enabled rating without a preference for reduced motion, and only on devices that can hover, so a tapped icon on a touch screen does not stay enlarged. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Draw the icons of a rating at 34px and keep 16px between them, so the default five icons stay in one row on screens down to 320px wide. Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de> Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Jumps were merged before the rating question, so a rating had no jumps.
It now gets them as the linear scale does: each value of the rating
gets a row with the same select in the editor, and the jumps are
stored in extraSettings.goTo as {value, target}. A value without a
jump leads to the following question. Lowering the highest rating
removes the jumps of the values that are gone, reported in the
response header X-Forms-Adjusted, and copying or importing a form
drops them as well.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
ef71165 to
b1926e3
Compare
AndyScherzinger
left a comment
There was a problem hiding this comment.
Third and final review round, again with a focus on performance, accessibility, security, clean code and architecture, plus a check on a Nextcloud 36 instance built from this branch: the editor with the question menu and the jump targets, the submit view logged in, through a public link and embedded, and the results summary. axe-core 4.14 reports no violations for the rating in any of them; the only hits are inside the question menu (role="false", aria-checked on its labels, and <li> items in a list with role="dialog"), which come from @nextcloud/vue and appear in every question menu. Keyboard use works in all three submit contexts: Enter moves from a short answer into the rating and on to the next question, arrow keys and Space choose a value, Ctrl+Enter submits or focuses the required rating with its error, and Enter keeps its own meaning in the date picker and the dropdown. Neither Ctrl+Enter pressed twice nor a held Enter sends a response twice, as the form unmounts while it is sent. The server rejects "0", "8", "05", "5.0", " 5" and true as rating answers, and unknown icons and bounds in the settings.
The findings are inline. The fixes are fixups of the commits that introduced them, covered by two new rating e2e tests, and the updated branch is pushed. ESLint, Stylelint and the build pass, Prettier flags no file the base branch does not flag already, npm run typecheck reports the same errors with and without the fixes (it already fails for every question component, and CI does not run it), the PHP unit tests pass apart from the three UploadedFilesShareServiceTest cases that fail on Nextcloud 36, and the Playwright suite passes.
Assisted by Claude Code:claude-opus-5-5
Closes #2608.
Summary
A compact rating question, with stars, hearts or thumbs up, configurable from 2 to 10 icons (default 5).
A linear scale already covers 1..N, but renders as a row of radio buttons. A rating is the control people expect for "how would you rate this", takes far less width, and reads at a glance in the results.
Accessibility
Built from real radio inputs rather than clickable icons, so:
3 of 5) rather than as an unnamed radio--default-clickable-areasquare while the icon itself stays small — an icon-sized target is awkward to hit on a phoneprefers-reduced-motionStorage and validation
The answer is stored as the plain number, so results and CSV export need no special handling.
It is validated server-side as a whole number within the configured maximum rather than trusting the client. A rating carries no options, so it is checked on its own rather than as a predefined-option type.
Scope
maxRatingandratingIconlive in the existingextraSettingsFormsQuestionTypeis deliberately left alone, matching howlinearscale,rankingandcolorare already handled, soopenapi.jsonis unaffectedTesting
npm run lint,npm run stylelintandphp -lcleanmainwith no errorsHappy to adjust the default icon count, the icon set, or drop the hearts/thumbs options if you would rather keep it to stars.
🤖 AI (if applicable)