Skip to content

InputChoiceSorting: Rework logic to work horizontally.#333

Draft
Frost000 wants to merge 4 commits into
chairemobilite:mainfrom
Frost000:Horizontal-Sorting-Options
Draft

InputChoiceSorting: Rework logic to work horizontally.#333
Frost000 wants to merge 4 commits into
chairemobilite:mainfrom
Frost000:Horizontal-Sorting-Options

Conversation

@Frost000
Copy link
Copy Markdown
Contributor

Rework logic to use better css classes and work with Flex to be able to set custom lengths freely horizontally. The horizontal limitation of the older logic is no more and should be more flexible.

Ex:
CustomSortSansLimites

Rework logic to use better css classes and work with Flex to be able to set custom lengths freely horizontally. The horizontal limitation of the older logic is no more and should be more flexible.
Copy link
Copy Markdown
Contributor

@tahini tahini left a comment

Choose a reason for hiding this comment

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

Thanks! seems to work, I,m no css expert, maybe @kaligrafy or @davidmurray can take a look. A few comments on the code though, and please run yarn format before submitting.

)
: null;

return (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Run yarn format on the code, this looks misaligned

// separate by columns if needed:
const columnedChoiceInputs = this.getColumnedChoices(choiceInputs);
if (this.props.widgetConfig.alignment === undefined || this.props.widgetConfig.alignment === 'vertical') {
const strCustomLabel = this.props.widgetConfig.customLabel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This statement is identical to the one after the if below (I think). If so, take it out of the if, above it, so you don't have to copy-paste it.

<span>{strCustomLabel}</span>
</label>
)}
<input
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This whole block is very similar to the one of the else, below this if. What is the difference? If it is only the class, you can do your if only in this one place, to avoid too much code duplication. If there are many differences, it is worth doing a separate block, with a comment explaining the difference. Otherwise, the code is harder to read as it is harder to understand the diff between the 2 blocks.

default:
return verticalByColumns(arr, 2);
}
return splitSort(arr, 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iiuc, what this PR changes also is that the alignment is now the responsibility of the widget/css instead of this group sorting, as before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

);
if (this.props.widgetConfig.alignment === undefined || this.props.widgetConfig.alignment === 'vertical') {
columnedChoiceInputs.push(
<div className="survey-question__input-radio-group-column" key={i}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here too, instead of the if-then-else, you can use

className=`survey-question__input-radio-group-{this.props.widgetConfig.alignment === undefined || this.props.widgetConfig.alignment === 'vertical' ? 'column' : 'row' }`

to avoid code duplication.

* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import { DESTRUCTION } from 'dns';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is probably unused?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove

)}
<input
type="text"
tabIndex={-1}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

peut-être que ce code va faire en sorte que l'élément de sera pas sélectionnable avec le clavier. Est-ce le cas?
Si oui il faudrait retirer tabIndex={-1}

Copy link
Copy Markdown
Contributor

@tahini tahini left a comment

Choose a reason for hiding this comment

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

You may want to add a few unit tests for either InputRadio or InputCheckbox to make sure the right css is picked: in a describe block, add 4 tests with each of the alignments types, mixed with custom alignement length and columns/rows, etc. It should be fairly easy to add snapshot tests and make sure the result is as expected.

* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import { DESTRUCTION } from 'dns';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove

{columnWidgets}
</div>
);
if (this.props.widgetConfig.alignment === undefined || this.props.widgetConfig.alignment === 'vertical') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, in this if, the undefined alignment is considered as vertical

: null;

const shouldDisplayAsRows =
this.props.widgetConfig.alignment === undefined || this.props.widgetConfig.alignment === 'auto';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this one, the undefined should be displayed as rows.

1- Is it normal or a mistake? If normal, please add a comment explaining why in the code
2- The alignment type says alignment?: 'vertical' | 'horizontal' | 'auto'. I think you should add a || for the horizontal case here.

@greenscientist
Copy link
Copy Markdown
Contributor

@tahini , should we incorporate this or forget about it?

@samuel-duhaime
Copy link
Copy Markdown
Collaborator

Do we have a use case for this? I don't see any.

@tahini
Copy link
Copy Markdown
Contributor

tahini commented Dec 17, 2024

We had a use case in od_mtl, see the issue linked at the beginning of the PR. I think we can keep it and re-work

@tahini tahini marked this pull request as draft April 9, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants