Merge pull request #72 from nuxxapp/refactor/canvas-data

Updated project data, removed old interfaces, and added node icon component
pull/73/head
Samuel Rowe 3 years ago committed by GitHub
commit 7ec8a03e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,28 @@
import { DatabaseIcon, ServerIcon, ChipIcon } from "@heroicons/react/solid";
type NodeIconProps = {
nodeType: string;
};
const NodeIcon = ({ nodeType }: NodeIconProps) => {
switch (nodeType) {
case "SERVICE":
return (
<ServerIcon className="w-3 h-3 text-gray-500 absolute top-2 right-2" />
);
case "VOLUME":
return (
<DatabaseIcon className="w-3 h-3 text-gray-500 absolute top-2 right-2" />
);
case "NETWORK":
return (
<ChipIcon className="w-3 h-3 text-gray-500 absolute top-2 right-2" />
);
default:
return (
<ServerIcon className="w-3 h-3 text-gray-600 absolute top-2 right-2" />
);
}
};
export default NodeIcon;

@ -1,9 +1,9 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { ServerIcon } from "@heroicons/react/outline";
import { truncateStr } from "../../utils"; import { truncateStr } from "../../utils";
import { IServiceNodeItem, CallbackFunction } from "../../types"; import { IServiceNodeItem, CallbackFunction } from "../../types";
import eventBus from "../../events/eventBus"; import eventBus from "../../events/eventBus";
import { Popover } from "./Popover"; import { Popover } from "./Popover";
import NodeIcon from "./NodeIcon";
interface INodeProps { interface INodeProps {
node: IServiceNodeItem; node: IServiceNodeItem;
@ -56,9 +56,9 @@ export default function ServiceNode(props: INodeProps) {
)} )}
<div className="relative node-label w-full py-2 px-4"> <div className="relative node-label w-full py-2 px-4">
<> <>
{node.canvasConfig.service_name && ( {node.canvasConfig.node_name && (
<div className="text-sm font-semibold overflow-x-hidden"> <div className="text-sm font-semibold overflow-x-hidden">
{truncateStr(node.canvasConfig.service_name, 12)} {truncateStr(node.canvasConfig.node_name, 12)}
</div> </div>
)} )}
@ -68,7 +68,7 @@ export default function ServiceNode(props: INodeProps) {
</div> </div>
)} )}
<ServerIcon className="w-3 h-3 text-gray-600 absolute top-2 right-2" /> <NodeIcon nodeType={node.type} />
</> </>
</div> </div>
</div> </div>

@ -1,9 +1,9 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { DatabaseIcon } from "@heroicons/react/outline";
import { truncateStr } from "../../utils"; import { truncateStr } from "../../utils";
import { IVolumeNodeItem, CallbackFunction } from "../../types"; import { IVolumeNodeItem, CallbackFunction } from "../../types";
import eventBus from "../../events/eventBus"; import eventBus from "../../events/eventBus";
import { Popover } from "./Popover"; import { Popover } from "./Popover";
import NodeIcon from "./NodeIcon";
interface INodeProps { interface INodeProps {
node: IVolumeNodeItem; node: IVolumeNodeItem;
@ -62,7 +62,7 @@ export default function VolumeNode(props: INodeProps) {
</div> </div>
)} )}
<DatabaseIcon className="w-3 h-3 text-gray-600 absolute top-2 right-2" /> <NodeIcon nodeType={node.type} />
</> </>
</div> </div>
</div> </div>

