etr2460 commented on a change in pull request #11854: URL: https://github.com/apache/incubator-superset/pull/11854#discussion_r536331077
########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( Review comment: I think we prefer `Record<string, any>` to object for typescript ########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( + <CopyToClipboard + text={data ? prepareCopyToClipboardTabularData(data) : ''} + wrapped={false} + copyNode={ + <CopyButton buttonSize="xs"> + <i className="fa fa-clipboard" /> + </CopyButton> + } + /> +); + +export const FilterInput = ({ + onChangeHandler, +}: { + onChangeHandler(filterText: string): void; +}) => { + const debouncedChangeHandler = debounce(onChangeHandler, 500); + return ( + <FormControl + placeholder={t('Search')} + bsSize="sm" + onChange={(event: any) => { + const filterText = event.target.value; + debouncedChangeHandler(filterText); + }} + /> + ); +}; + +export const RowCount = ({ data }: { data: object[] }) => ( + <RowCountLabel rowcount={data?.length ?? 0} suffix={t('rows retrieved')} /> +); + +export const useFilteredTableData = (filterText: string, data?: object[]) => Review comment: same comment here about the typing of object ########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( + <CopyToClipboard + text={data ? prepareCopyToClipboardTabularData(data) : ''} Review comment: if data is always an object, then this check shouldn't be needed ########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( + <CopyToClipboard + text={data ? prepareCopyToClipboardTabularData(data) : ''} + wrapped={false} + copyNode={ + <CopyButton buttonSize="xs"> + <i className="fa fa-clipboard" /> + </CopyButton> + } + /> +); + +export const FilterInput = ({ + onChangeHandler, +}: { + onChangeHandler(filterText: string): void; +}) => { + const debouncedChangeHandler = debounce(onChangeHandler, 500); + return ( + <FormControl + placeholder={t('Search')} + bsSize="sm" + onChange={(event: any) => { + const filterText = event.target.value; + debouncedChangeHandler(filterText); + }} + /> + ); +}; + +export const RowCount = ({ data }: { data: object[] }) => ( + <RowCountLabel rowcount={data?.length ?? 0} suffix={t('rows retrieved')} /> +); + +export const useFilteredTableData = (filterText: string, data?: object[]) => + useMemo(() => { + if (!data?.length) { + return []; + } + const formattedData = applyFormattingToTabularData(data); + return formattedData.filter((row: object) => Review comment: same comment here about the typing of object ########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( + <CopyToClipboard + text={data ? prepareCopyToClipboardTabularData(data) : ''} + wrapped={false} + copyNode={ + <CopyButton buttonSize="xs"> + <i className="fa fa-clipboard" /> + </CopyButton> + } + /> +); + +export const FilterInput = ({ + onChangeHandler, +}: { + onChangeHandler(filterText: string): void; +}) => { + const debouncedChangeHandler = debounce(onChangeHandler, 500); + return ( + <FormControl + placeholder={t('Search')} + bsSize="sm" + onChange={(event: any) => { + const filterText = event.target.value; + debouncedChangeHandler(filterText); + }} + /> + ); +}; + +export const RowCount = ({ data }: { data: object[] }) => ( Review comment: same comment here about the typing of object ########## File path: superset-frontend/src/explore/components/DataTableControl.tsx ########## @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { FormControl } from 'react-bootstrap'; +import debounce from 'lodash/debounce'; +import Button from 'src/components/Button'; +import { + applyFormattingToTabularData, + prepareCopyToClipboardTabularData, +} from 'src/utils/common'; +import CopyToClipboard from 'src/components/CopyToClipboard'; +import RowCountLabel from './RowCountLabel'; + +export const CopyButton = styled(Button)` + font-size: ${({ theme }) => theme.typography.sizes.s}px; + + // needed to override button's first-of-type margin: 0 + && { + margin: 0 ${({ theme }) => theme.gridUnit * 2}px; + } + + i { + padding: 0 ${({ theme }) => theme.gridUnit}px; + } +`; + +export const CopyToClipboardButton = ({ data }: { data: object }) => ( + <CopyToClipboard + text={data ? prepareCopyToClipboardTabularData(data) : ''} + wrapped={false} + copyNode={ + <CopyButton buttonSize="xs"> + <i className="fa fa-clipboard" /> + </CopyButton> + } + /> +); + +export const FilterInput = ({ + onChangeHandler, +}: { + onChangeHandler(filterText: string): void; +}) => { + const debouncedChangeHandler = debounce(onChangeHandler, 500); + return ( + <FormControl + placeholder={t('Search')} + bsSize="sm" + onChange={(event: any) => { + const filterText = event.target.value; + debouncedChangeHandler(filterText); + }} + /> + ); +}; + +export const RowCount = ({ data }: { data: object[] }) => ( + <RowCountLabel rowcount={data?.length ?? 0} suffix={t('rows retrieved')} /> +); + +export const useFilteredTableData = (filterText: string, data?: object[]) => + useMemo(() => { + if (!data?.length) { + return []; + } + const formattedData = applyFormattingToTabularData(data); + return formattedData.filter((row: object) => + Object.values(row).some(value => + value.toString().toLowerCase().includes(filterText.toLowerCase()), + ), + ); + }, [data, filterText]); + +export const useTableColumns = (data?: object[]) => Review comment: same comment here about the typing of object (i'm going to stop making these, but please clean up the rest, thanks!) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
