diff --git a/packages/frontend/src/components/Chain/Chain.tsx b/packages/frontend/src/components/Chain/Chain.tsx index 046437c..064e9a3 100644 --- a/packages/frontend/src/components/Chain/Chain.tsx +++ b/packages/frontend/src/components/Chain/Chain.tsx @@ -123,6 +123,7 @@ export class Chain extends React.Component { const { filter } = this.state; const nodeFilter = this.getNodeFilter(); const nodes = nodeFilter ? this.nodes().filter(nodeFilter) : this.nodes(); + const columns = Node.Row.columns.filter(({ setting }) => setting == null || settings[setting]); if (nodeFilter && nodes.length === 0) { return ( @@ -137,10 +138,10 @@ export class Chain extends React.Component { {filter != null ? : null} - + { - nodes.map((node) => ) + nodes.map((node) => ) }
diff --git a/packages/frontend/src/components/Node/Row.tsx b/packages/frontend/src/components/Node/Row.tsx index 7a3f309..a603b61 100644 --- a/packages/frontend/src/components/Node/Row.tsx +++ b/packages/frontend/src/components/Node/Row.tsx @@ -4,7 +4,7 @@ import { Types, Maybe, timestamp } from '@dotstats/common'; import { formatNumber, milliOrSecond, secondsWithPrecision } from '../../utils'; import { State as AppState, Node } from '../../state'; import { PersistentSet } from '../../persist'; -import { SEMVER_PATTERN } from './'; +import { SEMVER_PATTERN, Truncate } from './'; import { Ago, Icon, Tooltip, Sparkline } from '../'; import nodeIcon from '../../icons/server.svg'; @@ -29,8 +29,8 @@ import './Row.css'; interface RowProps { node: Node; - settings: AppState.Settings; pins: PersistentSet; + columns: Column[]; }; interface RowState { @@ -38,7 +38,7 @@ interface RowState { }; interface HeaderProps { - settings: AppState.Settings; + columns: Column[]; }; interface Column { @@ -49,16 +49,6 @@ interface Column { render: (node: Node) => React.ReactElement | string; } -function Truncate(props: { text: string, position?: 'left' | 'right' | 'center' }): React.ReactElement { - const { text, position } = props; - - return ( - -
{text}
-
- ); -} - function formatStamp(stamp: Types.Timestamp): string { const passed = (timestamp() - stamp) / 1000 | 0; @@ -215,8 +205,7 @@ export default class Row extends React.Component { ]; public static Header = (props: HeaderProps) => { - const { settings } = props; - const columns = Row.columns.filter(({ setting }) => setting == null || settings[setting]); + const { columns } = props; const last = columns.length - 1; return ( @@ -259,7 +248,7 @@ export default class Row extends React.Component { } public render() { - const { node, settings } = this.props; + const { node, columns } = this.props; let className = 'Node-Row'; @@ -274,9 +263,7 @@ export default class Row extends React.Component { return ( { - Row.columns - .filter(({ setting }) => setting == null || settings[setting]) - .map(({ render }, index) => {render(node)}) + columns.map(({ render }, index) => {render(node)}) } ); diff --git a/packages/frontend/src/components/Node/Truncate.tsx b/packages/frontend/src/components/Node/Truncate.tsx new file mode 100644 index 0000000..f84fa4f --- /dev/null +++ b/packages/frontend/src/components/Node/Truncate.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { Tooltip } from '../'; + +namespace Truncate { + export interface Props { + text: string, + position?: Tooltip.Props['position'] + } +} + +class Truncate extends React.Component { + public render() { + const { text, position } = this.props; + + return ( + +
{text}
+
+ ); + } + + public shouldComponentUpdate(nextProps: Truncate.Props): boolean { + return this.props.text !== nextProps.text || this.props.position !== nextProps.position; + } +} + +export default Truncate; diff --git a/packages/frontend/src/components/Node/index.ts b/packages/frontend/src/components/Node/index.ts index 2df6450..aeb8364 100644 --- a/packages/frontend/src/components/Node/index.ts +++ b/packages/frontend/src/components/Node/index.ts @@ -1,6 +1,7 @@ import Row from './Row'; import Location from './Location'; +import Truncate from './Truncate'; -export { Row, Location }; +export { Row, Location, Truncate }; export const SEMVER_PATTERN = /^\d+\.\d+\.\d+/;