Skip to content

Commit

Permalink
add the react table to deployments UI
Browse files Browse the repository at this point in the history
  • Loading branch information
priley86 committed Apr 22, 2019
1 parent 6824f9b commit 1e27b7b
Show file tree
Hide file tree
Showing 7 changed files with 615 additions and 28 deletions.
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"dependencies": {
"@patternfly/patternfly": "2.4.1",
"@patternfly/react-core": "3.2.4",
"@patternfly/react-table": "git+https://git@github.com/priley86/react-table.git",
"@patternfly/react-virtualized-extension": "git+https://git@github.com/priley86/react-virtualized-extension.git",
"brace": "0.11.x",
"classnames": "2.x",
"core-js": "2.x",
Expand Down
70 changes: 68 additions & 2 deletions frontend/public/components/deployment.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import * as _ from 'lodash-es';

import {
headerCol,
sortable,
} from '@patternfly/react-table';
import { Link } from 'react-router-dom';
import { DeploymentModel } from '../models';
import { configureUpdateStrategyModal, errorModal } from './modals';
import { Conditions } from './conditions';
Expand All @@ -13,6 +17,7 @@ import {
ListPage,
WorkloadListHeader,
WorkloadListRow,
Table,
} from './factory';
import {
AsyncComponent,
Expand All @@ -26,6 +31,11 @@ import {
StatusIcon,
togglePaused,
WorkloadPausedAlert,
LabelList,
ResourceKebab,
ResourceLink,
resourcePath,
Selector,
} from './utils';

const {ModifyCount, AddStorage, EditEnvironment, common} = Kebab.factory;
Expand Down Expand Up @@ -117,7 +127,63 @@ const DeploymentsDetailsPage = props => <DetailsPage
/>;

const Row = props => <WorkloadListRow {...props} kind="Deployment" actions={menuActions} />;
const DeploymentsList = props => <List {...props} Header={WorkloadListHeader} Row={Row} />;

const kind = 'Deployment';

const DeploymentTableRow = (o, index) => {
return {
id: index,
cells: [
{
title: <ResourceLink kind={kind} name={o.metadata.name} namespace={o.metadata.namespace} title={o.metadata.uid} />,
},
{
title: <ResourceLink kind="Namespace" name={o.metadata.namespace} title={o.metadata.namespace} />,
},
{
title: <LabelList kind={kind} labels={o.metadata.labels} />,
},
{
title: <Link to={`${resourcePath(kind, o.metadata.name, o.metadata.namespace)}/pods`} title="pods">
{o.status.replicas || 0} of {o.spec.replicas} pods
</Link>,
},
{
title: <Selector selector={o.spec.selector} namespace={o.metadata.namespace} />,
},
{
title: <div className="dropdown-kebab-pf">
<ResourceKebab actions={menuActions} kind={kind} resource={o} />
</div>,
props: { className: 'pf-c-table__action'},
},
]
};
};

const DeploymentTableRows = componentProps =>
_.map(componentProps.data, (obj, index) => obj && obj.metadata && DeploymentTableRow(obj, index));

const DeploymentTableHeader = props => {
return [
{ title: 'Name', sortField: 'metadata.name', transforms: [sortable], cellTransforms: [headerCol()], props},
{ title: 'Namespace', sortField: 'metadata.namespace', transforms: [sortable], props },
{ title: 'Labels', sortField: 'metadata.labels', transforms: [sortable], props},
{ title: 'Status', sortField: 'metadata.labels', props: {...props, className: 'meta-status'},
{ title: 'Pod Selector', sortField: 'spec.selector', transforms: [sortable], props },
// todo: add support for table actions api: https://github.com/patternfly/patternfly-react/pull/1441
// this is for the empty actions/kebab column header
{ title: '' },
];
};

const DeploymentsList = props => <React.Fragment>
<Table {...props} aria-label="Deployments" Header={DeploymentTableHeader} Rows={DeploymentTableRows} virtualize />
{/* <br />
<br />
<List {...props} Header={WorkloadListHeader} Row={Row} /> */}
</React.Fragment>;

const DeploymentsPage = props => <ListPage canCreate={true} ListComponent={DeploymentsList} {...props} />;

export {DeploymentsList, DeploymentsPage, DeploymentsDetailsPage};
1 change: 1 addition & 0 deletions frontend/public/components/factory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './details';
export * from './list-page';
export * from './list';
export * from './modal';
export * from './table';
Loading

0 comments on commit 1e27b7b

Please sign in to comment.