refactor(web): remove typescript
This commit is contained in:
@@ -2,44 +2,30 @@ import * as React from 'react';
|
||||
import throttle from 'lodash/throttle';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import { Box, Typography } from '@mui/material';
|
||||
|
||||
import { IJSONObject } from 'types';
|
||||
import JSONViewer from 'components/JSONViewer';
|
||||
import SearchInput from 'components/SearchInput';
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
import filterObject from 'helpers/filterObject';
|
||||
|
||||
type JSONViewerProps = {
|
||||
data: IJSONObject;
|
||||
};
|
||||
|
||||
const SearchableJSONViewer = ({ data }: JSONViewerProps) => {
|
||||
const [filteredData, setFilteredData] = React.useState<IJSONObject | null>(
|
||||
data
|
||||
);
|
||||
const SearchableJSONViewer = ({ data }) => {
|
||||
const [filteredData, setFilteredData] = React.useState(data);
|
||||
const formatMessage = useFormatMessage();
|
||||
|
||||
const onSearchChange = React.useMemo(
|
||||
() =>
|
||||
throttle((event: React.ChangeEvent) => {
|
||||
const search = (event.target as HTMLInputElement).value.toLowerCase();
|
||||
|
||||
throttle((event) => {
|
||||
const search = event.target.value.toLowerCase();
|
||||
if (!search) {
|
||||
setFilteredData(data);
|
||||
return;
|
||||
}
|
||||
|
||||
const newFilteredData = filterObject(data, search);
|
||||
|
||||
if (isEmpty(newFilteredData)) {
|
||||
setFilteredData(null);
|
||||
} else {
|
||||
setFilteredData(newFilteredData);
|
||||
}
|
||||
}, 400),
|
||||
[data]
|
||||
[data],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box my={2}>
|
||||
@@ -52,5 +38,4 @@ const SearchableJSONViewer = ({ data }: JSONViewerProps) => {
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchableJSONViewer;
|
Reference in New Issue
Block a user