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 search to the apps overview #1402

Merged
merged 19 commits into from
Jan 6, 2023
Merged

Add search to the apps overview #1402

merged 19 commits into from
Jan 6, 2023

Conversation

bharatkashyap
Copy link
Member

  • Visual demonstration
Screen.Recording.2022-12-01.at.11.53.27.PM.mov

@bharatkashyap bharatkashyap added the design: ux Design label Dec 1, 2022
@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 December 1, 2022 18:24 — with Render Abandoned
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 1, 2022 18:25 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 1, 2022 18:37 — with Render Destroyed
@@ -712,18 +712,13 @@ export function getThemedComponents(theme: Theme): { components: Theme['componen
defaultProps: {
Copy link
Member Author

@bharatkashyap bharatkashyap Dec 1, 2022

Choose a reason for hiding this comment

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

Some minor changes to the theme to make the search input look aligned with the rest of the UI

@bharatkashyap bharatkashyap requested a review from a team December 2, 2022 07:27
}, []);

const filteredElements = React.useMemo(() => {
return elements.filter((elem: any) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember in some other PR it was mentioned that we should not use abbrevations and instead use full name

Suggested change
return elements.filter((elem: any) =>
return elements.filter((element: any) =>
element.name.toLowerCase().includes(searchText.toLowerCase()),

}, [elements, searchText]);

return [
<TextField
Copy link
Contributor

@bytasv bytasv Dec 2, 2022

Choose a reason for hiding this comment

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

This pattern of returning both react component and filtered values as a pair looks pretty uncommon. Since the logic is so trivial, I'd personally consider keeping component itself inside the main component.

To separate filtering/searching logic, maybe we could keep this useSearch hook, but instead of returning component we would return only filtered results. Then the input for hook would be allApps, searchValue:

const [searchValue, setSearchValue] = useState('')
const filteredApps = useSearch(apps, searchValue)
...
<TextField key='search' value={searchValue} onChange={(event) => setSearchValue(event.target.value)}

The only reason right now why I'd keep this hook separate from main code is to anticipate possibility to use querying against API in the future maybe, but maybe even that's not needed 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Don't create hooks until a clear pattern of reuse emerges. The logic can go straight into toolpad/Apps/index.ts. We will extract reusable patterns once we align implementation between apps and connections

@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 December 6, 2022 07:18 — with Render Abandoned
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 6, 2022 07:18 — with Render Destroyed
@prakhargupta1
Copy link
Member

Q: In UX review last week, we briefly discussed showing apps in a table, in case we do that will it impact this search bar?

@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 December 9, 2022 08:35 — with Render Abandoned
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 9, 2022 08:36 — with Render Destroyed
@@ -891,11 +886,31 @@ export function getThemedComponents(theme: Theme): { components: Theme['componen
defaultProps: {
margin: 'dense',
},
styleOverrides: {
root: {
fontSize: defaultTheme.typography.pxToRem(13),
Copy link
Member

@Janpot Janpot Dec 13, 2022

Choose a reason for hiding this comment

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

Will it be a problem that changes made for search input will affect all inputs?

Perhaps we should start with just wrapping a TextField?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, updated

Copy link
Member

Choose a reason for hiding this comment

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

But this is just the same but applying to all TextFields. Is there a good reason that this has to be built inside of the theme overrides? I mean, there are a lot of non-search TextFields.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would say there's no urgent reason to do this, we could also only apply this styling to this particular TextField

At the same time, I also see no real drawbacks of making all text fields more dense and conserving some space, but perhaps that can wait till more comprehensive UI work.

I'll update to only apply styling to this TextField

@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 December 13, 2022 13:09 — with Render Abandoned
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 16, 2022 10:35 — with Render Destroyed
@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 December 21, 2022 06:17 — with Render Abandoned
@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 December 21, 2022 06:18 — with Render Destroyed
@oliviertassinari oliviertassinari requested a deployment to add-home-search - toolpad-db PR #1402 January 3, 2023 09:40 — with Render Abandoned
@bharatkashyap bharatkashyap requested review from a team and removed request for Janpot January 3, 2023 10:38
Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

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

Looks solid!
Just left some comments about the styles, but it shouldn't be too much.

@@ -738,7 +751,33 @@ export default function Home() {
Apps
</Typography>
<FlexFill />
<Button onClick={() => setCreateDialogOpen(true)}>Create New</Button>
<TextField
Copy link
Member

Choose a reason for hiding this comment

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

Is there really no other way to style this text field as we want to without these a bit ugly overrides? Can't we do it with just regular props? But I understand that if the intended design is imposing certain things there might be no other way to do it.

I also noticed that the icon and the text are slightly misaligned vertically, but maybe most people wouldn't even notice:
Screenshot 2023-01-04 at 10 24 54

Copy link
Member

Choose a reason for hiding this comment

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

At least we should extract these styles to a variable above the component, so that we don't mix them with the JSX logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there really no other way to style this text field as we want to without these a bit ugly overrides?

In the beginning I added these overrides to the default theme so as to make all text fields look more dense and match the buttons in the theme, but in the discussion here we decided to go ahead with styling just this text field for now.

At least we should extract these styles to a variable above the component, so that we don't mix them with the JSX logic.

Agreed, I'll do this.

I also noticed that the icon and the text are slightly misaligned vertically, but maybe most people wouldn't even notice:

Agreed, this was much less noticeable in the dark theme. I'll fix this

setSearchText(event.target.value);
}, []);

const filteredApps = React.useMemo(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this works well, but as a short-term solution - long term we should have pagination when loading a list of apps, and the search should filter the results server-side.

Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

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

Thanks for the changes Bharat, the test looks good too!

This input is still not aligned though:
Screenshot 2023-01-05 at 12 26 17

I'll approve this already anyway as that's just a small detail.

@oliviertassinari oliviertassinari temporarily deployed to add-home-search - toolpad PR #1402 January 5, 2023 18:22 — with Render Destroyed
@bharatkashyap bharatkashyap merged commit d541e97 into master Jan 6, 2023
@bharatkashyap bharatkashyap deleted the add-home-search branch January 6, 2023 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants