Skip to content

Commit

Permalink
Merge pull request #815 from porter-dev/lost-tailscale-changes
Browse files Browse the repository at this point in the history
Service list form component for tailscale add-on
  • Loading branch information
jusrhee authored Jun 23, 2021
2 parents 58a4ccb + 06f17d9 commit c686f1e
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 35 deletions.
5 changes: 4 additions & 1 deletion dashboard/src/components/values-form/FormWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export default class FormWrapper extends Component<PropsType, StateType> {
};
if (tabs) {
tabs.forEach((tab: any, i: number) => {
if (tab?.name && tab.label) {
// Exclude value if omitFromLaunch is set
let omit =
tab.settings?.omitFromLaunch && this.props.externalValues?.isLaunch;
if (tab?.name && tab.label && !omit) {
// If a tab is valid, extract state
tab.sections?.forEach((section: Section, i: number) => {
section?.contents?.forEach((item: FormElement, i: number) => {
Expand Down
29 changes: 27 additions & 2 deletions dashboard/src/components/values-form/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import React from "react";
import styled from "styled-components";

export default function Heading(props: { isAtTop?: boolean; children: any }) {
export default function Heading(props: {
isAtTop?: boolean;
children: any;
docs?: string;
}) {
return (
<StyledHeading isAtTop={props.isAtTop}>{props.children}</StyledHeading>
<StyledHeading isAtTop={props.isAtTop}>
{props.children}
{props.docs && (
<a href={props.docs} target="_blank">
<i className="material-icons">help_outline</i>
</a>
)}
</StyledHeading>
);
}

Expand All @@ -15,4 +26,18 @@ const StyledHeading = styled.div<{ isAtTop: boolean }>`
margin-bottom: 5px;
display: flex;
align-items: center;
> a {
> i {
display: flex;
align-items: center;
margin-bottom: -2px;
font-size: 16px;
margin-left: 12px;
color: #858faaaa;
:hover {
color: #aaaabb;
}
}
}
`;
114 changes: 114 additions & 0 deletions dashboard/src/components/values-form/ServiceRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { Component } from "react";
import styled from "styled-components";
import { Context } from "shared/Context";
import { hardcodedNames, hardcodedIcons } from "shared/hardcodedNameDict";

type PropsType = {
service: {
clusterIP: string;
name: string;
release: string;
app: string;
namespace: string;
type?: string;
};
};

type StateType = any;

export default class ServiceRow extends Component<PropsType, StateType> {
render() {
let { clusterIP, name, namespace, type, app, release } = this.props.service;
name = name || release;
type = type || app;
return (
<>
{name &&
type &&
hardcodedNames[type] &&
hardcodedIcons[type] &&
namespace !== "kube-system" && (
<StyledServiceRow>
<Flex>
<Icon src={hardcodedIcons[type]} />
<Type>{hardcodedNames[type]}</Type>
<Name>{name}</Name> <Dash>-</Dash> <IP>{clusterIP}</IP>
</Flex>
<TagWrapper>
Namespace: <NamespaceTag>{namespace}</NamespaceTag>
</TagWrapper>
</StyledServiceRow>
)}
</>
);
}
}

ServiceRow.contextType = Context;

const Flex = styled.div`
display: flex;
align-items: center;
`;

const TagWrapper = styled.div`
float: right;
height: 20px;
font-size: 13px;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff44;
border-right: 0;
border-radius: 3px;
padding-left: 5px;
`;

const NamespaceTag = styled.div`
height: 20px;
margin-left: 6px;
color: #aaaabb;
border-radius: 3px;
font-size: 13px;
display: flex;
align-items: center;
justify-content: center;
padding-left: 3px;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
`;

const Dash = styled.div`
margin-right: 10px;
`;

const Icon = styled.img`
width: 20px;
margin-right: 12px;
`;

const Type = styled.div`
color: #aaaabb;
margin-right: 15px;
`;

const Name = styled.div`
margin-right: 10px;
`;

const IP = styled.div`
user-select: text;
font-weight: 500;
`;

const StyledServiceRow = styled.div`
width: 100%;
height: 40px;
background: #ffffff11;
margin-bottom: 15px;
border-radius: 5px;
padding: 15px;
display: flex;
align-items: center;
justify-content: space-between;
`;
36 changes: 27 additions & 9 deletions dashboard/src/components/values-form/ValuesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SelectRow from "./SelectRow";
import Helper from "./Helper";
import Heading from "./Heading";
import ExpandableResource from "../ExpandableResource";
import ServiceRow from "./ServiceRow";
import VeleroForm from "../forms/VeleroForm";
import InputArray from "./InputArray";
import KeyValueArray from "./KeyValueArray";
Expand Down Expand Up @@ -68,22 +69,38 @@ export default class ValuesForm extends Component<PropsType, StateType> {

switch (item.type) {
case "heading":
return <Heading key={i}>{item.label}</Heading>;
return (
<Heading key={i} docs={item.settings?.docs}>
{item.label}
</Heading>
);
case "subtitle":
return <Helper key={i}>{item.label}</Helper>;
case "service-ip-list":
if (Array.isArray(item.value)) {
return (
<ResourceList key={key}>
{item.value?.map((service: any, i: number) => {
return <ServiceRow service={service} key={i} />;
})}
</ResourceList>
);
}
case "resource-list":
if (Array.isArray(item.value)) {
return (
<ResourceList key={key}>
{item.value?.map((resource: any, i: number) => {
return (
<ExpandableResource
key={i}
resource={resource}
isLast={i === item.value.length - 1}
roundAllCorners={true}
/>
);
if (resource.data) {
return (
<ExpandableResource
key={i}
resource={resource}
isLast={i === item.value.length - 1}
roundAllCorners={true}
/>
);
}
})}
</ResourceList>
);
Expand Down Expand Up @@ -181,6 +198,7 @@ export default class ValuesForm extends Component<PropsType, StateType> {
<InputRow
key={key}
width="100%"
placeholder={item.placeholder}
isRequired={item.required}
type="password"
value={this.getInputValue(item)}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/main/home/launch/Launch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Loading from "components/Loading";
import LaunchFlow from "./launch-flow/LaunchFlow";
import NoClusterPlaceholder from "../NoClusterPlaceholder";

import hardcodedNames from "./hardcodedNameDict";
import { hardcodedNames } from "shared/hardcodedNameDict";
import semver from "semver";

const tabOptions = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PorterTemplate } from "shared/types";
import Helper from "components/values-form/Helper";
import Selector from "components/Selector";

import hardcodedNames from "../hardcodedNameDict";
import { hardcodedNames } from "shared/hardcodedNameDict";

type PropsType = {
currentTemplate: any;
Expand Down
20 changes: 0 additions & 20 deletions dashboard/src/main/home/launch/hardcodedNameDict.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion dashboard/src/main/home/launch/launch-flow/LaunchFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import api from "shared/api";
import { Context } from "shared/Context";
import { pushFiltered } from "shared/routing";

import hardcodedNames from "../hardcodedNameDict";
import { hardcodedNames } from "shared/hardcodedNameDict";
import SourcePage from "./SourcePage";
import SettingsPage from "./SettingsPage";

Expand Down
53 changes: 53 additions & 0 deletions dashboard/src/shared/hardcodedNameDict.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const hardcodedNames: { [key: string]: string } = {
docker: "Docker",
"https-issuer": "HTTPS Issuer",
metabase: "Metabase",
mongodb: "MongoDB",
mysql: "MySQL",
postgresql: "PostgreSQL",
redis: "Redis",
ubuntu: "Ubuntu",
web: "Web Service",
worker: "Worker",
job: "Job",
"cert-manager": "Cert Manager",
elasticsearch: "Elasticsearch",
prometheus: "Prometheus",
rabbitmq: "RabbitMQ",
logdna: "LogDNA",
"tailscale-relay": "Tailscale",
};

const hardcodedIcons: { [key: string]: string } = {
"https-issuer":
"https://cdn4.iconfinder.com/data/icons/macster-2/100/https__-512.png",
metabase:
"https://pbs.twimg.com/profile_images/961380992727465985/4unoiuHt.jpg",
mongodb:
"https://bitnami.com/assets/stacks/mongodb/img/mongodb-stack-220x234.png",
mysql: "https://www.mysql.com/common/logos/logo-mysql-170x115.png",
postgresql:
"https://bitnami.com/assets/stacks/postgresql/img/postgresql-stack-110x117.png",
redis:
"https://cdn4.iconfinder.com/data/icons/redis-2/1451/Untitled-2-512.png",
ubuntu: "Ubuntu",
web:
"https://user-images.githubusercontent.com/65516095/111255214-07d3da80-85ed-11eb-99e2-fddcbdb99bdb.png",
worker:
"https://user-images.githubusercontent.com/65516095/111255250-1b7f4100-85ed-11eb-8bd1-7b17be3e0e06.png",
job:
"https://user-images.githubusercontent.com/65516095/111258413-4e2c3800-85f3-11eb-8a6a-88e03460f8fe.png",
"cert-manager":
"https://raw.githubusercontent.com/jetstack/cert-manager/master/logo/logo.png",
elasticsearch:
"https://ria.gallerycdn.vsassets.io/extensions/ria/elastic/0.13.3/1530754501320/Microsoft.VisualStudio.Services.Icons.Default",
prometheus:
"https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/assets/prometheus_logo-cb55bb5c346.png",
rabbitmq:
"https://bitnami.com/assets/stacks/rabbitmq/img/rabbitmq-stack-220x234.png",
logdna:
"https://user-images.githubusercontent.com/65516095/118185526-a2447480-b40a-11eb-9bdb-82aa0a306f26.png",
"tailscale-relay": "Tailscale",
};

export { hardcodedNames, hardcodedIcons };
1 change: 1 addition & 0 deletions dashboard/src/shared/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface FormElement {
placeholder?: string;
value?: any;
settings?: {
docs?: string;
default?: number | string | boolean;
options?: any[];
omitUnitFromValue?: boolean;
Expand Down
4 changes: 4 additions & 0 deletions internal/models/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type FormTab struct {
Name string `yaml:"name" json:"name"`
Label string `yaml:"label" json:"label"`
Sections []*FormSection `yaml:"sections" json:"sections,omitempty"`
Settings struct {
OmitFromLaunch bool `yaml:"omitFromLaunch,omitempty" json:"omitFromLaunch,omitempty"`
} `yaml:"settings,omitempty" json:"settings,omitempty"`
}

// FormSection is a section of a form
Expand All @@ -51,6 +54,7 @@ type FormContent struct {
Placeholder string `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
Value interface{} `yaml:"value,omitempty" json:"value,omitempty"`
Settings struct {
Docs string `yaml:"docs,omitempty" json:"docs,omitempty"`
Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
Unit interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
OmitUnitFromValue bool `yaml:"omitUnitFromValue,omitempty" json:"omitUnitFromValue,omitempty"`
Expand Down

0 comments on commit c686f1e

Please sign in to comment.