diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/CreateEnvironment/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/CreateEnvironment/index.js new file mode 100644 index 00000000..d01f98fb --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/CreateEnvironment/index.js @@ -0,0 +1,70 @@ +import React, { useEffect, useRef } from 'react'; +import Portal from "components/Portal/index"; +import Modal from "components/Modal/index"; +import { useFormik } from 'formik'; +import { addWorkspace } from 'providers/ReduxStore/slices/workspaces'; +import * as Yup from 'yup'; +import { useDispatch } from 'react-redux'; + +const CreateEnvironment = ({onClose}) => { + const dispatch = useDispatch(); + const inputRef = useRef(); + const formik = useFormik({ + enableReinitialize: true, + initialValues: { + name: "" + }, + validationSchema: Yup.object({ + name: Yup.string() + .min(1, 'must be atleast 1 characters') + .max(30, 'must be 30 characters or less') + .required('name is required') + }), + onSubmit: (values) => { + // dispatch(addWorkspace({name: values.name})); + // onClose(); + } + }); + + useEffect(() => { + if(inputRef && inputRef.current) { + inputRef.current.focus(); + } + }, [inputRef]); + + const onSubmit = () => { + formik.handleSubmit(); + } + + return ( + + +
+
+ + + {formik.touched.name && formik.errors.name ? ( +
{formik.errors.name}
+ ) : null} +
+
+
+
+ ); +} + +export default CreateEnvironment; + diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/StyledWrapper.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/StyledWrapper.js new file mode 100644 index 00000000..48b87421 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/StyledWrapper.js @@ -0,0 +1,15 @@ +import styled from 'styled-components'; + +const Wrapper = styled.div` + button.submit { + color: white; + background-color: var(--color-background-danger) !important; + border: inherit !important; + + &:hover { + border: inherit !important; + } + } +`; + +export default Wrapper; diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/index.js new file mode 100644 index 00000000..f13aee31 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/DeleteEnvironment/index.js @@ -0,0 +1,34 @@ +import React from 'react'; +import Portal from "components/Portal/index"; +import Modal from "components/Modal/index"; +// import { deleteWorkspace } from 'providers/ReduxStore/slices/workspaces'; +import { useDispatch } from 'react-redux'; +import StyledWrapper from './StyledWrapper'; + +const DeleteEnvironment = ({onClose, environment}) => { + const dispatch = useDispatch(); + const onConfirm = () =>{ + // dispatch(deleteWorkspace({workspaceUid: workspace.uid})) + onClose(); + }; + + return ( + + + + Are you sure you want to delete {environment.name} ? + + + + + ); +} + +export default DeleteEnvironment; + diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/EnvironmentDetails/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/EnvironmentDetails/index.js new file mode 100644 index 00000000..35f5a486 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/EnvironmentDetails/index.js @@ -0,0 +1,25 @@ +import React, { useEffect, useState } from "react"; +import { IconEdit, IconTrash } from "@tabler/icons"; +import RenameEnvironment from "../../RenameEnvironment"; +import DeleteEnvironment from "../../DeleteEnvironment"; +// import StyledWrapper from "./StyledWrapper"; + +const EnvironmentDetails = ({selected}) => { + const [ openEditModal, setOpenEditModal] = useState(false); + const [ openDeleteModal, setOpenDeleteModal] = useState(false); + + return ( +
+ {selected.name} +
+ setOpenEditModal(true)}/> + setOpenDeleteModal(true)}/> +
+ {openEditModal && setOpenEditModal(false)} environment={selected} />} + {openDeleteModal && setOpenDeleteModal(false)} environment={selected} />} +
+ + ); +}; + +export default EnvironmentDetails; diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/StyledWrapper.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/StyledWrapper.js new file mode 100644 index 00000000..c44482cc --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/StyledWrapper.js @@ -0,0 +1,43 @@ +import styled from "styled-components"; + +const StyledWrapper = styled.div` + margin-left: -1rem; + margin-block: -1.5rem; + .environments-sidebar { + margin-bottom: 8px; + background-color: #ffffff; + min-height: 300px; + } + + .environment-item { + min-width: 150px; + display: block; + position: relative; + cursor: pointer; + padding: 8px 10px; + color: rgb(35, 35, 35); + border-bottom: 1px solid #eaecef; + + &:hover { + text-decoration: none; + background-color: #f6f8fa; + } + } + + .active { + background-color: #e1e4e8; + &:hover { + text-decoration: none; + background-color: #e1e4e8; + } + } + + .create-env { + padding: 8px 10px; + cursor: pointer; + border-bottom: none; + color: var(--color-text-link); + } +`; + +export default StyledWrapper; \ No newline at end of file diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/index.js new file mode 100644 index 00000000..19a15d03 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/Layout/index.js @@ -0,0 +1,40 @@ +import React, { useEffect, useState, forwardRef, useRef } from "react"; +import EnvironmentDetails from "./EnvironmentDetails"; +import CreateEnvironment from "../CreateEnvironment/index"; +import StyledWrapper from "./StyledWrapper"; + +const environments = [ + {name: "My env", uid: 123}, + {name: "hjdgfh dj", uid: 3876}, + {name: "hjdgfer dj", uid: 4678}, +]; + +const Layout = () => { + const [selectedEnvironment, setSelectedEnvironment] = useState({}); + const [openCreateModal, setOpenCreateModal] = useState(false); + + useEffect(() => { + setSelectedEnvironment(environments[0]); + }, []); + + return ( + +
+
+
+ {environments && environments.length && environments.map((env) => ( +
setSelectedEnvironment(env)}> + {env.name} +
+ ))} +

setOpenCreateModal(true)}> + Create

