feat(datasourcename):Allow specifying the datasourcename as a parameter (#3029)

This commit is contained in:
Bill Wallace authored and GitHub committed 2022-11-22 09:09:24 -05:00
1 parent bbfdda7fe7
commit abd75b0ba1
6 files changed
+237 -27

No files matched your search

@@ -19,29 +19,38 @@ function DataSourceWrapper(props) {
const params = useParams();
const location = useLocation();
// TODO: Fetch by type, name, etc?
const dataSourceModules = extensionManager.modules[MODULE_TYPES.DATA_SOURCE];
// TODO: Good usecase for flatmap?
const webApiDataSources = dataSourceModules.reduce((acc, curr) => {
const mods = [];
curr.module.forEach(mod => {
if (mod.type === 'webApi') {
mods.push(mod);
}
});
return acc.concat(mods);
}, []);
// TODO - get the variable from the props all the time...
let dataSourceName = new URLSearchParams(location.search).get(
'datasourcename'
);
const dataPath = dataSourceName ? `/${dataSourceName}` : '';
// Grabbing first defined for now - should get active
// TODO: Why does this return an array?
const dataSource = webApiDataSources
.map(ds => extensionManager.getDataSources(ds.name)?.[0])
.find(it => it !== undefined);
if (!dataSource) {
throw new Error(
`No data source found for any of ${webApiDataSources.map(it => it.name)}`
);
if (!dataSourceName && window.config.defaultDataSourceName) {
dataSourceName = window.config.defaultDataSourceName;
} else if (!dataSourceName) {
// Gets the first defined datasource with the right name
// Mostly for historical reasons - new configs should use the defaultDataSourceName
const dataSourceModules =
extensionManager.modules[MODULE_TYPES.DATA_SOURCE];
// TODO: Good usecase for flatmap?
const webApiDataSources = dataSourceModules.reduce((acc, curr) => {
const mods = [];
curr.module.forEach(mod => {
if (mod.type === 'webApi') {
mods.push(mod);
}
});
return acc.concat(mods);
}, []);
dataSourceName = webApiDataSources
.map(ds => ds.name)
.find(it => extensionManager.getDataSources(it)?.[0] !== undefined);
}
const dataSource = extensionManager.getDataSources(dataSourceName)?.[0];
if (!dataSource) {
throw new Error(`No data source found for ${dataSourceName}`);
}
// Route props --> studies.mapParams
// mapParams --> studies.search
// studies.search --> studies.processResults
@@ -114,6 +123,7 @@ function DataSourceWrapper(props) {
<LayoutTemplate
{...rest}
data={data.studies}
dataPath={dataPath}
dataTotal={data.total}
dataSource={dataSource}
isLoadingData={isLoading}