-
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 #357 from bento-platform/refact/func-explorer-search
refact(explorer): rewrite ExplorerSearchContent to be func
- Loading branch information
Showing
1 changed file
with
50 additions
and
62 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 |
---|---|---|
@@ -1,67 +1,55 @@ | ||
import React, {Component} from "react"; | ||
import {connect} from "react-redux"; | ||
import {Redirect, Route, Switch} from "react-router-dom"; | ||
import PropTypes from "prop-types"; | ||
import React, { useMemo } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { Redirect, Route, Switch } from "react-router-dom"; | ||
|
||
import {Layout, Menu, Skeleton} from "antd"; | ||
import { Layout, Menu, Skeleton } from "antd"; | ||
|
||
import SitePageHeader from "../SitePageHeader"; | ||
import {LAYOUT_CONTENT_STYLE} from "../../styles/layoutContent"; | ||
import ExplorerDatasetSearch from "./ExplorerDatasetSearch"; | ||
import {matchingMenuKeys, renderMenuItem} from "../../utils/menu"; | ||
import {projectPropTypesShape} from "../../propTypes"; | ||
|
||
class ExplorerSearchContent extends Component { | ||
render() { | ||
const menuItems = this.props.projects.map(project => ({ | ||
// url: `/data/explorer/projects/${project.identifier}`, | ||
key: project.identifier, | ||
text: project.title, | ||
children: project.datasets.map(dataset => ({ | ||
url: `/data/explorer/search/${dataset.identifier}`, | ||
text: dataset.title, | ||
})), | ||
})); | ||
|
||
const datasets = this.props.projects.flatMap(p => p.datasets); | ||
|
||
return <> | ||
<SitePageHeader title="Data Explorer" /> | ||
<Layout> | ||
<Layout.Sider style={{background: "white"}} width={256} breakpoint="lg" collapsedWidth={0}> | ||
<div style={{display: "flex", height: "100%", flexDirection: "column"}}> | ||
<Menu mode="inline" | ||
style={{flex: 1, paddingTop: "8px"}} | ||
defaultOpenKeys={menuItems.map(p => p.key)} | ||
selectedKeys={matchingMenuKeys(menuItems)}> | ||
{menuItems.map(renderMenuItem)} | ||
</Menu> | ||
</div> | ||
</Layout.Sider> | ||
<Layout.Content style={LAYOUT_CONTENT_STYLE}> | ||
{datasets.length > 0 ? ( | ||
<Switch> | ||
<Route path="/data/explorer/search/:dataset" component={ExplorerDatasetSearch} /> | ||
<Redirect | ||
from="/data/explorer/search" | ||
to={`/data/explorer/search/${datasets[0].identifier}`} /> | ||
</Switch> | ||
) : (this.props.isFetchingDependentData ? <Skeleton /> : "No datasets available")} | ||
</Layout.Content> | ||
</Layout> | ||
</>; | ||
} | ||
} | ||
|
||
ExplorerSearchContent.propTypes = { | ||
projects: PropTypes.arrayOf(projectPropTypesShape), | ||
isFetchingDependentData: PropTypes.bool, | ||
import SitePageHeader from "../SitePageHeader"; | ||
import { LAYOUT_CONTENT_STYLE } from "../../styles/layoutContent"; | ||
import { matchingMenuKeys, renderMenuItem } from "../../utils/menu"; | ||
|
||
const ExplorerSearchContent = () => { | ||
const projects = useSelector((state) => state.projects.items); | ||
const isFetchingDependentData = useSelector((state) => state.user.isFetchingDependentData); | ||
|
||
const menuItems = useMemo(() => projects.map(project => ({ | ||
// url: `/data/explorer/projects/${project.identifier}`, | ||
key: project.identifier, | ||
text: project.title, | ||
children: project.datasets.map(dataset => ({ | ||
url: `/data/explorer/search/${dataset.identifier}`, | ||
text: dataset.title, | ||
})), | ||
})), [projects]); | ||
|
||
const datasets = useMemo(() => projects.flatMap(p => p.datasets), [projects]); | ||
|
||
return <> | ||
<SitePageHeader title="Data Explorer" /> | ||
<Layout> | ||
<Layout.Sider style={{background: "white"}} width={256} breakpoint="lg" collapsedWidth={0}> | ||
<div style={{display: "flex", height: "100%", flexDirection: "column"}}> | ||
<Menu mode="inline" | ||
style={{flex: 1, paddingTop: "8px"}} | ||
defaultOpenKeys={menuItems.map(p => p.key)} | ||
selectedKeys={matchingMenuKeys(menuItems)}> | ||
{menuItems.map(renderMenuItem)} | ||
</Menu> | ||
</div> | ||
</Layout.Sider> | ||
<Layout.Content style={LAYOUT_CONTENT_STYLE}> | ||
{datasets.length > 0 ? ( | ||
<Switch> | ||
<Route path="/data/explorer/search/:dataset" component={ExplorerDatasetSearch} /> | ||
<Redirect | ||
from="/data/explorer/search" | ||
to={`/data/explorer/search/${datasets[0].identifier}`} /> | ||
</Switch> | ||
) : (isFetchingDependentData ? <Skeleton /> : "No datasets available")} | ||
</Layout.Content> | ||
</Layout> | ||
</>; | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
projects: state.projects.items, | ||
isFetchingDependentData: state.user.isFetchingDependentData, | ||
autoQuery: state.explorer.autoQuery, | ||
}); | ||
|
||
export default connect(mapStateToProps)(ExplorerSearchContent); | ||
export default ExplorerSearchContent; |