-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Conversation
@@ -712,18 +712,13 @@ export function getThemedComponents(theme: Theme): { components: Theme['componen | |||
defaultProps: { |
There was a problem hiding this comment.
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
}, []); | ||
|
||
const filteredElements = React.useMemo(() => { | ||
return elements.filter((elem: any) => |
There was a problem hiding this comment.
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
return elements.filter((elem: any) => | |
return elements.filter((element: any) => | |
element.name.toLowerCase().includes(searchText.toLowerCase()), |
}, [elements, searchText]); | ||
|
||
return [ | ||
<TextField |
There was a problem hiding this comment.
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 🤷
There was a problem hiding this comment.
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
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? |
packages/toolpad-app/src/theme.ts
Outdated
@@ -891,11 +886,31 @@ export function getThemedComponents(theme: Theme): { components: Theme['componen | |||
defaultProps: { | |||
margin: 'dense', | |||
}, | |||
styleOverrides: { | |||
root: { | |||
fontSize: defaultTheme.typography.pxToRem(13), |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, updated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screen.Recording.2022-12-01.at.11.53.27.PM.mov