1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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';
11 interface WithResourceProps {
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)
22 export const getDataFromResource = (property: string, resource?: Resource) => {
23 return resource && resource[property] ? resource[property] : '(none)';
26 export const withResourceData = (property: string, render: (data: any) => React.ReactElement<any>) =>
27 withResource(({ resource }) => render(getDataFromResource(property, resource)));