@ -23,7 +23,7 @@ const ModalServiceCreate = (props: IModalServiceProps) => {
}; };
const validationSchema = yup.object({ const validationSchema = yup.object({
canvasConfig: yup.object({ canvasConfig: yup.object({
service_name: yup node_name: yup
.string() .string()
.max(256, "service name should be 256 characters or less") .max(256, "service name should be 256 characters or less")
.required("service name is required") .required("service name is required")
@ -146,10 +146,7 @@ const ModalServiceCreate = (props: IModalServiceProps) => {
<button <button
className="btn-util" className="btn-util"
type="button" type="button"
onClick={() => { onClick={formik.submitForm}
onAddEndpoint(formik.values);
formik.resetForm();
}}
> >
Add Add
</button> </button>

@ -32,7 +32,7 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
}; };
const validationSchema = yup.object({ const validationSchema = yup.object({
canvasConfig: yup.object({ canvasConfig: yup.object({
service_name: yup node_name: yup
.string() .string()
.max(256, "service name should be 256 characters or less") .max(256, "service name should be 256 characters or less")
.required("service name is required") .required("service name is required")

@ -3,7 +3,7 @@ import TextField from "../../global/FormElements/InputField";
const General = () => { const General = () => {
return ( return (
<> <>
<TextField label="Service name" name="canvasConfig.service_name" /> <TextField label="Service name" name="canvasConfig.node_name" />
<TextField label="Container name" name="serviceConfig.container_name" /> <TextField label="Container name" name="serviceConfig.container_name" />
</> </>
); );

@ -4,7 +4,10 @@ import * as yup from "yup";
import { XIcon } from "@heroicons/react/outline"; import { XIcon } from "@heroicons/react/outline";
import General from "./General"; import General from "./General";
import Labels from "./Labels"; import Labels from "./Labels";
import { topLevelVolumeConfigInitialValues } from "../../../utils"; import {
topLevelVolumeConfigInitialValues,
volumeConfigCanvasInitialValues
} from "../../../utils";
import { CallbackFunction } from "../../../types"; import { CallbackFunction } from "../../../types";
interface IModalVolumeCreate { interface IModalVolumeCreate {
@ -68,6 +71,9 @@ const ModalVolumeCreate = (props: IModalVolumeCreate) => {
<Formik <Formik
initialValues={{ initialValues={{
canvasConfig: {
...volumeConfigCanvasInitialValues()
},
volumeConfig: { volumeConfig: {
...topLevelVolumeConfigInitialValues() ...topLevelVolumeConfigInitialValues()
}, },

@ -110,13 +110,7 @@ export default function Project() {
position: canvasPosition, position: canvasPosition,
nodes: nodes, nodes: nodes,
connections: connections connections: connections
}, }
configs: [],
networks: [],
secrets: [],
services: nodes,
version: 3,
volumes: []
} }
}; };

@ -26,14 +26,6 @@ export interface IProject {
modified_at: string; modified_at: string;
} }
export interface IContainer {
name: string;
args?: string[];
command?: string[];
image: string;
imagePullPolicy: string;
}
export interface INodeLibraryItem { export interface INodeLibraryItem {
id: number; id: number;
name: string; name: string;
@ -64,7 +56,8 @@ export interface IFlatConnection {
} }
export interface ICanvasConfig { export interface ICanvasConfig {
service_name: string; node_name?: string;
node_icon?: string;
} }
export interface IGraphData { export interface IGraphData {
@ -321,12 +314,6 @@ export interface IService {
}; };
volumes_from: string[]; volumes_from: string[];
working_dir: string; working_dir: string;
tag: string;
}
export interface IDockerCompose {
version: string;
services: IService[];
} }
export interface IServiceNodeItem extends INodeItem { export interface IServiceNodeItem extends INodeItem {
@ -353,12 +340,6 @@ export interface IProjectPayload {
nodes: any; nodes: any;
connections: any; connections: any;
}; };
configs: [];
networks: [];
secrets: [];
services: any;
version: number;
volumes: [];
}; };
} }

@ -1,2 +0,0 @@
export const ServiceNodeConfiguration =
'{"canvasConfig":{"name":""},"key":"service","type":"SERVICE","inputs":["op_source"],"outputs":[]}';

@ -106,12 +106,26 @@ export const attachUUID = (key: string): string => {
return key + "-" + uuidv4(); return key + "-" + uuidv4();
}; };
export const iconByNodeType: Record<string, string> = {
service: "ServerIcon",
volume: "DatabaseIcon",
network: "ChipIcon"
};
export const getClientNodeItem = ( export const getClientNodeItem = (
nodeItem: IServiceNodeItem, nodeItem: IServiceNodeItem,
library: INodeLibraryItem library: INodeLibraryItem
): IServiceNodeItem => { ): IServiceNodeItem => {
const uniqueKey = attachUUID(nodeItem.key); const uniqueKey = attachUUID(nodeItem.key);
if (
nodeItem.canvasConfig.node_icon &&
nodeItem.canvasConfig.node_icon.length === 0
) {
nodeItem.canvasConfig.node_icon =
iconByNodeType[nodeItem.type] || "ServerIcon";
}
return { return {
...nodeItem, ...nodeItem,
key: uniqueKey, key: uniqueKey,
@ -188,9 +202,16 @@ export const topLevelNetworkConfigInitialValues =
}; };
}; };
export const volumeConfigCanvasInitialValues = (): ICanvasConfig => {
return {
node_icon: ""
};
};
export const serviceConfigCanvasInitialValues = (): ICanvasConfig => { export const serviceConfigCanvasInitialValues = (): ICanvasConfig => {
return { return {
service_name: "unnamed" node_name: "unnamed",
node_icon: ""
}; };
}; };

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save