Create common render functions module
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 26 Jul 2018 10:43:29 +0000 (12:43 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 26 Jul 2018 10:43:29 +0000 (12:43 +0200)
Feature #13887

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/views-components/data-explorer/renderers.tsx [new file with mode: 0644]
src/views/favorite-panel/favorite-panel.tsx
src/views/project-panel/project-panel.tsx

diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx
new file mode 100644 (file)
index 0000000..2b99f02
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { Grid, Typography } from '@material-ui/core';
+import { FavoriteStar } from '../favorite-star/favorite-star';
+import { ResourceKind } from '../../models/resource';
+import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '../../components/icon/icon';
+import { formatDate, formatFileSize } from '../../common/formatters';
+import { resourceLabel } from '../../common/labels';
+
+
+export const renderName = (item: {name: string; uuid: string, kind: string}) =>
+    <Grid container alignItems="center" wrap="nowrap" spacing={16}>
+        <Grid item>
+            {renderIcon(item)}
+        </Grid>
+        <Grid item>
+            <Typography color="primary">
+                {item.name}
+            </Typography>
+        </Grid>
+        <Grid item>
+            <Typography variant="caption">
+                <FavoriteStar resourceUuid={item.uuid} />
+            </Typography>
+        </Grid>
+    </Grid>;
+
+
+export const renderIcon = (item: {kind: string}) => {
+    switch (item.kind) {
+        case ResourceKind.PROJECT:
+            return <ProjectIcon />;
+        case ResourceKind.COLLECTION:
+            return <CollectionIcon />;
+        case ResourceKind.PROCESS:
+            return <ProcessIcon />;
+        default:
+            return <DefaultIcon />;
+    }
+};
+
+export const renderDate = (date: string) => {
+    return <Typography noWrap>{formatDate(date)}</Typography>;
+};
+
+export const renderFileSize = (fileSize?: number) =>
+    <Typography noWrap>
+        {formatFileSize(fileSize)}
+    </Typography>;
+
+export const renderOwner = (owner: string) =>
+    <Typography noWrap color="primary" >
+        {owner}
+    </Typography>;
+
+export const renderType = (type: string) =>
+    <Typography noWrap>
+        {resourceLabel(type)}
+    </Typography>;
+
+export const renderStatus = (item: {status?: string}) =>
+    <Typography noWrap align="center" >
+        {item.status || "-"}
+    </Typography>;
\ No newline at end of file
index 36a3410763129b043c95c2d55af45a39814f0a15..25a82511508152e6140b28fb82817bd2a02724e2 100644 (file)
@@ -4,8 +4,7 @@
 
 import * as React from 'react';
 import { FavoritePanelItem } from './favorite-panel-item';
-import { Grid, Typography, Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-import { formatDate, formatFileSize } from '../../common/formatters';
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
 import { DataExplorer } from "../../views-components/data-explorer/data-explorer";
 import { DispatchProp, connect } from 'react-redux';
 import { DataColumns } from '../../components/data-table/data-table';
@@ -16,9 +15,8 @@ import { ContainerRequestState } from '../../models/container-request';
 import { SortDirection } from '../../components/data-table/data-column';
 import { ResourceKind } from '../../models/resource';
 import { resourceLabel } from '../../common/labels';
-import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '../../components/icon/icon';
 import { ArvadosTheme } from '../../common/custom-theme';
-import { FavoriteStar } from "../../views-components/favorite-star/favorite-star";
+import { renderName, renderStatus, renderType, renderOwner, renderFileSize, renderDate } from '../../views-components/data-explorer/renderers';
 
 type CssRules = "toolbar" | "button";
 
@@ -32,61 +30,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
 });
 
