if (isoDate) {
const date = new Date(isoDate);
const text = date.toLocaleString();
- return text === 'Invalid Date' ? "" : text;
+ return text === 'Invalid Date' ? "(none)" : text;
}
- return "";
+ return "(none)";
};
export const formatFileSize = (size?: number) => {
resourceKind: ComputeNodeData.COMPUTE_NODE,
resourcePrefix: ResourcePrefix.COMPUTE_NODES,
resourceKindProperty: ComputeNodeData.PROPERTIES,
- property: dataComputeNode!.properties
+ property: dataComputeNode ? dataComputeNode.properties : {}
});
dispatch<any>(initAdvancedTabDialog(advanceDataComputeNode));
break;
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 } from './with-resources';
const renderName = (item: { name: string; uuid: string, kind: string }) =>
<Grid container alignItems="center" wrap="nowrap" spacing={16}>
})(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 = withResource(({ resource }) => renderNodeInfo(getDataFromResource('info', resource)));
-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 = withResource(({ resource }) => renderNodeData(getDataFromResource('uuid', resource)));
-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 = withResource(({ resource }) => renderNodeData(getDataFromResource('domain', resource)));
-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 = withResource(({ resource }) => renderNodeDate(getDataFromResource('firstPingAt', resource)));
-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 = withResource(({ resource }) => renderNodeData(getDataFromResource('hostname', resource)));
-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 = withResource(({ resource }) => renderNodeData(getDataFromResource('ipAddress', resource)));
-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 = withResource(({ resource }) => renderNodeData(getDataFromResource('jobUuid', resource)));
+
+export const ComputeNodeLastPingAt = withResource(({ resource }) => renderNodeDate(getDataFromResource('lastPingAt', resource)));
// Links Resources
const renderLinkName = (item: { name: string }) =>
--- /dev/null
+// 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)';
+};
import { SortDirection } from '~/components/data-table/data-column';
import { createTree } from '~/models/tree';
import {
- ResourceUuid, ResourceNodeInfo, ResourceNodeDomain, ResourceNodeHostname, ResourceNodeJobUuid,
- ResourceNodeFirstPingAt, ResourceNodeLastPingAt, ResourceNodeIpAddress
+ ComputeNodeUuid, ComputeNodeInfo, ComputeNodeDomain, ComputeNodeHostname, ComputeNodeJobUuid,
+ ComputeNodeFirstPingAt, ComputeNodeLastPingAt, ComputeNodeIpAddress
} from '~/views-components/data-explorer/renderers';
import { ResourcesState } from '~/store/resources/resources';
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeInfo uuid={uuid} />
+ render: uuid => <ComputeNodeInfo uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.UUID,
configurable: true,
sortDirection: SortDirection.NONE,
filters: createTree(),
- render: uuid => <ResourceUuid uuid={uuid} />
+ render: uuid => <ComputeNodeUuid uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.DOMAIN,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeDomain uuid={uuid} />
+ render: uuid => <ComputeNodeDomain uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.FIRST_PING_AT,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeFirstPingAt uuid={uuid} />
+ render: uuid => <ComputeNodeFirstPingAt uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.HOSTNAME,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeHostname uuid={uuid} />
+ render: uuid => <ComputeNodeHostname uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.IP_ADDRESS,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeIpAddress uuid={uuid} />
+ render: uuid => <ComputeNodeIpAddress uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.JOB,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeJobUuid uuid={uuid} />
+ render: uuid => <ComputeNodeJobUuid uuid={uuid} />
},
{
name: ComputeNodePanelColumnNames.LAST_PING_AT,
selected: true,
configurable: true,
filters: createTree(),
- render: uuid => <ResourceNodeLastPingAt uuid={uuid} />
+ render: uuid => <ComputeNodeLastPingAt uuid={uuid} />
}
];
+const DEFAULT_MESSAGE = 'Your compute node list is empty.';
+
export interface ComputeNodePanelRootActionProps {
onItemClick: (item: string) => void;
onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
dataTableDefaultView={
<DataTableDefaultView
icon={ShareMeIcon}
- messages={['Your compute node list is empty.']} />
+ messages={[DEFAULT_MESSAGE]} />
} />;
};
\ No newline at end of file
ComputeNodePanelRootDataProps,
ComputeNodePanelRootActionProps
} from '~/views/compute-node-panel/compute-node-panel-root';
-import { openComputeNodeContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
+import { openComputeNodeContextMenu } from '~/store/context-menu/context-menu-actions';
const mapStateToProps = (state: RootState): ComputeNodePanelRootDataProps => {
return {