-
Notifications
You must be signed in to change notification settings - Fork 16
refactor(query): Refactor QueryInputBox into a dedicated component from SearchTabPanel. #196
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.css
This file contains hidden or 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,33 @@ | ||
.query-input-box-with-progress { | ||
/* JoyUI has a rounding issue when calculating the Textarea width, causing it to overflow its | ||
container. */ | ||
margin-right: 1px; | ||
} | ||
|
||
.query-input-box { | ||
flex-direction: row !important; | ||
border-radius: 0 !important; | ||
} | ||
|
||
.query-option-button { | ||
width: 1.5rem !important; | ||
min-width: 0 !important; | ||
height: 1.5rem !important; | ||
min-height: 0 !important; | ||
|
||
font-family: Inter, sans-serif !important; | ||
} | ||
|
||
.query-input-box-textarea { | ||
width: 0; | ||
} | ||
|
||
.query-input-box-end-decorator { | ||
display: block !important; | ||
margin-block-start: 0 !important; | ||
} | ||
|
||
.query-input-box-linear-progress { | ||
/* stylelint-disable-next-line custom-property-pattern */ | ||
--LinearProgress-radius: 0 !important; | ||
} |
120 changes: 120 additions & 0 deletions
120
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.tsx
This file contains hidden or 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,120 @@ | ||
import React, { | ||
useContext, | ||
useState, | ||
} from "react"; | ||
|
||
import { | ||
LinearProgress, | ||
Stack, | ||
Textarea, | ||
} from "@mui/joy"; | ||
|
||
import {StateContext} from "../../../../../contexts/StateContextProvider"; | ||
import { | ||
QUERY_PROGRESS_VALUE_MAX, | ||
QueryArgs, | ||
} from "../../../../../typings/query"; | ||
import {UI_ELEMENT} from "../../../../../typings/states"; | ||
import {isDisabled} from "../../../../../utils/states"; | ||
import ToggleIconButton from "./ToggleIconButton"; | ||
|
||
import "./QueryInputBox.css"; | ||
|
||
|
||
/** | ||
* Provides a text input and optional toggles for submitting search queries. | ||
* | ||
* @return | ||
*/ | ||
const QueryInputBox = () => { | ||
const {queryProgress, startQuery, uiState} = useContext(StateContext); | ||
|
||
const [queryString, setQueryString] = useState<string>(""); | ||
const [isCaseSensitive, setIsCaseSensitive] = useState<boolean>(false); | ||
const [isRegex, setIsRegex] = useState<boolean>(false); | ||
|
||
const handleQuerySubmit = (newArgs: Partial<QueryArgs>) => { | ||
startQuery({ | ||
isCaseSensitive: isCaseSensitive, | ||
isRegex: isRegex, | ||
queryString: queryString, | ||
...newArgs, | ||
}); | ||
}; | ||
|
||
const handleQueryInputChange = (ev: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
setQueryString(ev.target.value); | ||
handleQuerySubmit({queryString: ev.target.value}); | ||
}; | ||
|
||
const handleCaseSensitivityButtonClick = () => { | ||
handleQuerySubmit({isCaseSensitive: !isCaseSensitive}); | ||
setIsCaseSensitive(!isCaseSensitive); | ||
}; | ||
|
||
const handleRegexButtonClick = () => { | ||
handleQuerySubmit({isRegex: !isRegex}); | ||
setIsRegex(!isRegex); | ||
}; | ||
Henry8192 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const isQueryInputBoxDisabled = isDisabled(uiState, UI_ELEMENT.QUERY_INPUT_BOX); | ||
|
||
return ( | ||
<div className={"query-input-box-with-progress"}> | ||
<Textarea | ||
className={"query-input-box"} | ||
maxRows={7} | ||
placeholder={"Search"} | ||
size={"sm"} | ||
endDecorator={ | ||
<Stack | ||
direction={"row"} | ||
spacing={0.25} | ||
> | ||
<ToggleIconButton | ||
className={"query-option-button"} | ||
disabled={isQueryInputBoxDisabled} | ||
isChecked={isCaseSensitive} | ||
size={"sm"} | ||
tooltipTitle={"Match case"} | ||
variant={"plain"} | ||
onClick={handleCaseSensitivityButtonClick} | ||
> | ||
Aa | ||
</ToggleIconButton> | ||
|
||
<ToggleIconButton | ||
className={"query-option-button"} | ||
disabled={isQueryInputBoxDisabled} | ||
isChecked={isRegex} | ||
size={"sm"} | ||
tooltipTitle={"Use regular expression"} | ||
variant={"plain"} | ||
onClick={handleRegexButtonClick} | ||
> | ||
.* | ||
</ToggleIconButton> | ||
</Stack> | ||
} | ||
slotProps={{ | ||
textarea: { | ||
className: "query-input-box-textarea", | ||
disabled: isQueryInputBoxDisabled, | ||
}, | ||
endDecorator: {className: "query-input-box-end-decorator"}, | ||
}} | ||
onChange={handleQueryInputChange}/> | ||
<LinearProgress | ||
className={"query-input-box-linear-progress"} | ||
determinate={true} | ||
thickness={4} | ||
value={queryProgress * 100} | ||
color={QUERY_PROGRESS_VALUE_MAX === queryProgress ? | ||
"success" : | ||
"primary"}/> | ||
</div> | ||
); | ||
}; | ||
|
||
junhaoliao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default QueryInputBox; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.