diff --git a/package-lock.json b/package-lock.json
index 7fdfd83c49..ebf2a11a14 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,6 +26,7 @@
"jest": "^29.2.0",
"pretty-quick": "^3.1.3",
"randomstring": "^1.2.2",
+ "react-color": "^2.19.3",
"ts-jest": "^29.0.5"
}
},
@@ -2674,6 +2675,15 @@
"graphql-ws": ">= 4.5.0"
}
},
+ "node_modules/@icons/material": {
+ "version": "0.2.4",
+ "resolved": "https://registry.npmjs.org/@icons/material/-/material-0.2.4.tgz",
+ "integrity": "sha512-QPcGmICAPbGLGb6F/yNf/KzKqvFx8z5qx3D1yFqVAjoFmXK35EgyW+cJ57Te3CNsmzblwtzakLGFqHPqrfb4Tw==",
+ "dev": true,
+ "peerDependencies": {
+ "react": "*"
+ }
+ },
"node_modules/@istanbuljs/load-nyc-config": {
"version": "1.1.0",
"dev": true,
@@ -11818,6 +11828,12 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/material-colors": {
+ "version": "1.2.6",
+ "resolved": "https://registry.npmjs.org/material-colors/-/material-colors-1.2.6.tgz",
+ "integrity": "sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==",
+ "dev": true
+ },
"node_modules/mdn-data": {
"version": "2.0.14",
"dev": true,
@@ -14269,6 +14285,24 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-color": {
+ "version": "2.19.3",
+ "resolved": "https://registry.npmjs.org/react-color/-/react-color-2.19.3.tgz",
+ "integrity": "sha512-LEeGE/ZzNLIsFWa1TMe8y5VYqr7bibneWmvJwm1pCn/eNmrabWDh659JSPn9BuaMpEfU83WTOJfnCcjDZwNQTA==",
+ "dev": true,
+ "dependencies": {
+ "@icons/material": "^0.2.4",
+ "lodash": "^4.17.15",
+ "lodash-es": "^4.17.15",
+ "material-colors": "^1.2.1",
+ "prop-types": "^15.5.10",
+ "reactcss": "^1.2.0",
+ "tinycolor2": "^1.4.1"
+ },
+ "peerDependencies": {
+ "react": "*"
+ }
+ },
"node_modules/react-dnd": {
"version": "16.0.1",
"license": "MIT",
@@ -14352,6 +14386,7 @@
},
"node_modules/react-is": {
"version": "18.2.0",
+ "dev": true,
"license": "MIT"
},
"node_modules/react-pdf": {
@@ -14421,6 +14456,15 @@
"react-dom": ">=16.14.0"
}
},
+ "node_modules/reactcss": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/reactcss/-/reactcss-1.2.3.tgz",
+ "integrity": "sha512-KiwVUcFu1RErkI97ywr8nvx8dNOpT03rbnma0SSalTYjkrPYaEajR4a/MRt6DZ46K6arDRbWMNHF+xH7G7n/8A==",
+ "dev": true,
+ "dependencies": {
+ "lodash": "^4.0.1"
+ }
+ },
"node_modules/read-config-file": {
"version": "6.2.0",
"dev": true,
@@ -17712,7 +17756,7 @@
},
"packages/bruno-electron": {
"name": "bruno",
- "version": "v1.1.1",
+ "version": "v1.2.0",
"dependencies": {
"@aws-sdk/credential-providers": "^3.425.0",
"@usebruno/js": "0.9.2",
@@ -19970,6 +20014,12 @@
"meros": "^1.1.4"
}
},
+ "@icons/material": {
+ "version": "0.2.4",
+ "resolved": "https://registry.npmjs.org/@icons/material/-/material-0.2.4.tgz",
+ "integrity": "sha512-QPcGmICAPbGLGb6F/yNf/KzKqvFx8z5qx3D1yFqVAjoFmXK35EgyW+cJ57Te3CNsmzblwtzakLGFqHPqrfb4Tw==",
+ "dev": true
+ },
"@istanbuljs/load-nyc-config": {
"version": "1.1.0",
"dev": true,
@@ -21445,8 +21495,7 @@
}
},
"@tabler/icons": {
- "version": "1.119.0",
- "requires": {}
+ "version": "1.119.0"
},
"@tauri-apps/cli": {
"version": "1.2.2",
@@ -22018,8 +22067,7 @@
}
},
"@usebruno/schema": {
- "version": "file:packages/bruno-schema",
- "requires": {}
+ "version": "file:packages/bruno-schema"
},
"@usebruno/testbench": {
"version": "file:packages/bruno-testbench",
@@ -22163,8 +22211,7 @@
},
"@webpack-cli/configtest": {
"version": "1.2.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"@webpack-cli/info": {
"version": "1.5.0",
@@ -22175,8 +22222,7 @@
},
"@webpack-cli/serve": {
"version": "1.7.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"@xtuc/ieee754": {
"version": "1.2.0",
@@ -22258,8 +22304,7 @@
},
"ajv-keywords": {
"version": "3.5.2",
- "dev": true,
- "requires": {}
+ "dev": true
},
"amdefine": {
"version": "0.0.8"
@@ -22851,7 +22896,7 @@
"node-machine-id": "^1.1.12",
"qs": "^6.11.0",
"socks-proxy-agent": "^8.0.2",
- "tough-cookie": "*",
+ "tough-cookie": "^4.1.3",
"uuid": "^9.0.0",
"vm2": "^3.9.13",
"yup": "^0.32.11"
@@ -23212,8 +23257,7 @@
"chai-string": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/chai-string/-/chai-string-1.5.0.tgz",
- "integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==",
- "requires": {}
+ "integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw=="
},
"chalk": {
"version": "4.1.2",
@@ -23648,8 +23692,7 @@
},
"css-declaration-sorter": {
"version": "6.3.1",
- "dev": true,
- "requires": {}
+ "dev": true
},
"css-loader": {
"version": "6.7.3",
@@ -23768,8 +23811,7 @@
},
"cssnano-utils": {
"version": "3.1.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"csso": {
"version": "4.2.0",
@@ -25004,8 +25046,7 @@
}
},
"goober": {
- "version": "2.1.11",
- "requires": {}
+ "version": "2.1.11"
},
"gopd": {
"version": "1.0.1",
@@ -25399,8 +25440,7 @@
},
"icss-utils": {
"version": "5.1.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"idb": {
"version": "7.1.1"
@@ -26000,8 +26040,7 @@
},
"jest-pnp-resolver": {
"version": "1.2.3",
- "dev": true,
- "requires": {}
+ "dev": true
},
"jest-regex-util": {
"version": "29.2.0",
@@ -26699,6 +26738,12 @@
}
}
},
+ "material-colors": {
+ "version": "1.2.6",
+ "resolved": "https://registry.npmjs.org/material-colors/-/material-colors-1.2.6.tgz",
+ "integrity": "sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==",
+ "dev": true
+ },
"mdn-data": {
"version": "2.0.14",
"dev": true
@@ -26715,8 +26760,7 @@
"merge-refs": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/merge-refs/-/merge-refs-1.2.2.tgz",
- "integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw==",
- "requires": {}
+ "integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw=="
},
"merge-stream": {
"version": "2.0.0",
@@ -26726,8 +26770,7 @@
"version": "1.4.1"
},
"meros": {
- "version": "1.2.1",
- "requires": {}
+ "version": "1.2.1"
},
"methods": {
"version": "1.1.2"
@@ -27604,23 +27647,19 @@
},
"postcss-discard-comments": {
"version": "5.1.2",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-discard-duplicates": {
"version": "5.1.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-discard-empty": {
"version": "5.1.1",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-discard-overridden": {
"version": "5.1.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-js": {
"version": "3.0.3",
@@ -27702,8 +27741,7 @@
},
"postcss-modules-extract-imports": {
"version": "3.0.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-modules-local-by-default": {
"version": "4.0.0",
@@ -27736,8 +27774,7 @@
},
"postcss-normalize-charset": {
"version": "5.1.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"postcss-normalize-display-values": {
"version": "5.1.0",
@@ -28174,6 +28211,21 @@
"loose-envify": "^1.1.0"
}
},
+ "react-color": {
+ "version": "2.19.3",
+ "resolved": "https://registry.npmjs.org/react-color/-/react-color-2.19.3.tgz",
+ "integrity": "sha512-LEeGE/ZzNLIsFWa1TMe8y5VYqr7bibneWmvJwm1pCn/eNmrabWDh659JSPn9BuaMpEfU83WTOJfnCcjDZwNQTA==",
+ "dev": true,
+ "requires": {
+ "@icons/material": "^0.2.4",
+ "lodash": "^4.17.15",
+ "lodash-es": "^4.17.15",
+ "material-colors": "^1.2.1",
+ "prop-types": "^15.5.10",
+ "reactcss": "^1.2.0",
+ "tinycolor2": "^1.4.1"
+ }
+ },
"react-dnd": {
"version": "16.0.1",
"requires": {
@@ -28213,11 +28265,11 @@
}
},
"react-inspector": {
- "version": "6.0.2",
- "requires": {}
+ "version": "6.0.2"
},
"react-is": {
- "version": "18.2.0"
+ "version": "18.2.0",
+ "dev": true
},
"react-pdf": {
"version": "7.5.1",
@@ -28257,6 +28309,15 @@
"classnames": "^2.3.2"
}
},
+ "reactcss": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/reactcss/-/reactcss-1.2.3.tgz",
+ "integrity": "sha512-KiwVUcFu1RErkI97ywr8nvx8dNOpT03rbnma0SSalTYjkrPYaEajR4a/MRt6DZ46K6arDRbWMNHF+xH7G7n/8A==",
+ "dev": true,
+ "requires": {
+ "lodash": "^4.0.1"
+ }
+ },
"read-config-file": {
"version": "6.2.0",
"dev": true,
@@ -28379,8 +28440,7 @@
}
},
"redux-thunk": {
- "version": "2.4.2",
- "requires": {}
+ "version": "2.4.2"
},
"regenerate": {
"version": "1.4.2",
@@ -28617,8 +28677,7 @@
},
"rollup-plugin-peer-deps-external": {
"version": "2.2.4",
- "dev": true,
- "requires": {}
+ "dev": true
},
"rollup-plugin-postcss": {
"version": "4.0.2",
@@ -29176,8 +29235,7 @@
},
"style-loader": {
"version": "3.3.1",
- "dev": true,
- "requires": {}
+ "dev": true
},
"styled-components": {
"version": "5.3.6",
@@ -29206,8 +29264,7 @@
}
},
"styled-jsx": {
- "version": "5.0.7",
- "requires": {}
+ "version": "5.0.7"
},
"stylehacks": {
"version": "5.1.1",
@@ -29880,8 +29937,7 @@
}
},
"use-sync-external-store": {
- "version": "1.2.0",
- "requires": {}
+ "version": "1.2.0"
},
"utf8-byte-length": {
"version": "1.0.4",
@@ -30042,8 +30098,7 @@
},
"acorn-import-assertions": {
"version": "1.8.0",
- "dev": true,
- "requires": {}
+ "dev": true
},
"schema-utils": {
"version": "3.1.1",
diff --git a/package.json b/package.json
index eab3cd9da9..c19543d819 100644
--- a/package.json
+++ b/package.json
@@ -18,12 +18,13 @@
"@faker-js/faker": "^7.6.0",
"@jest/globals": "^29.2.0",
"@playwright/test": "^1.27.1",
+ "fs-extra": "^11.1.1",
"husky": "^8.0.3",
"jest": "^29.2.0",
"pretty-quick": "^3.1.3",
"randomstring": "^1.2.2",
- "ts-jest": "^29.0.5",
- "fs-extra": "^11.1.1"
+ "react-color": "^2.19.3",
+ "ts-jest": "^29.0.5"
},
"scripts": {
"dev:web": "npm run dev --workspace=packages/bruno-app",
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSelector/StyledWrapper.js b/packages/bruno-app/src/components/Environments/EnvironmentSelector/StyledWrapper.js
index a7c57209bb..b1c09d5f24 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSelector/StyledWrapper.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSelector/StyledWrapper.js
@@ -1,7 +1,7 @@
import styled from 'styled-components';
const Wrapper = styled.div`
- .current-enviroment {
+ .current-environment {
background-color: ${(props) => props.theme.sidebar.badge.bg};
border-radius: 15px;
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSelector/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSelector/index.js
index f7ea334fc0..ac1ec69261 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSelector/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSelector/index.js
@@ -1,4 +1,4 @@
-import React, { useRef, forwardRef, useState } from 'react';
+import React, { useRef, forwardRef, useState, useEffect } from 'react';
import find from 'lodash/find';
import Dropdown from 'components/Dropdown';
import { selectEnvironment } from 'providers/ReduxStore/slices/collections/actions';
@@ -12,12 +12,20 @@ const EnvironmentSelector = ({ collection }) => {
const dispatch = useDispatch();
const dropdownTippyRef = useRef();
const [openSettingsModal, setOpenSettingsModal] = useState(false);
- const { environments, activeEnvironmentUid } = collection;
+ const { activeEnvironmentUid } = collection;
+ const [environments, setEnvironments] = useState(collection.environments);
+ useEffect(() => {
+ console.log('useEffect EnvironmentSelector');
+ }, [environments]);
const activeEnvironment = activeEnvironmentUid ? find(environments, (e) => e.uid === activeEnvironmentUid) : null;
const Icon = forwardRef((props, ref) => {
return (
-
+
{activeEnvironment ? activeEnvironment.name : 'No Environment'}
@@ -52,7 +60,8 @@ const EnvironmentSelector = ({ collection }) => {
dropdownTippyRef.current.hide();
}}
>
-
{e.name}
+
+
{e.name}
))
: null}
@@ -74,7 +83,14 @@ const EnvironmentSelector = ({ collection }) => {
- {openSettingsModal && setOpenSettingsModal(false)} />}
+ {openSettingsModal && (
+ setOpenSettingsModal(false)}
+ />
+ )}
);
};
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentColor/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentColor/index.js
new file mode 100644
index 0000000000..a0b1c47dbe
--- /dev/null
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentColor/index.js
@@ -0,0 +1,70 @@
+import React from 'react';
+import { useRef, useEffect } from 'react';
+import toast from 'react-hot-toast';
+import { useTheme } from 'providers/Theme';
+import { useDispatch } from 'react-redux';
+import { saveEnvironmentColor } from 'providers/ReduxStore/slices/collections/actions';
+import { useFormik } from 'formik';
+import * as Yup from 'yup';
+import { CirclePicker } from 'react-color';
+import { selectEnvironment as _selectEnvironment } from 'providers/ReduxStore/slices/collections';
+
+const EnvironmentColor = ({ environment, onColorChange, collection }) => {
+ const dispatch = useDispatch();
+
+ const formik = useFormik({
+ enableReinitialize: true,
+ initialValues: {
+ color: environment.color || ''
+ },
+ validationSchema: Yup.object({
+ color: Yup.string().optional()
+ }),
+ onSubmit: (values) => {
+ if (!formik.dirty) {
+ toast.error('Nothing to save');
+ return;
+ }
+ dispatch(saveEnvironmentColor(values.color, environment.uid, collection.uid))
+ .then(() => {
+ toast.success('Environment color changed successfully');
+ onColorChange(values.color);
+ })
+ .catch((e) => {
+ console.log(e);
+ toast.error('An error occurred while changing the environment color');
+ });
+ }
+ });
+
+ useEffect(() => {
+ if (formik.dirty) {
+ formik.handleSubmit();
+ }
+ }, [formik.values.color]);
+
+ return (
+ formik.setFieldValue('color', color.hex)}
+ value={formik.values.color || ''}
+ />
+ );
+};
+export default EnvironmentColor;
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js
index ba6b0e9e35..436afdde18 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js
@@ -52,7 +52,6 @@ const EnvironmentVariables = ({ environment, collection }) => {
const ErrorMessage = ({ name }) => {
const meta = formik.getFieldMeta(name);
- console.log(name, meta);
if (!meta.error) {
return null;
}
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.js
index f8b9e364eb..3c9abca458 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.js
@@ -1,17 +1,26 @@
import { IconCopy, IconDatabase, IconEdit, IconTrash } from '@tabler/icons';
-import { useState } from 'react';
+import { useState, useEffect } from 'react';
import CopyEnvironment from '../../CopyEnvironment';
import DeleteEnvironment from '../../DeleteEnvironment';
import RenameEnvironment from '../../RenameEnvironment';
import EnvironmentVariables from './EnvironmentVariables';
+import EnvironmentColor from '../EnvironmentDetails/EnvironmentColor';
-const EnvironmentDetails = ({ environment, collection }) => {
+const EnvironmentDetails = ({ environment, onColorChange, collection }) => {
const [openEditModal, setOpenEditModal] = useState(false);
const [openDeleteModal, setOpenDeleteModal] = useState(false);
const [openCopyModal, setOpenCopyModal] = useState(false);
+ const [iconDatabaseColor, setIconDatabaseColor] = useState(environment.color);
+
+ useEffect(() => {
+ setIconDatabaseColor(environment.color);
+ }, [environment]);
return (
-
+
{openEditModal && (
setOpenEditModal(false)} environment={environment} collection={collection} />
)}
@@ -27,7 +36,7 @@ const EnvironmentDetails = ({ environment, collection }) => {
)}
-
+
{environment.name}
@@ -37,9 +46,8 @@ const EnvironmentDetails = ({ environment, collection }) => {
-
-
-
+
+
);
};
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
index 9886b54bb4..a6059e4744 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
@@ -8,7 +8,7 @@ import ImportEnvironment from '../ImportEnvironment';
import ManageSecrets from '../ManageSecrets';
import StyledWrapper from './StyledWrapper';
-const EnvironmentList = ({ collection }) => {
+const EnvironmentList = ({ collection, setEnvironments }) => {
const { environments } = collection;
const [selectedEnvironment, setSelectedEnvironment] = useState(null);
const [openCreateModal, setOpenCreateModal] = useState(false);
@@ -18,6 +18,13 @@ const EnvironmentList = ({ collection }) => {
const envUids = environments ? environments.map((env) => env.uid) : [];
const prevEnvUids = usePrevious(envUids);
+ const onColorChange = (environment, color) => {
+ const updatedEnvironments = environments.map((e) => (e.uid === environment.uid ? { ...e, color: color } : e));
+ console.log('onColorChange', updatedEnvironments);
+ setSelectedEnvironment({ ...selectedEnvironment, color: color });
+ setEnvironments(updatedEnvironments);
+ };
+
useEffect(() => {
if (selectedEnvironment) {
return;
@@ -85,7 +92,11 @@ const EnvironmentList = ({ collection }) => {
-
+ onColorChange(selectedEnvironment, color)}
+ collection={collection}
+ />
);
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js
index 6daccc3746..30b47266f5 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js
@@ -1,15 +1,19 @@
import Modal from 'components/Modal/index';
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import CreateEnvironment from './CreateEnvironment';
import EnvironmentList from './EnvironmentList';
import StyledWrapper from './StyledWrapper';
import ImportEnvironment from './ImportEnvironment';
-const EnvironmentSettings = ({ collection, onClose }) => {
+const EnvironmentSettings = ({ collection, setEnvironments, onClose }) => {
const { environments } = collection;
const [openCreateModal, setOpenCreateModal] = useState(false);
const [openImportModal, setOpenImportModal] = useState(false);
+ useEffect(() => {
+ console.log('useEffect EnvironmentSettings');
+ }, [collection]);
+
if (!environments || !environments.length) {
return (
@@ -48,7 +52,7 @@ const EnvironmentSettings = ({ collection, onClose }) => {
return (
-
+
);
};
diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
index 2ef107954b..6c373dd00c 100644
--- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
+++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
@@ -826,6 +826,29 @@ export const saveEnvironment = (variables, environmentUid, collectionUid) => (di
});
};
+export const saveEnvironmentColor = (color, environmentUid, collectionUid) => (dispatch, getState) => {
+ return new Promise((resolve, reject) => {
+ const state = getState();
+ const collection = findCollectionByUid(state.collections.collections, collectionUid);
+ if (!collection) {
+ return reject(new Error('Collection not found'));
+ }
+
+ const collectionCopy = cloneDeep(collection);
+ const environment = findEnvironmentInCollection(collectionCopy, environmentUid);
+ if (!environment) {
+ return reject(new Error('Environment not found'));
+ }
+
+ const updatedEnvironment = { ...environment, color: color };
+ environmentSchema
+ .validate(updatedEnvironment)
+ .then(() => ipcRenderer.invoke('renderer:save-environment', collection.pathname, updatedEnvironment))
+ .then(resolve)
+ .catch(reject);
+ });
+};
+
export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, getState) => {
return new Promise((resolve, reject) => {
const state = getState();
diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
index 24655f4f09..b48b94e968 100644
--- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
+++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
@@ -126,7 +126,7 @@ export const collectionsSlice = createSlice({
}
},
saveEnvironment: (state, action) => {
- const { variables, environmentUid, collectionUid } = action.payload;
+ const { variables, color, environmentUid, collectionUid } = action.payload;
const collection = findCollectionByUid(state.collections, collectionUid);
if (collection) {
@@ -134,6 +134,7 @@ export const collectionsSlice = createSlice({
if (environment) {
environment.variables = variables;
+ environment.color = color;
}
}
},
diff --git a/packages/bruno-lang/v2/src/envToJson.js b/packages/bruno-lang/v2/src/envToJson.js
index eef4de375d..429451d32e 100644
--- a/packages/bruno-lang/v2/src/envToJson.js
+++ b/packages/bruno-lang/v2/src/envToJson.js
@@ -2,7 +2,7 @@ const ohm = require('ohm-js');
const _ = require('lodash');
const grammar = ohm.grammar(`Bru {
- BruEnvFile = (vars | secretvars)*
+ BruEnvFile = (vars | secretvars | color)*
nl = "\\r"? "\\n"
st = " " | "\\t"
@@ -27,6 +27,7 @@ const grammar = ohm.grammar(`Bru {
secretvars = "vars:secret" array
vars = "vars" dictionary
+ color = "color:" any*
}`);
const mapPairListToKeyValPairs = (pairList = []) => {
@@ -84,7 +85,8 @@ const sem = grammar.createSemantics().addAttribute('ast', {
BruEnvFile(tags) {
if (!tags || !tags.ast || !tags.ast.length) {
return {
- variables: []
+ variables: [],
+ color: '#B80000'
};
}
@@ -151,6 +153,11 @@ const sem = grammar.createSemantics().addAttribute('ast', {
return {
variables: vars
};
+ },
+ color: (_1, anystring) => {
+ return {
+ color: anystring.sourceString.trim()
+ };
}
});
diff --git a/packages/bruno-lang/v2/src/jsonToEnv.js b/packages/bruno-lang/v2/src/jsonToEnv.js
index 42d0a4281d..a7b4a89e71 100644
--- a/packages/bruno-lang/v2/src/jsonToEnv.js
+++ b/packages/bruno-lang/v2/src/jsonToEnv.js
@@ -18,13 +18,16 @@ const envToJson = (json) => {
return ` ${prefix}${name}`;
});
+ const color = _.get(json, 'color', '');
+
+ let output = '';
+
if (!variables || !variables.length) {
- return `vars {
+ output += `vars {
}
`;
}
- let output = '';
if (vars.length) {
output += `vars {
${vars.join('\n')}
@@ -39,6 +42,12 @@ ${secretVars.join(',\n')}
`;
}
+ if (color !== undefined) {
+ console.log('jsonToEnv color', color);
+ output += `color: ${color}
+`;
+ }
+
return output;
};
diff --git a/packages/bruno-schema/src/collections/index.js b/packages/bruno-schema/src/collections/index.js
index 37e6629af9..ca10579ab4 100644
--- a/packages/bruno-schema/src/collections/index.js
+++ b/packages/bruno-schema/src/collections/index.js
@@ -15,7 +15,8 @@ const environmentVariablesSchema = Yup.object({
const environmentSchema = Yup.object({
uid: uidSchema,
name: Yup.string().min(1).required('name is required'),
- variables: Yup.array().of(environmentVariablesSchema).required('variables are required')
+ variables: Yup.array().of(environmentVariablesSchema).required('variables are required'),
+ color: Yup.string().optional()
})
.noUnknown(true)
.strict();