Change code after CR
[arvados-workbench2.git] / src / views-components / data-explorer / with-resources.tsx
diff --git a/src/views-components/data-explorer/with-resources.tsx b/src/views-components/data-explorer/with-resources.tsx
new file mode 100644 (file)
index 0000000..f6670bd
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { connect } from 'react-redux';
+import { RootState } from '~/store/store';
+import { getResource } from '~/store/resources/resources';
+import { Resource } from '~/models/resource';
+
+interface WithResourceProps {
+    resource?: Resource;
+}
+
+export const withResource = (component: React.ComponentType<WithResourceProps & { uuid: string }>) =>
+    connect<WithResourceProps>(
+        (state: RootState, props: { uuid: string }): WithResourceProps => ({
+            resource: getResource(props.uuid)(state.resources)
+        })
+    )(component);
+
+export const getDataFromResource = (property: string, resource?: Resource) => {
+    return resource && resource[property] ? resource[property] : '(none)';
+};