-const renderName = (item: FavoritePanelItem) =>
-    <Grid container alignItems="center" wrap="nowrap" spacing={16}>
-        <Grid item>
-            {renderIcon(item)}
-        </Grid>
-        <Grid item>
-            <Typography color="primary">
-                {item.name}
-            </Typography>
-        </Grid>
-        <Grid item>
-            <Typography variant="caption">
-                <FavoriteStar resourceUuid={item.uuid} />
-            </Typography>
-        </Grid>
-    </Grid>;
-
-
-const renderIcon = (item: FavoritePanelItem) => {
-    switch (item.kind) {
-        case ResourceKind.PROJECT:
-            return <ProjectIcon />;
-        case ResourceKind.COLLECTION:
-            return <CollectionIcon />;
-        case ResourceKind.PROCESS:
-            return <ProcessIcon />;
-        default:
-            return <DefaultIcon />;
-    }
-};
-
-const renderDate = (date: string) => {
-    return <Typography noWrap>{formatDate(date)}</Typography>;
-};
-
-const renderFileSize = (fileSize?: number) =>
-    <Typography noWrap>
-        {formatFileSize(fileSize)}
-    </Typography>;
-
-const renderOwner = (owner: string) =>
-    <Typography noWrap color="primary" >
-        {owner}
-    </Typography>;
-
-const renderType = (type: string) =>
-    <Typography noWrap>
-        {resourceLabel(type)}
-    </Typography>;
-
-const renderStatus = (item: FavoritePanelItem) =>
-    <Typography noWrap align="center" >
-        {item.status || "-"}
-    </Typography>;
-
 export enum FavoritePanelColumnNames {
     NAME = "Name",
     STATUS = "Status",
index 17b0fd723db9f07f2c5c05d7e905aa6b6823bb71..c7138c3029cafdd2b05894738304ac6eee57f0a4 100644 (file)
@@ -4,8 +4,7 @@
 
 import * as React from 'react';
 import { ProjectPanelItem } from './project-panel-item';
-import { Grid, Typography, Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-import { formatDate, formatFileSize } from '../../common/formatters';
+import { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
 import { DataExplorer } from "../../views-components/data-explorer/data-explorer";
 import { DispatchProp, connect } from 'react-redux';
 import { DataColumns } from '../../components/data-table/data-table';
@@ -16,9 +15,8 @@ import { ContainerRequestState } from '../../models/container-request';
 import { SortDirection } from '../../components/data-table/data-column';
 import { ResourceKind } from '../../models/resource';
 import { resourceLabel } from '../../common/labels';
-import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, FavoriteIcon } from '../../components/icon/icon';
 import { ArvadosTheme } from '../../common/custom-theme';
-import { FavoriteStar } from '../../views-components/favorite-star/favorite-star';
+import { renderName, renderStatus, renderType, renderOwner, renderFileSize, renderDate } from '../../views-components/data-explorer/renderers';
 
 type CssRules = "toolbar" | "button";
 
@@ -32,61 +30,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
 });
 
-const renderName = (item: ProjectPanelItem) =>
-    <Grid container alignItems="center" wrap="nowrap" spacing={16}>
-        <Grid item>
-            {renderIcon(item)}
-        </Grid>
-        <Grid item>
-            <Typography color="primary">
-                {item.name}
-            </Typography>
-        </Grid>
-        <Grid item>
-            <Typography variant="caption">
-                <FavoriteStar resourceUuid={item.uuid} />
-            </Typography>
-        </Grid>
-    </Grid>;
-
-
-const renderIcon = (item: ProjectPanelItem) => {
-    switch (item.kind) {
-        case ResourceKind.PROJECT:
-            return <ProjectIcon />;
-        case ResourceKind.COLLECTION:
-            return <CollectionIcon />;
-        case ResourceKind.PROCESS:
-            return <ProcessIcon />;
-        default:
-            return <DefaultIcon />;
-    }
-};
-
-const renderDate = (date: string) => {
-    return <Typography noWrap>{formatDate(date)}</Typography>;
-};
-
-const renderFileSize = (fileSize?: number) =>
-    <Typography noWrap>
-        {formatFileSize(fileSize)}
-    </Typography>;
-
-const renderOwner = (owner: string) =>
-    <Typography noWrap color="primary" >
-        {owner}
-    </Typography>;
-
-const renderType = (type: string) =>
-    <Typography noWrap>
-        {resourceLabel(type)}
-    </Typography>;
-
-const renderStatus = (item: ProjectPanelItem) =>
-    <Typography noWrap align="center" >
-        {item.status || "-"}
-    </Typography>;
-
 export enum ProjectPanelColumnNames {
     NAME = "Name",
     STATUS = "Status",