-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,94 @@ | ||
import { computed, runInAction, makeObservable } from "mobx"; | ||
import { runInAction } from "mobx"; | ||
import { observer } from "mobx-react"; | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import { withTranslation } from "react-i18next"; | ||
import { withTheme } from "styled-components"; | ||
import { useTranslation } from "react-i18next"; | ||
import Box from "../../../Styled/Box"; | ||
import DataCatalog from "../../DataCatalog/DataCatalog"; | ||
import DataPreview from "../../Preview/DataPreview"; | ||
import Breadcrumbs from "../../Search/Breadcrumbs"; | ||
import SearchBox, { DEBOUNCE_INTERVAL } from "../../Search/SearchBox.jsx"; | ||
import Styles from "./data-catalog-tab.scss"; | ||
import Breadcrumbs from "../../Search/Breadcrumbs"; | ||
import Box from "../../../Styled/Box"; | ||
import { useViewState } from "../../Context"; | ||
|
||
// The DataCatalog Tab | ||
@observer | ||
class DataCatalogTab extends React.Component { | ||
static propTypes = { | ||
terria: PropTypes.object, | ||
viewState: PropTypes.object, | ||
items: PropTypes.array, | ||
searchPlaceholder: PropTypes.string, | ||
onActionButtonClicked: PropTypes.func, | ||
theme: PropTypes.object, | ||
t: PropTypes.func.isRequired | ||
}; | ||
interface DataCatalogTabProps { | ||
items?: unknown[]; | ||
searchPlaceholder?: string; | ||
onActionButtonClicked?: () => void; | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
makeObservable(this); | ||
} | ||
const DataCatalogTab = observer(function DataCatalogTab( | ||
props: DataCatalogTabProps | ||
) { | ||
const viewState = useViewState(); | ||
const { t } = useTranslation(); | ||
|
||
@computed | ||
get searchPlaceholder() { | ||
const { t } = this.props; | ||
return this.props.searchPlaceholder || t("addData.searchPlaceholder"); | ||
} | ||
const { | ||
searchState, | ||
previewedItem: previewed, | ||
breadcrumbsShown: showBreadcrumbs, | ||
terria | ||
} = viewState; | ||
|
||
changeSearchText(newText) { | ||
const searchPlaceholder = | ||
props.searchPlaceholder || t("addData.searchPlaceholder"); | ||
|
||
const changeSearchText = (newText: string) => { | ||
runInAction(() => { | ||
this.props.viewState.searchState.catalogSearchText = newText; | ||
viewState.searchState.catalogSearchText = newText; | ||
}); | ||
} | ||
}; | ||
|
||
search() { | ||
this.props.viewState.searchState.searchCatalog(); | ||
} | ||
const search = () => { | ||
viewState.searchState.searchCatalog(); | ||
}; | ||
|
||
render() { | ||
const terria = this.props.terria; | ||
const searchState = this.props.viewState.searchState; | ||
const previewed = this.props.viewState.previewedItem; | ||
const showBreadcrumbs = this.props.viewState.breadcrumbsShown; | ||
return ( | ||
<div className={Styles.root}> | ||
<Box fullHeight column> | ||
<Box fullHeight overflow="hidden"> | ||
<Box className={Styles.dataExplorer} styledWidth="40%"> | ||
{/* ~TODO: Put this back once we add a MobX DataCatalogSearch Provider~ */} | ||
{/* TODO2: Implement a more generic MobX DataCatalogSearch */} | ||
{searchState.catalogSearchProvider && ( | ||
<SearchBox | ||
searchText={searchState.catalogSearchText} | ||
onSearchTextChanged={(val) => this.changeSearchText(val)} | ||
onDoSearch={() => this.search()} | ||
placeholder={this.searchPlaceholder} | ||
debounceDuration={ | ||
terria.catalogReferencesLoaded && | ||
searchState.catalogSearchProvider | ||
? searchState.catalogSearchProvider | ||
.debounceDurationOnceLoaded | ||
: DEBOUNCE_INTERVAL | ||
} | ||
/> | ||
)} | ||
<DataCatalog | ||
terria={this.props.terria} | ||
viewState={this.props.viewState} | ||
onActionButtonClicked={this.props.onActionButtonClicked} | ||
items={this.props.items} | ||
/> | ||
</Box> | ||
<Box styledWidth="60%"> | ||
<DataPreview | ||
terria={terria} | ||
viewState={this.props.viewState} | ||
previewed={previewed} | ||
return ( | ||
<div className={Styles.root}> | ||
<Box fullHeight column> | ||
<Box fullHeight overflow="hidden"> | ||
<Box className={Styles.dataExplorer} styledWidth="40%"> | ||
{/* ~TODO: Put this back once we add a MobX DataCatalogSearch Provider~ */} | ||
{/* TODO2: Implement a more generic MobX DataCatalogSearch */} | ||
{searchState.catalogSearchProvider && ( | ||
<SearchBox | ||
searchText={searchState.catalogSearchText} | ||
onSearchTextChanged={changeSearchText} | ||
onDoSearch={() => search()} | ||
placeholder={searchPlaceholder} | ||
debounceDuration={ | ||
terria.catalogReferencesLoaded && | ||
searchState.catalogSearchProvider | ||
? (searchState.catalogSearchProvider as any) | ||
.debounceDurationOnceLoaded | ||
: DEBOUNCE_INTERVAL | ||
} | ||
/> | ||
</Box> | ||
)} | ||
<DataCatalog | ||
terria={terria} | ||
viewState={viewState} | ||
onActionButtonClicked={props.onActionButtonClicked} | ||
items={props.items} | ||
/> | ||
</Box> | ||
|
||
{showBreadcrumbs && ( | ||
<Breadcrumbs | ||
terria={this.props.terria} | ||
viewState={this.props.viewState} | ||
<Box styledWidth="60%"> | ||
<DataPreview | ||
terria={terria} | ||
viewState={viewState} | ||
previewed={previewed} | ||
/> | ||
)} | ||
</Box> | ||
</Box> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default withTranslation()(withTheme(DataCatalogTab)); | ||
{showBreadcrumbs && ( | ||
<Breadcrumbs | ||
terria={terria} | ||
viewState={viewState} | ||
previewed={previewed} | ||
/> | ||
)} | ||
</Box> | ||
</div> | ||
); | ||
}); | ||
|
||
export default DataCatalogTab; |
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