From 5da51fc95aa77b393df7394443d6c243eb87c3bb Mon Sep 17 00:00:00 2001 From: Artem Golub Date: Tue, 12 Jul 2022 22:29:01 +0300 Subject: [PATCH] feat: add initial volume modal, types --- .../src/components/Modal/Volume/General.tsx | 32 +++++ .../src/components/Modal/Volume/Labels.tsx | 6 + .../src/components/Modal/Volume/index.tsx | 116 ++++++++++++++++++ .../frontend/src/components/Project/index.tsx | 17 ++- services/frontend/src/types/index.ts | 69 +++++++---- services/frontend/src/utils/index.ts | 10 +- 6 files changed, 224 insertions(+), 26 deletions(-) create mode 100644 services/frontend/src/components/Modal/Volume/General.tsx create mode 100644 services/frontend/src/components/Modal/Volume/Labels.tsx create mode 100644 services/frontend/src/components/Modal/Volume/index.tsx diff --git a/services/frontend/src/components/Modal/Volume/General.tsx b/services/frontend/src/components/Modal/Volume/General.tsx new file mode 100644 index 0000000..00639c8 --- /dev/null +++ b/services/frontend/src/components/Modal/Volume/General.tsx @@ -0,0 +1,32 @@ +const General = (props: any) => { + const { formik } = props; + + return ( + <> +
+
+
+ +
+ +
+
+
+
+ + ); +}; +export default General; diff --git a/services/frontend/src/components/Modal/Volume/Labels.tsx b/services/frontend/src/components/Modal/Volume/Labels.tsx new file mode 100644 index 0000000..9838a34 --- /dev/null +++ b/services/frontend/src/components/Modal/Volume/Labels.tsx @@ -0,0 +1,6 @@ +const Labels = (props: any) => { + const { formik } = props; + + return <>; +}; +export default Labels; diff --git a/services/frontend/src/components/Modal/Volume/index.tsx b/services/frontend/src/components/Modal/Volume/index.tsx new file mode 100644 index 0000000..680a892 --- /dev/null +++ b/services/frontend/src/components/Modal/Volume/index.tsx @@ -0,0 +1,116 @@ +import { useState } from "react"; +import { useFormik } from "formik"; +import { XIcon } from "@heroicons/react/outline"; +import General from "./General"; +import Labels from "./Labels"; +import { topLevelVolumeConfigInitialValues } from "../../../utils"; +import { CallbackFunction } from "../../../types"; + +interface IModalVolume { + onHide: CallbackFunction; +} + +const ModalVolume = (props: IModalVolume) => { + const { onHide } = props; + const [openTab, setOpenTab] = useState("General"); + + const formik = useFormik({ + initialValues: { + ...topLevelVolumeConfigInitialValues() + }, + onSubmit: () => undefined + }); + const tabs = [ + { + name: "General", + href: "#", + current: true, + hidden: false + }, + { + name: "Labels", + href: "#", + current: false, + hidden: false + } + ]; + const classNames = (...classes: string[]) => { + return classes.filter(Boolean).join(" "); + }; + + return ( +
+
+
+
+
+
+

Top level volumes

+ +
+ +
+ + +
+
+ {openTab === "General" && } + {openTab === "Labels" && } + +
+
+ +
+ +
+
+
+
+
+ ); +}; + +export default ModalVolume; diff --git a/services/frontend/src/components/Project/index.tsx b/services/frontend/src/components/Project/index.tsx index 739eecd..2071a61 100644 --- a/services/frontend/src/components/Project/index.tsx +++ b/services/frontend/src/components/Project/index.tsx @@ -34,6 +34,7 @@ import ModalConfirmDelete from "../Modal/ConfirmDelete"; import ModalServiceCreate from "../Modal/Service/Create"; import ModalServiceEdit from "../Modal/Service/Edit"; import ModalNetwork from "../Modal/Network"; +import ModalVolume from "../Modal/Volume"; import CodeEditor from "../CodeEditor"; export default function Project() { @@ -281,6 +282,10 @@ export default function Project() { setShowNetworksModal(false)} /> ) : null} + {showVolumesModal ? ( + setShowVolumesModal(false)} /> + ) : null} + {showModalCreateService ? ( setShowModalCreateService(false)} @@ -391,19 +396,23 @@ export default function Project() { Service + + diff --git a/services/frontend/src/types/index.ts b/services/frontend/src/types/index.ts index 5393ba9..4caf949 100644 --- a/services/frontend/src/types/index.ts +++ b/services/frontend/src/types/index.ts @@ -1,9 +1,8 @@ import { AnchorId } from "@jsplumb/common"; import { Dictionary } from "lodash"; +import { KeyValuePair } from "tailwindcss/types/config"; import { NodeGroupType } from "./enums"; -type NetworkImapConfig = "subnet"; - type KeyValPair = { [x: string]: string | number; }; @@ -78,23 +77,16 @@ export interface IAnchor { position: AnchorId; } -export interface IVolume { - type: string; - source: string; - target: string; - read_only: boolean; - bind: { - propagation: string; - create_host_path: boolean; - selinux: string; - }; - volume: { - nocopy: boolean; - }; - tmpfs: { - size: string | number; +export interface IVolumeTopLevel { + driver: string; + driver_opts: { + type: string; + o: string; + device: string; }; - consistency: string; + external: boolean; + labels: string[] | KeyValuePair; + name: string; } export interface INetworkTopLevel { @@ -148,10 +140,26 @@ export interface IService { cap_drop: string[]; cgroup_parent: string; command: string | string[]; - configs: string[] | KeyValPair[]; + configs: + | string[] + | { + [x: string]: { + source: string; + target: string; + uid: string; + gid: string; + mode: number; + }; + }; container_name: string; credential_spec: KeyValPair; - depends_on: string[] | { [key: string]: string | number | KeyValPair }; + depends_on: + | string[] + | { + [key: string]: { + condition: string; + }; + }; deploy: { endpoint_mode: string; labels: string[] | { [key: string]: string }; @@ -291,7 +299,26 @@ export interface IService { }; user: string; userns_mode: string; - volumes: string[] | IVolume; + volumes: + | string[] + | { + type: string; + source: string; + target: string; + read_only: boolean; + bind: { + propagation: string; + create_host_path: boolean; + selinux: string; + }; + volume: { + nocopy: boolean; + }; + tmpfs: { + size: string | number; + }; + consistency: string; + }; volumes_from: string[]; working_dir: string; tag: string; diff --git a/services/frontend/src/utils/index.ts b/services/frontend/src/utils/index.ts index 40fed1b..76cd396 100644 --- a/services/frontend/src/utils/index.ts +++ b/services/frontend/src/utils/index.ts @@ -16,7 +16,8 @@ import { INodeLibraryItem, INodeGroup, ICanvasConfig, - INetworkTopLevel + INetworkTopLevel, + IVolumeTopLevel } from "../types"; export function ensure( @@ -173,6 +174,13 @@ export const getNodeKeyFromConnectionId = (uuid: string) => { return key; }; +export const topLevelVolumeConfigInitialValues = + (): Partial => { + return { + name: "unnamed" + }; + }; + export const topLevelNetworkConfigInitialValues = (): Partial => { return {