From 6e0c6489bc761bac498ff4a77dc1bcd777594c67 Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Fri, 14 Dec 2018 16:43:13 +0100 Subject: [PATCH] Change code after CR Feature #14602_admin_compute_node_paginations Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- src/common/formatters.ts | 4 +- src/store/advanced-tab/advanced-tab.ts | 2 +- .../data-explorer/renderers.tsx | 64 ++++++------------- .../data-explorer/with-resources.tsx | 24 +++++++ .../compute-node-panel-root.tsx | 24 +++---- .../compute-node-panel/compute-node-panel.tsx | 2 +- 6 files changed, 59 insertions(+), 61 deletions(-) create mode 100644 src/views-components/data-explorer/with-resources.tsx diff --git a/src/common/formatters.ts b/src/common/formatters.ts index 5383c66e94..ae50ee8add 100644 --- a/src/common/formatters.ts +++ b/src/common/formatters.ts @@ -8,9 +8,9 @@ export const formatDate = (isoDate?: string) => { 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) => { diff --git a/src/store/advanced-tab/advanced-tab.ts b/src/store/advanced-tab/advanced-tab.ts index da3f5c9173..0cb1c74038 100644 --- a/src/store/advanced-tab/advanced-tab.ts +++ b/src/store/advanced-tab/advanced-tab.ts @@ -252,7 +252,7 @@ export const openAdvancedTabDialog = (uuid: string) => resourceKind: ComputeNodeData.COMPUTE_NODE, resourcePrefix: ResourcePrefix.COMPUTE_NODES, resourceKindProperty: ComputeNodeData.PROPERTIES, - property: dataComputeNode!.properties + property: dataComputeNode ? dataComputeNode.properties : {} }); dispatch(initAdvancedTabDialog(advanceDataComputeNode)); break; diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx index 9b9a5bb5c3..b74e8af19e 100644 --- a/src/views-components/data-explorer/renderers.tsx +++ b/src/views-components/data-explorer/renderers.tsx @@ -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 } from './with-resources'; const renderName = (item: { name: string; uuid: string, kind: string }) => @@ -194,58 +192,32 @@ export const ResourceUsername = connect( })(renderUsername); // Compute Node Resources -const renderNodeDate = (date?: string) => - {formatDate(date) || '(none)'}; +const renderNodeDate = (date: string) => + {formatDate(date)}; -const renderNodeData = (property?: string) => - {property || '(none)'}; +const renderNodeData = (data: string) => { + return {data}; +}; -const renderNodeInfo = (item: { info: NodeInfo }) => - - {JSON.stringify(item.info, null, 4)} - ; +const renderNodeInfo = (data: string) => { + return {JSON.stringify(data, null, 4)}; +}; -export const ResourceNodeInfo = connect( - (state: RootState, props: { uuid: string }) => { - const resource = getResource(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(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(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(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(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(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(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 }) => diff --git a/src/views-components/data-explorer/with-resources.tsx b/src/views-components/data-explorer/with-resources.tsx new file mode 100644 index 0000000000..f6670bd664 --- /dev/null +++ b/src/views-components/data-explorer/with-resources.tsx @@ -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) => + connect( + (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)'; +}; diff --git a/src/views/compute-node-panel/compute-node-panel-root.tsx b/src/views/compute-node-panel/compute-node-panel-root.tsx index 1a525d8667..feaadb5e5b 100644 --- a/src/views/compute-node-panel/compute-node-panel-root.tsx +++ b/src/views/compute-node-panel/compute-node-panel-root.tsx @@ -11,8 +11,8 @@ import { DataColumns } from '~/components/data-table/data-table'; 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'; @@ -33,7 +33,7 @@ export const computeNodePanelColumns: DataColumns = [ selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.UUID, @@ -41,52 +41,54 @@ export const computeNodePanelColumns: DataColumns = [ configurable: true, sortDirection: SortDirection.NONE, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.DOMAIN, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.FIRST_PING_AT, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.HOSTNAME, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.IP_ADDRESS, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.JOB, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => }, { name: ComputeNodePanelColumnNames.LAST_PING_AT, selected: true, configurable: true, filters: createTree(), - render: uuid => + render: uuid => } ]; +const DEFAULT_MESSAGE = 'Your compute node list is empty.'; + export interface ComputeNodePanelRootActionProps { onItemClick: (item: string) => void; onContextMenu: (event: React.MouseEvent, item: string) => void; @@ -111,6 +113,6 @@ export const ComputeNodePanelRoot = (props: ComputeNodePanelRootProps) => { dataTableDefaultView={ + messages={[DEFAULT_MESSAGE]} /> } />; }; \ No newline at end of file diff --git a/src/views/compute-node-panel/compute-node-panel.tsx b/src/views/compute-node-panel/compute-node-panel.tsx index 77a6abef45..a531b2d0cb 100644 --- a/src/views/compute-node-panel/compute-node-panel.tsx +++ b/src/views/compute-node-panel/compute-node-panel.tsx @@ -10,7 +10,7 @@ import { 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 { -- 2.30.2