17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views-components / data-explorer / with-resources.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { RootState } from 'store/store';
8 import { getResource } from 'store/resources/resources';
9 import { Resource } from 'models/resource';
10
11 interface WithResourceProps {
12     resource?: Resource;
13 }
14
15 export const withResource = (component: React.ComponentType<WithResourceProps & { uuid: string }>) =>
16     connect<WithResourceProps>(
17         (state: RootState, props: { uuid: string }): WithResourceProps => ({
18             resource: getResource(props.uuid)(state.resources)
19         })
20     )(component);
21
22 export const getDataFromResource = (property: string, resource?: Resource) => {
23     return resource && resource[property] ? resource[property] : '(none)';
24 };
25
26 export const withResourceData = (property: string, render: (data: any) => React.ReactElement<any>) =>
27     withResource(({ resource }) => render(getDataFromResource(property, resource)));