show instance type in details

This commit is contained in:
Tao Bror Bojlén 2019-07-24 19:25:20 +03:00
parent 3b515c3a36
commit a615d115fd
No known key found for this signature in database
GPG key ID: C6EC7AAB905F9E6F
7 changed files with 44 additions and 20 deletions

View file

@ -49,7 +49,8 @@ defmodule BackendWeb.InstanceView do
domainCount: length(instance.peers), domainCount: length(instance.peers),
peers: render_many(instance.peers, InstanceView, "instance.json"), peers: render_many(instance.peers, InstanceView, "instance.json"),
lastUpdated: last_updated, lastUpdated: last_updated,
status: status status: status,
type: instance.type
} }
end end
end end

View file

@ -1,21 +1,16 @@
import { Button, Classes, H5, H6, Icon, MenuItem } from "@blueprintjs/core"; import { Button, Classes, H5, H6, MenuItem } from "@blueprintjs/core";
import { IconNames } from "@blueprintjs/icons"; import { IconNames } from "@blueprintjs/icons";
import { ItemRenderer, Select } from "@blueprintjs/select"; import { ItemRenderer, Select } from "@blueprintjs/select";
import React from "react"; import React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { FloatingCard } from "."; import { FloatingCard, InstanceType } from ".";
import { QUALITATIVE_COLOR_SCHEME } from "../../constants";
import { IColorSchemeType } from "../../types"; import { IColorSchemeType } from "../../types";
import { capitalize } from "../../util";
const ColorSchemeSelect = Select.ofType<IColorSchemeType>(); const ColorSchemeSelect = Select.ofType<IColorSchemeType>();
const StyledLi = styled.li` const StyledLi = styled.li`
margin-top: 2px; margin-top: 2px;
`; `;
const StyledIcon = styled(Icon)`
margin-right: 5px;
`;
const StyledKeyContainer = styled.div` const StyledKeyContainer = styled.div`
margin-top: 10px; margin-top: 10px;
`; `;
@ -51,10 +46,9 @@ const GraphKey: React.FC<IGraphKeyProps> = ({ current, colorSchemes, onItemSelec
<StyledKeyContainer> <StyledKeyContainer>
<H6>Key</H6> <H6>Key</H6>
<ul className={Classes.LIST_UNSTYLED}> <ul className={Classes.LIST_UNSTYLED}>
{current.values.map((v, idx) => ( {current.values.map(v => (
<StyledLi> <StyledLi>
<StyledIcon icon={IconNames.FULL_CIRCLE} color={QUALITATIVE_COLOR_SCHEME[idx]} /> <InstanceType type={v} />
{capitalize(v)}
</StyledLi> </StyledLi>
))} ))}
</ul> </ul>

View file

@ -0,0 +1,27 @@
import { Icon } from "@blueprintjs/core";
import { IconNames } from "@blueprintjs/icons";
import React from "react";
import { QUALITATIVE_COLOR_SCHEME } from "../../constants";
import { typeColorScheme } from "../../types";
import { capitalize } from "../../util";
interface IInstanceTypeProps {
type: string;
colorAfterName?: boolean;
}
/**
* By default, renders the color followed by the name of the instance type.
* You can change this by passing `colorAfterName={true}`.
*/
const InstanceType: React.FC<IInstanceTypeProps> = ({ type, colorAfterName }) => {
const idx = typeColorScheme.values.indexOf(type);
const name = " " + capitalize(type);
return (
<>
{!!colorAfterName && name}
<Icon icon={IconNames.SYMBOL_CIRCLE} color={QUALITATIVE_COLOR_SCHEME[idx]} />
{!colorAfterName && name}
</>
);
};
export default InstanceType;

View file

@ -2,3 +2,4 @@ export { default as Page } from "./Page";
export { default as FloatingCard } from "./FloatingCard"; export { default as FloatingCard } from "./FloatingCard";
export { default as GraphKey } from "./GraphKey"; export { default as GraphKey } from "./GraphKey";
export { default as GraphResetButton } from "./GraphResetButton"; export { default as GraphResetButton } from "./GraphResetButton";
export { default as InstanceType } from "./InstanceType";

View file

@ -1,14 +1,11 @@
import { Card, Classes, Elevation, H4, Icon } from "@blueprintjs/core"; import { Card, Classes, Elevation, H4 } from "@blueprintjs/core";
import { IconNames } from "@blueprintjs/icons";
import inflection from "inflection"; import inflection from "inflection";
import * as numeral from "numeral"; import * as numeral from "numeral";
import React from "react"; import React from "react";
import sanitize from "sanitize-html"; import sanitize from "sanitize-html";
import styled from "styled-components"; import styled from "styled-components";
import { QUALITATIVE_COLOR_SCHEME } from "../../constants";
import { ISearchResultInstance } from "../../redux/types"; import { ISearchResultInstance } from "../../redux/types";
import { typeColorScheme } from "../../types"; import { InstanceType } from "../atoms";
import { capitalize } from "../../util";
const StyledCard = styled(Card)` const StyledCard = styled(Card)`
width: 80%; width: 80%;
@ -50,11 +47,9 @@ const SearchResult: React.FC<ISearchResultProps> = ({ result, onClick }) => {
let typeIcon; let typeIcon;
if (result.type) { if (result.type) {
const idx = typeColorScheme.values.indexOf(result.type);
typeIcon = ( typeIcon = (
<StyledType className={Classes.TEXT_MUTED}> <StyledType className={Classes.TEXT_MUTED}>
<Icon icon={IconNames.SYMBOL_CIRCLE} color={QUALITATIVE_COLOR_SCHEME[idx]} /> <InstanceType type={result.type} />
{" " + capitalize(result.type)}
</StyledType> </StyledType>
); );
} }

View file

@ -30,6 +30,7 @@ import { Dispatch } from "redux";
import styled from "styled-components"; import styled from "styled-components";
import { IAppState, IGraph, IInstanceDetails } from "../../redux/types"; import { IAppState, IGraph, IInstanceDetails } from "../../redux/types";
import { domainMatchSelector, getFromApi, isSmallScreen } from "../../util"; import { domainMatchSelector, getFromApi, isSmallScreen } from "../../util";
import { InstanceType } from "../atoms";
import { Cytoscape, ErrorState } from "../molecules/"; import { Cytoscape, ErrorState } from "../molecules/";
const InstanceScreenContainer = styled.div` const InstanceScreenContainer = styled.div`
@ -258,7 +259,7 @@ class InstanceScreenImpl extends React.PureComponent<IInstanceScreenProps, IInst
if (!this.props.instanceDetails) { if (!this.props.instanceDetails) {
throw new Error("Did not receive instance details as expected!"); throw new Error("Did not receive instance details as expected!");
} }
const { version, userCount, statusCount, domainCount, lastUpdated, insularity } = this.props.instanceDetails; const { version, userCount, statusCount, domainCount, lastUpdated, insularity, type } = this.props.instanceDetails;
return ( return (
<StyledHTMLTable small={true} striped={true}> <StyledHTMLTable small={true} striped={true}>
<tbody> <tbody>
@ -266,6 +267,10 @@ class InstanceScreenImpl extends React.PureComponent<IInstanceScreenProps, IInst
<td>Version</td> <td>Version</td>
<td>{<Code>{version}</Code> || "Unknown"}</td> <td>{<Code>{version}</Code> || "Unknown"}</td>
</tr> </tr>
<tr>
<td>Instance type</td>
<td>{(type && <InstanceType type={type} colorAfterName={true} />) || "Unknown"}</td>
</tr>
<tr> <tr>
<td>Users</td> <td>Users</td>
<td>{(userCount && numeral.default(userCount).format("0,0")) || "Unknown"}</td> <td>{(userCount && numeral.default(userCount).format("0,0")) || "Unknown"}</td>

View file

@ -47,6 +47,7 @@ export interface IInstanceDetails {
peers?: IInstance[]; peers?: IInstance[];
lastUpdated?: string; lastUpdated?: string;
status: string; status: string;
type?: string;
} }
interface IGraphNode { interface IGraphNode {