+
+
+ +
+ {openCreateModal && setOpenCreateModal(false)}/>} +
+ ); +}; + +export default Layout; diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/RenameEnvironment/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/RenameEnvironment/index.js new file mode 100644 index 00000000..7023a997 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/RenameEnvironment/index.js @@ -0,0 +1,70 @@ +import React, { useEffect, useRef } from 'react'; +import Portal from "components/Portal/index"; +import Modal from "components/Modal/index"; +import { useFormik } from 'formik'; +// import { rename } from 'providers/ReduxStore/slices/environments'; +import * as Yup from 'yup'; +import { useDispatch } from 'react-redux'; + +const RenameEnvironment = ({onClose, environment}) => { + // const dispatch = useDispatch(); + const inputRef = useRef(); + const formik = useFormik({ + enableReinitialize: true, + initialValues: { + name: environment.name + }, + validationSchema: Yup.object({ + name: Yup.string() + .min(1, 'must be atleast 1 characters') + .max(30, 'must be 30 characters or less') + .required('name is required') + }), + onSubmit: (values) => { + // dispatch(rename({name: values.name, uid: environment.uid})); + onClose(); + } + }); + + useEffect(() => { + if(inputRef && inputRef.current) { + inputRef.current.focus(); + } + }, [inputRef]); + + const onSubmit = () => { + formik.handleSubmit(); + } + + return ( + + +
+
+ + + {formik.touched.name && formik.errors.name ? ( +
{formik.errors.name}
+ ) : null} +
+
+
+
+ ); +} + +export default RenameEnvironment; + diff --git a/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/index.js b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/index.js new file mode 100644 index 00000000..3e2c05a0 --- /dev/null +++ b/packages/bruno-app/src/components/EnvironmentSelector/EnvironmentSettings/index.js @@ -0,0 +1,43 @@ +import Modal from "components/Modal/index"; +import React, { useState } from "react"; +import CreateEnvironment from "./CreateEnvironment"; +import Layout from "./Layout"; + +const EnvironmentSettings = ({onClose}) => { + const environments = [ + {name: "My env", uid: 123}, + {name: "hjdgfh dj", uid: 3876}, + ]; + const [openCreateModal, setOpenCreateModal] = useState(false) + + if(!environments.length) { + return ( + +

No environment found!

+ + {openCreateModal && setOpenCreateModal(false)}/>} +
+ ) + } + + return ( + + + + ) + +} + +export default EnvironmentSettings; diff --git a/packages/bruno-app/src/components/EnvironmentSelector/index.js b/packages/bruno-app/src/components/EnvironmentSelector/index.js index 7f24dee0..7d5de34f 100644 --- a/packages/bruno-app/src/components/EnvironmentSelector/index.js +++ b/packages/bruno-app/src/components/EnvironmentSelector/index.js @@ -1,10 +1,12 @@ -import React, { useRef, forwardRef } from 'react'; +import React, { useRef, forwardRef, useState } from 'react'; import Dropdown from 'components/Dropdown'; import { IconAdjustmentsHorizontal, IconCaretDown } from '@tabler/icons'; +import EnvironmentSettings from "./EnvironmentSettings"; import StyledWrapper from './StyledWrapper'; const EnvironmentSelector = () => { const dropdownTippyRef = useRef(); + const [openSettingsModal, setOpenSettingsModal] = useState(false); const Icon = forwardRef((props, ref) => { return ( @@ -36,9 +38,7 @@ const EnvironmentSelector = () => { }}> No Environment -
{ - dropdownTippyRef.current.hide(); - }}> +
setOpenSettingsModal(true)}>
@@ -46,6 +46,7 @@ const EnvironmentSelector = () => {
+ {openSettingsModal && setOpenSettingsModal(false)}/>} ); }; diff --git a/packages/bruno-app/src/components/Modal/index.js b/packages/bruno-app/src/components/Modal/index.js index 0d5badc8..e3a6c57a 100644 --- a/packages/bruno-app/src/components/Modal/index.js +++ b/packages/bruno-app/src/components/Modal/index.js @@ -18,10 +18,14 @@ const ModalContent = ({children}) => ( ); -const ModalFooter = ({confirmText, cancelText, handleSubmit, handleCancel, confirmDisabled, hideCancel}) => { +const ModalFooter = ({confirmText, cancelText, handleSubmit, handleCancel, confirmDisabled, hideCancel, hideFooter}) => { confirmText = confirmText || 'Save'; cancelText = cancelText || 'Cancel'; + if (hideFooter) { + return null; + } + return (
@@ -80,14 +84,15 @@ const Modal = ({
closeModal()} /> {children} - {!hideFooter ? closeModal()} handleSubmit={handleConfirm} confirmDisabled={confirmDisabled} hideCancel={hideCancel} - /> : null} + hideFooter={hideFooter} + />
{/* Clicking on backdrop closes the modal */} diff --git a/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/AddWorkspace/index.js b/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/AddWorkspace/index.js index 46340234..a8a8f987 100644 --- a/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/AddWorkspace/index.js +++ b/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/AddWorkspace/index.js @@ -52,7 +52,7 @@ const AddWorkspace = ({onClose}) => { >
- + { >
- +