-
Notifications
You must be signed in to change notification settings - Fork 2
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 #270 from bento-platform/features/table-removal
refact!: table removal
- Loading branch information
Showing
54 changed files
with
1,071 additions
and
1,680 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Modal } from "antd"; | ||
|
||
const { confirm } = Modal; | ||
|
||
const genericConfirm = ({title, content, onOk, onCancel, ...rest}) => { | ||
confirm({ | ||
title: title, | ||
content: content, | ||
onOk: onOk, | ||
onCancel, | ||
...rest, | ||
}); | ||
}; | ||
|
||
export default genericConfirm; |
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,132 @@ | ||
import React, {useCallback, useMemo, useState} from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import { Button, Col, Row, Table, Typography } from "antd"; | ||
|
||
import PropTypes from "prop-types"; | ||
import { datasetPropTypesShape, projectPropTypesShape } from "../../propTypes"; | ||
import { clearDatasetDataType } from "../../modules/metadata/actions"; | ||
import { fetchDatasetDataTypesSummaryIfPossible } from "../../modules/datasets/actions"; | ||
import genericConfirm from "../ConfirmationModal"; | ||
import DataTypeSummaryModal from "./datatype/DataTypeSummaryModal"; | ||
import { nop } from "../../utils/misc"; | ||
|
||
const NA_TEXT = <span style={{ color: "#999", fontStyle: "italic" }}>N/A</span>; | ||
|
||
const DatasetDataTypes = React.memo( | ||
({isPrivate, project, dataset, onDatasetIngest}) => { | ||
const dispatch = useDispatch(); | ||
const datasetDataTypes = useSelector((state) => Object.values( | ||
state.datasetDataTypes.itemsById[dataset.identifier]?.itemsById)); | ||
const datasetSummaries = useSelector((state) => state.datasetSummaries.itemsById[dataset.identifier]); | ||
const isFetchingDataset = useSelector( | ||
(state) => state.datasetDataTypes.itemsById[dataset.identifier]?.isFetching); | ||
|
||
const [datatypeSummaryVisible, setDatatypeSummaryVisible] = useState(false); | ||
const [selectedDataType, setSelectedDataType] = useState(null); | ||
|
||
const selectedSummary = (selectedDataType !== null && datasetSummaries) | ||
? datasetSummaries[selectedDataType.id] | ||
: {}; | ||
|
||
const handleClearDataType = useCallback((dataType) => { | ||
genericConfirm({ | ||
title: `Are you sure you want to delete the "${dataType.label || dataType.id}" data type?`, | ||
content: "Deleting this means all instances of this data type contained in the dataset " + | ||
"will be deleted permanently, and will no longer be available for exploration.", | ||
onOk: async () => { | ||
await dispatch(clearDatasetDataType(dataset.identifier, dataType.id)); | ||
await dispatch(fetchDatasetDataTypesSummaryIfPossible(dataset.identifier)); | ||
}, | ||
}); | ||
}, [dispatch, dataset]); | ||
|
||
const showDatatypeSummary = useCallback((dataType) => { | ||
setSelectedDataType(dataType); | ||
setDatatypeSummaryVisible(true); | ||
}, []); | ||
|
||
const dataTypesColumns = useMemo(() => [ | ||
{ | ||
title: "Name", | ||
key: "label", | ||
render: (dt) => | ||
isPrivate ? ( | ||
<a onClick={() => showDatatypeSummary(dt)}> | ||
{dt.label ?? NA_TEXT} | ||
</a> | ||
) : dt.label ?? NA_TEXT, | ||
defaultSortOrder: "ascend", | ||
sorter: (a, b) => a.label.localeCompare(b.label), | ||
}, | ||
{ | ||
title: "Count", | ||
dataIndex: "count", | ||
render: (c) => (c ?? NA_TEXT), | ||
}, | ||
...(isPrivate ? [ | ||
{ | ||
title: "Actions", | ||
key: "actions", | ||
width: 230, | ||
render: (dt) => ( | ||
<Row gutter={10}> | ||
<Col span={12}> | ||
<Button | ||
icon="import" | ||
style={{ width: "100%" }} | ||
onClick={() => (onDatasetIngest || nop)(project, dataset, dt)} | ||
> | ||
Ingest | ||
</Button> | ||
</Col> | ||
<Col span={12}> | ||
<Button | ||
type="danger" | ||
icon="delete" | ||
disabled={ !dt.count || dt.count && dt.count === 0} | ||
onClick={() => handleClearDataType(dt)} | ||
style={{ width: "100%" }} | ||
> | ||
Clear | ||
</Button> | ||
</Col> | ||
</Row> | ||
), | ||
}, | ||
] : null), | ||
], [isPrivate, project, dataset, onDatasetIngest]); | ||
|
||
const onDataTypeSummaryModalCancel = useCallback(() => setDatatypeSummaryVisible(false), []); | ||
|
||
return ( | ||
<> | ||
<DataTypeSummaryModal | ||
dataType={selectedDataType} | ||
summary={selectedSummary} | ||
visible={datatypeSummaryVisible} | ||
onCancel={onDataTypeSummaryModalCancel} | ||
/> | ||
|
||
<Typography.Title level={4}> | ||
Data Types | ||
</Typography.Title> | ||
|
||
<Table | ||
bordered | ||
dataSource={datasetDataTypes} | ||
rowKey="id" | ||
columns={dataTypesColumns} | ||
loading={isFetchingDataset} | ||
/> | ||
</> | ||
); | ||
}); | ||
|
||
DatasetDataTypes.propTypes = { | ||
isPrivate: PropTypes.bool, | ||
project: projectPropTypesShape, | ||
dataset: datasetPropTypesShape, | ||
onDatasetIngest: PropTypes.func, | ||
}; | ||
|
||
export default DatasetDataTypes; |
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.