UI Improvements
[arvados.git] / src / views-components / data-explorer / renderers.tsx
index 9b9a5bb5c371a1a34195b82879eea901dc13f223..bb3f4e10ed1ab5b2b7fe5c305befa9bf920735c5 100644 (file)
@@ -25,9 +25,7 @@ import { UserResource } from '~/models/user';
 import { toggleIsActive, toggleIsAdmin } from '~/store/users/users-actions';
 import { LinkResource } from '~/models/link';
 import { navigateTo } from '~/store/navigation/navigation-action';
-import { Link } from 'react-router-dom';
-import { NodeResource } from '../../models/node';
-import { NodeInfo } from '~/models/node';
+import { withResource, getDataFromResource, withResourceData } from '~/views-components/data-explorer/with-resources';
 
 const renderName = (item: { name: string; uuid: string, kind: string }) =>
     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
@@ -35,7 +33,7 @@ const renderName = (item: { name: string; uuid: string, kind: string }) =>
             {renderIcon(item)}
         </Grid>
         <Grid item>
-            <Typography color="primary" style={{ width: '450px' }}>
+            <Typography color="primary" style={{ width: 'auto' }}>
                 {item.name}
             </Typography>
         </Grid>
@@ -194,58 +192,32 @@ export const ResourceUsername = connect(
     })(renderUsername);
 
 // Compute Node Resources
-const renderNodeDate = (date?: string) =>
-    <Typography noWrap>{formatDate(date) || '(none)'}</Typography>;
+const renderNodeDate = (date: string) =>
+    <Typography noWrap>{formatDate(date)}</Typography>;
 
-const renderNodeData = (property?: string) => 
-    <Typography noWrap>{property || '(none)'}</Typography>;
+const renderNodeData = (data: string) => {
+    return <Typography noWrap>{data}</Typography>;
+};
 
-const renderNodeInfo = (item: { info: NodeInfo }) =>
-    <Typography>
-        {JSON.stringify(item.info, null, 4)}
-    </Typography>;
+const renderNodeInfo = (data: string) => {
+    return <Typography>{JSON.stringify(data, null, 4)}</Typography>;
+};
 
-export const ResourceNodeInfo = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return resource || { info: {} };
-    })(renderNodeInfo);
+export const ComputeNodeInfo = withResourceData('info', renderNodeInfo);
 
-export const ResourceNodeDomain = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { property: resource ? resource.domain : '' };
-    })((props: { property: string }) => renderNodeData(props.property));
+export const ComputeNodeUuid = withResourceData('uuid', renderNodeData);
 
-export const ResourceNodeFirstPingAt = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { date: resource ? resource.firstPingAt : '' };
-    })((props: { date: string }) => renderNodeDate(props.date));
+export const ComputeNodeDomain = withResourceData('domain', renderNodeData);
 
-export const ResourceNodeHostname = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { property: resource ? resource.hostname : '' };
-    })((props: { property: string }) => renderNodeData(props.property));
+export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderNodeDate);
 
-export const ResourceNodeIpAddress = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { property: resource ? resource.ipAddress : '' };
-    })((props: { property: string }) => renderNodeData(props.property));
+export const ComputeNodeHostname = withResourceData('hostname', renderNodeData);
 
-export const ResourceNodeJobUuid = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { property: resource ? resource.jobUuid : '' };
-    })((props: { property: string }) => renderNodeData(props.property));
+export const ComputeNodeIpAddress = withResourceData('ipAddress', renderNodeData);
 
-export const ResourceNodeLastPingAt = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<NodeResource>(props.uuid)(state.resources);
-        return { date: resource ? resource.lastPingAt : '' };
-    })((props: { date: string }) => renderNodeDate(props.date));
+export const ComputeNodeJobUuid = withResourceData('jobUuid', renderNodeData);
+
+export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderNodeDate);
 
 // Links Resources
 const renderLinkName = (item: { name: string }) =>