-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from Olog/CSSTUDIO-2220-search-initial-beta
Csstudio 2220 search initial beta
- Loading branch information
Showing
6 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Chip, InputAdornment, Stack } from "@mui/material"; | ||
import TextInput from "components/shared/input/TextInput"; | ||
import { ButtonDatePicker, DATE_FORMAT } from "components/shared/input/WizardDateInput"; | ||
import { forceUpdateSearchParams } from "features/searchParamsReducer"; | ||
import React from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
const SimpleSearch = () => { | ||
|
||
const searchParams = useSelector(state => state.searchParams); | ||
const dispatch = useDispatch(); | ||
|
||
const { control, handleSubmit, setValue, watch, getValues } = useForm({ | ||
defaultValues: { query: searchParams?.query, start: searchParams?.start }, | ||
values: { query: searchParams?.query, start: searchParams?.start } | ||
}); | ||
|
||
const dateValue = watch("start"); | ||
|
||
const onAccept = (momentDate) => { | ||
console.log({onAccept: momentDate}) | ||
setValue("start", momentDate.format(DATE_FORMAT)); | ||
onSubmit(getValues()); | ||
} | ||
const onReject = () => { | ||
setValue("start", null); | ||
onSubmit(getValues()); | ||
} | ||
|
||
const onSubmit = (data) => { | ||
console.log({onSubmit: data, searchParams}) | ||
const params = { | ||
...searchParams, | ||
...data | ||
} | ||
dispatch(forceUpdateSearchParams(params)); | ||
} | ||
|
||
return ( | ||
<Stack | ||
component="form" | ||
padding={1} | ||
gap={1} | ||
width="100%" | ||
onSubmit={handleSubmit(onSubmit)} | ||
> | ||
<TextInput | ||
control={control} | ||
name="query" | ||
label="Search" | ||
defaultValue="" | ||
fullWidth | ||
InputProps={{ | ||
endAdornment: | ||
<InputAdornment position="end"> | ||
<ButtonDatePicker | ||
onAccept={onAccept} | ||
ButtonFieldProps={{ | ||
inputProps: { | ||
"aria-label": `Select start date/time}` | ||
} | ||
}} | ||
/> | ||
</InputAdornment> | ||
}} | ||
/> | ||
<Stack flexDirection="row" justifyContent="flex-end"> | ||
{ | ||
dateValue ? <Chip label={dateValue} size="small" onDelete={onReject} /> : null | ||
} | ||
</Stack> | ||
</Stack> | ||
) | ||
}; | ||
|
||
export default SimpleSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import SimpleSearch from "./SimpleSearch"; | ||
|
||
export { SimpleSearch }; | ||
export default SimpleSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters