feat: updates

This commit is contained in:
lohxt1 2024-09-30 16:36:19 +05:30
parent d8bf27f288
commit f088cdb504
3 changed files with 42 additions and 5 deletions

View File

@ -59,7 +59,7 @@ const EnvironmentVariables = ({ environment, collection, setIsModified, original
const ErrorMessage = ({ name }) => { const ErrorMessage = ({ name }) => {
const meta = formik.getFieldMeta(name); const meta = formik.getFieldMeta(name);
if (!meta.error) { if (!meta.error || !meta.touched) {
return null; return null;
} }

View File

@ -62,7 +62,7 @@ const EnvironmentVariables = ({ environment, setIsModified, originalEnvironmentV
const ErrorMessage = ({ name }) => { const ErrorMessage = ({ name }) => {
const meta = formik.getFieldMeta(name); const meta = formik.getFieldMeta(name);
if (!meta.error) { if (!meta.error || !meta.touched) {
return null; return null;
} }

View File

@ -1,5 +1,6 @@
const _ = require('lodash'); const _ = require('lodash');
const Store = require('electron-store'); const Store = require('electron-store');
const { encryptString, decryptString } = require('../utils/encryption');
class GlobalEnvironmentsStore { class GlobalEnvironmentsStore {
constructor() { constructor() {
@ -9,16 +10,52 @@ class GlobalEnvironmentsStore {
}); });
} }
isValidValue(val) {
return typeof val === 'string' && val.length >= 0;
}
encryptGlobalEnvironmentVariables({ globalEnvironments }) {
return globalEnvironments?.map(env => {
const variables = env.variables?.map(v => ({
...v,
value: v?.secret ? (this.isValidValue(v.value) ? encryptString(v.value) : '') : v?.value
})) || [];
return {
...env,
variables
};
});
}
decryptGlobalEnvironmentVariables({ globalEnvironments }) {
return globalEnvironments?.map(env => {
const variables = env.variables?.map(v => ({
...v,
value: v?.secret ? (this.isValidValue(v.value) ? decryptString(v.value) : '') : v?.value
})) || [];
return {
...env,
variables
};
});
}
getGlobalEnvironments() { getGlobalEnvironments() {
return this.store.get('environments', []); let globalEnvironments = this.store.get('environments', []);
globalEnvironments = this.decryptGlobalEnvironmentVariables({ globalEnvironments });
return globalEnvironments;
} }
getActiveGlobalEnvironmentUid() { getActiveGlobalEnvironmentUid() {
return this.store.get('activeGlobalEnvironmentUid', null); return this.store.get('activeGlobalEnvironmentUid', null);
} }
setGlobalEnvironments(environments) { setGlobalEnvironments(globalEnvironments) {
return this.store.set('environments', environments); globalEnvironments = this.encryptGlobalEnvironmentVariables({ globalEnvironments });
return this.store.set('environments', globalEnvironments);
} }
setActiveGlobalEnvironmentUid(uid) { setActiveGlobalEnvironmentUid(uid) {