feat: add network and depends_on fields

pull/92/head
corpulent 3 years ago
parent 1249355d56
commit fa23834235

@ -68,6 +68,34 @@ const General = () => {
}} }}
/> />
<Records
name="dependsOn"
title="Depends on"
fields={(index: number) => [
{
name: `dependsOn[${index}]`,
placeholder: "Service name",
required: false,
type: "text"
}
]}
newValue={""}
/>
<Records
name="networks"
title="Networks"
fields={(index: number) => [
{
name: `networks[${index}]`,
placeholder: "Network name",
required: false,
type: "text"
}
]}
newValue={""}
/>
<Records <Records
name="labels" name="labels"
title="Labels" title="Labels"

@ -106,11 +106,13 @@ const initialValues: IEditServiceForm = {
imageTag: "", imageTag: "",
serviceName: "", serviceName: "",
containerName: "", containerName: "",
networks: [],
profiles: [], profiles: [],
ports: [], ports: [],
environmentVariables: [], environmentVariables: [],
volumes: [], volumes: [],
labels: [] labels: [],
dependsOn: []
}; };
yup.addMethod<yup.StringSchema>(yup.string, "port", function (message) { yup.addMethod<yup.StringSchema>(yup.string, "port", function (message) {
@ -288,10 +290,12 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
const { const {
build, build,
deploy, deploy,
depends_on,
image, image,
container_name = "", container_name = "",
environment, environment,
volumes, volumes,
networks,
ports, ports,
profiles, profiles,
labels labels
@ -458,6 +462,7 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
accessMode accessMode
}; };
}), }),
networks: (networks as string[]) ?? (initialValues.networks as string[]),
ports: ports0.map((port) => { ports: ports0.map((port) => {
const slashIndex = port.lastIndexOf("/"); const slashIndex = port.lastIndexOf("/");
const protocol = slashIndex >= 0 ? port.substring(slashIndex + 1) : ""; const protocol = slashIndex >= 0 ? port.substring(slashIndex + 1) : "";
@ -475,7 +480,8 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
}), }),
profiles: profiles ?? initialValues.profiles, profiles: profiles ?? initialValues.profiles,
labels: labels:
extractObjectOrArray("=", "key", "value", labels) ?? initialValues.labels extractObjectOrArray("=", "key", "value", labels) ?? initialValues.labels,
dependsOn: (depends_on as string[]) ?? (initialValues.dependsOn as string[])
}; };
}; };
@ -486,9 +492,11 @@ export const getFinalValues = (
const { const {
build, build,
deploy, deploy,
dependsOn,
environmentVariables, environmentVariables,
ports, ports,
profiles, profiles,
networks,
volumes, volumes,
labels labels
} = values; } = values;
@ -590,6 +598,7 @@ export const getFinalValues = (
(volume.accessMode ? `:${volume.accessMode}` : "") (volume.accessMode ? `:${volume.accessMode}` : "")
) )
), ),
networks: pruneArray(networks),
ports: pruneArray( ports: pruneArray(
ports.map( ports.map(
(port) => (port) =>
@ -599,7 +608,8 @@ export const getFinalValues = (
) )
), ),
profiles: pruneArray(profiles), profiles: pruneArray(profiles),
labels: packArrayAsObject(labels, "key", "value") labels: packArrayAsObject(labels, "key", "value"),
depends_on: pruneArray(dependsOn)
} }
}; };
}; };

@ -69,7 +69,7 @@ export default function Project() {
const [language, setLanguage] = useState("yaml"); const [language, setLanguage] = useState("yaml");
const [version, setVersion] = useState("3"); const [version, setVersion] = useState("3");
const [copyText, setCopyText] = useState("Copy"); const [copyText, setCopyText] = useState("Copy");
const [nodes, setNodes] = useState({}); const [nodes, setNodes] = useState<Record<string, any>>({});
const [connections, setConnections] = useState<[[string, string]] | []>([]); const [connections, setConnections] = useState<[[string, string]] | []>([]);
const [networks, setNetworks] = useState<Record<string, any>>({}); const [networks, setNetworks] = useState<Record<string, any>>({});
const [projectName, setProjectName] = useState( const [projectName, setProjectName] = useState(
@ -278,6 +278,20 @@ export default function Project() {
}; };
const onUpdateEndpoint = (nodeItem: IServiceNodeItem) => { const onUpdateEndpoint = (nodeItem: IServiceNodeItem) => {
const key = nodeItem.key;
if (Array.isArray(nodeItem.serviceConfig.depends_on)) {
nodeItem.serviceConfig.depends_on.forEach((dep: string) => {
const depObject = Object.keys(nodes).find((key: string) => {
const node = nodes[key];
if (node.canvasConfig.node_name === dep) {
return node;
}
});
onConnectionAttached([key, depObject]);
});
}
setNodes({ ...nodes, [nodeItem.key]: nodeItem }); setNodes({ ...nodes, [nodeItem.key]: nodeItem });
}; };

@ -454,6 +454,7 @@ export interface IEditServiceForm {
imageName: string; imageName: string;
imageTag: string; imageTag: string;
containerName: string; containerName: string;
networks: string[];
profiles: string[]; profiles: string[];
ports: { ports: {
hostPort: string; hostPort: string;
@ -473,6 +474,7 @@ export interface IEditServiceForm {
key: string; key: string;
value: string; value: string;
}[]; }[];
dependsOn: string[];
} }
export interface IEditVolumeForm { export interface IEditVolumeForm {

Loading…
Cancel
Save