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

Add SelectSearch #929

Merged
merged 5 commits into from
Nov 27, 2023
Merged

Add SelectSearch #929

merged 5 commits into from
Nov 27, 2023

Conversation

Oksamies
Copy link
Contributor

No description provided.

@Oksamies Oksamies changed the base branch from make-switch-form-usable to master November 24, 2023 19:32
@Oksamies Oksamies requested a review from anttimaki November 24, 2023 19:39
@Oksamies Oksamies changed the base branch from master to multi-select-search November 24, 2023 19:42
@Oksamies Oksamies force-pushed the multi-select-search branch from 94c0e37 to c2ff54f Compare November 24, 2023 19:44
@Oksamies Oksamies changed the base branch from multi-select-search to master November 24, 2023 20:57
Copy link
Contributor

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

Rejecting because our SelectSearch doesn't implement the Search part at all. Should be a quick fix?

Also worth noting that (at least some of) the issues raised on the review of #919 apply here too due to the copy-paste implementation.

} = useController({ name });

return (
<>
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 make sense to use div here? E.g. with flex the error span can get placed oddly. Just thinking aloud here, not sure if it's necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant replacing this <> fragment with a div, not the <span> inside. Now all the potential problems apply to that <div> as well since it's going to be rendered as a sibling to the <SelectSearch>

import { isNode } from "../../utils/type_guards";

type Props = {
options: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should use the same kind of "label & value" object as the multiselect, both for consistency and ease-of-use when working with options provided by the backend. Or is there some specific reason for going string-only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went for the string-only, solely for simplicity. Though I'd keep it string-only for now and edit the component, once the label value pair is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's your call. My two cents is that the simplicity that is achieved by using just strings seems pretty trivial. The work that is required to redo the interface once the component is in use in multiple places seems like a higher price to pay.

* Cyberstorm SelectSearch component
* TODO: Better keyboard navigation
*/
export const SelectSearch = React.forwardRef<HTMLInputElement, Props>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Lot of code repetition going on here. Did you consider that one of the selects should extend the other, or both extend some base implementation? I.e. do it under the hood, so that we would still export two different components, with similar (not necessarily identical) props. I'm asking because at a quick glance the only difference is that in single-select the add functions overrides the previous value instead of pushing it to the list.

Sometimes having separate components will be better for keeping the implementations simple and making changes easy, so it's not wrong to do so here. But in this case the similarities are pretty comprehensive, so using a different approach could make sense. "More art than science" kinda thing, really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep it as a separate component for now. (so no extending)

The reasoning is that; SelectSearch isn't even up to design specs and is kind of an "a component that works for now", so I don't want to invest too much time into refining this, until we've decided to either improve this or scrap it.

Also in general I've been trying to not make spaghetti and keep everything separated, so it's easier to refactor later. Even if it means we'll have a lot of similar code in different places.

Copy link
Contributor

Choose a reason for hiding this comment

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

Again your call, but please don't assume that the only two options on the table are "spaghetti" and "separated". Also properly done reuse can actually make future refactoring easier, not harder. Case in point: fixing the issues in other PR requires remembering to do the changes in both components.

@Oksamies Oksamies force-pushed the add-select-search branch 2 times, most recently from 9de4897 to a7df0b5 Compare November 27, 2023 14:28
} = useController({ name });

return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant replacing this <> fragment with a div, not the <span> inside. Now all the potential problems apply to that <div> as well since it's going to be rendered as a sibling to the <SelectSearch>

import { isNode } from "../../utils/type_guards";

type Props = {
options: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

It's your call. My two cents is that the simplicity that is achieved by using just strings seems pretty trivial. The work that is required to redo the interface once the component is in use in multiple places seems like a higher price to pay.

* Cyberstorm SelectSearch component
* TODO: Better keyboard navigation
*/
export const SelectSearch = React.forwardRef<HTMLInputElement, Props>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Again your call, but please don't assume that the only two options on the table are "spaghetti" and "separated". Also properly done reuse can actually make future refactoring easier, not harder. Case in point: fixing the issues in other PR requires remembering to do the changes in both components.

>
{options
.filter((option) =>
option.toLowerCase().includes(search.toLowerCase())
Copy link
Contributor

Choose a reason for hiding this comment

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

This will retain the selected value in the dropdown. Pointing it out since it differs from how the MultiSelectSearch works. Is this intentional and how we want these components to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say yes, we want the selected to be there, though an indicator on the selected item might be great. I'll come back to this after merging and rebasing the bigger PR 👍

@Oksamies Oksamies merged commit d3a1d8f into master Nov 27, 2023
17 checks passed
@Oksamies Oksamies deleted the add-select-search branch November 27, 2023 15:19
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.

2 participants