-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: search filter&highlight option 추가
+ copy&paste 마이너이슈 수정
- Loading branch information
Showing
21 changed files
with
229 additions
and
70 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
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,8 @@ | ||
import fetch from 'electron-fetch'; | ||
|
||
export const urlToBuffer = async (url: string) => { | ||
const response = await fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
const buffer = Buffer.from(arrayBuffer); | ||
return buffer; | ||
}; |
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
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,66 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import MuiCheckbox from '@material-ui/core/Checkbox'; | ||
import MuiFormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
useDispatch, | ||
useSelector, | ||
} from 'react-redux'; | ||
|
||
import tableActions from 'store/table/actions'; | ||
import { RootState } from 'store/types'; | ||
|
||
const FormControlLabel = withStyles((theme) => ({ | ||
root: { | ||
margin: theme.spacing(-1), | ||
marginBottom: theme.spacing(1), | ||
display: 'flex', | ||
}, | ||
}))(MuiFormControlLabel); | ||
|
||
const Checkbox = withStyles(() => ({ | ||
root: { | ||
width: 36, | ||
height: 36, | ||
}, | ||
}))(MuiCheckbox); | ||
|
||
const selector = ({ table: { searchSetting } }: RootState) => searchSetting; | ||
|
||
const Search: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
const settings = useSelector(selector); | ||
|
||
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
const nextSetting = { | ||
...settings, | ||
[e.target.name]: e.target.checked, | ||
}; | ||
dispatch(tableActions.setSearchSetting(nextSetting)); | ||
}, [dispatch, settings]); | ||
|
||
return ( | ||
<div> | ||
{Object.entries(settings).map(([key, value]) => ( | ||
<FormControlLabel | ||
key={`Preference-Search-${key}`} | ||
control={( | ||
<Checkbox | ||
color='primary' | ||
name={key} | ||
value={value} | ||
checked={value} | ||
onChange={handleChange} | ||
/> | ||
)} | ||
label={t(key)} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Search; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
|
||
import { shallowEqual, useSelector } from 'react-redux'; | ||
import { TableCellProps } from 'react-virtualized'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
import { RootState } from 'store/types'; | ||
|
||
type Props = Pick<TableCellProps, 'cellData'>; | ||
|
||
const selector = ({ table: { searchQuery, searchSetting: { shouldHighlight } } }: RootState) => ({ | ||
searchQuery, | ||
shouldHighlight, | ||
}); | ||
|
||
export const highlight = (cellData: Props['cellData'], search: string) => { | ||
if (typeof cellData !== 'string' || !search.length) { | ||
return { cellData: '', matched: [], re: '' }; | ||
} | ||
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
const re = new RegExp(escapedSearch, 'gi'); | ||
const matched = [...cellData.matchAll(re)]; | ||
return { cellData, re, matched }; | ||
}; | ||
|
||
const CellText: React.FC<Props> = ({ cellData = '' }) => { | ||
const { searchQuery: search, shouldHighlight } = useSelector(selector, shallowEqual); | ||
const { cellData: typedCellData, re, matched } = highlight(cellData, search); | ||
|
||
if (matched.length === 0 || !shouldHighlight) { | ||
return cellData; | ||
} | ||
return typedCellData.split(re).map((item, i) => i === 0 ? item : ( | ||
<React.Fragment key={`${search}-${item}-${uuid()}`}> | ||
<mark>{matched[i - 1][0]}</mark> | ||
{item} | ||
</React.Fragment> | ||
)); | ||
|
||
}; | ||
|
||
export default CellText; |
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
Oops, something went wrong.