From 8d41b94c368f18f766071bc027ae70e9547cc360 Mon Sep 17 00:00:00 2001 From: DomySh Date: Thu, 30 Jun 2022 19:21:14 +0200 Subject: [PATCH] Change port front and backend finished --- backend/app.py | 2 + ...geInternalPort.tsx => ChangePortModal.tsx} | 51 +++++++++++++++---- frontend/src/components/ServiceRow/index.tsx | 17 +++---- 3 files changed, 51 insertions(+), 19 deletions(-) rename frontend/src/components/ServiceRow/{ChangeInternalPort.tsx => ChangePortModal.tsx} (51%) diff --git a/backend/app.py b/backend/app.py index d654a0f..20aea62 100644 --- a/backend/app.py +++ b/backend/app.py @@ -206,6 +206,8 @@ async def change_port(service_id: str, change_port:ChangePortForm, auth: bool = if not change_port.port is None: sql_inj+=" public_port = ? " query.append(change_port.port) + if not change_port.port is None and not change_port.internalPort is None: + sql_inj += "," if not change_port.internalPort is None: sql_inj+=" internal_port = ? " query.append(change_port.internalPort) diff --git a/frontend/src/components/ServiceRow/ChangeInternalPort.tsx b/frontend/src/components/ServiceRow/ChangePortModal.tsx similarity index 51% rename from frontend/src/components/ServiceRow/ChangeInternalPort.tsx rename to frontend/src/components/ServiceRow/ChangePortModal.tsx index e643a93..535ce6e 100755 --- a/frontend/src/components/ServiceRow/ChangeInternalPort.tsx +++ b/frontend/src/components/ServiceRow/ChangePortModal.tsx @@ -1,21 +1,33 @@ -import { Button, Group, NumberInput, Space, Notification, Modal } from '@mantine/core'; +import { Button, Group, NumberInput, Space, Notification, Modal, Center, Title } from '@mantine/core'; import { useForm } from '@mantine/hooks'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { changeports, fireUpdateRequest, okNotify } from '../../js/utils'; import { ImCross } from "react-icons/im" import { Service } from '../../js/models'; +import { BsArrowDownSquareFill } from 'react-icons/bs'; type InputForm = { internalPort:number, + port:number } -function ChangeInternalPort({ service, opened, onClose }:{ service:Service, opened:boolean, onClose:()=>void }) { +function ChangePortModal({ service, opened, onClose }:{ service:Service, opened:boolean, onClose:()=>void }) { const form = useForm({ - initialValues: { internalPort:service.internal_port }, - validationRules:{ internalPort: (value) => value>0 && value<65536 && value != service.internal_port } + initialValues: { + internalPort: service.internal_port, + port: service.public_port + }, + validationRules:{ + internalPort: (value) => value>0 && value<65536, + port: (value) => value>0 && value<65536 + } }) + useEffect(()=>{ + form.setValues({internalPort: service.internal_port, port:service.public_port}) + },[opened]) + const close = () =>{ onClose() form.reset() @@ -44,19 +56,40 @@ function ChangeInternalPort({ service, opened, onClose }:{ service:Service, open } - return + return
+ + + + +
+ + + + +
The change of the ports will cause a temporarily shutdown of the service! ⚠️
+ + + - + @@ -71,4 +104,4 @@ function ChangeInternalPort({ service, opened, onClose }:{ service:Service, open } -export default ChangeInternalPort; +export default ChangePortModal; diff --git a/frontend/src/components/ServiceRow/index.tsx b/frontend/src/components/ServiceRow/index.tsx index 6823f2f..d9a258e 100755 --- a/frontend/src/components/ServiceRow/index.tsx +++ b/frontend/src/components/ServiceRow/index.tsx @@ -9,7 +9,7 @@ import { deleteservice, errorNotify, fireUpdateRequest, okNotify, pauseservice, import { BsArrowRepeat, BsTrashFill } from 'react-icons/bs'; import { TbNumbers } from 'react-icons/tb'; import { BiRename } from 'react-icons/bi' -import ChangeInternalPort from './ChangeInternalPort'; +import ChangePortModal from './ChangePortModal'; //"status":"stop"/"wait"/"active"/"pause", function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) { @@ -27,7 +27,7 @@ function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) const [tooltipStopOpened, setTooltipStopOpened] = useState(false); const [deleteModal, setDeleteModal] = useState(false) const [changePortModal, setChangePortModal] = useState(false) - const [chooseInternalPortModal, setChooseInternalPortModal] = useState(false) + const [choosePortModal, setChoosePortModal] = useState(false) const stopService = async () => { setButtonLoading(true) @@ -146,14 +146,11 @@ function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) Rename service } onClick={()=>{}}>Change service name - Public proxy port - } onClick={()=>{}}>Change port + Change ports + } onClick={()=>setChoosePortModal(true)}>Change port + } onClick={()=>setChangePortModal(true)}>Regen proxy port - Internal proxy port - } onClick={()=>setChangePortModal(true)}>Regen port - } onClick={()=>setChooseInternalPortModal(true)}>Choose port - - Delete service + Danger zone } onClick={()=>setDeleteModal(true)}>Delete Service @@ -219,7 +216,7 @@ function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) action={changePort} opened={changePortModal} /> - setChooseInternalPortModal(false)} opened={chooseInternalPortModal} /> + setChoosePortModal(false)} opened={choosePortModal} /> }