mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-16 17:51:48 +01:00
fix: global env ui fixes (#3305)
This commit is contained in:
parent
a4ad4f6073
commit
dddc79c709
@ -7,6 +7,7 @@ import toast from 'react-hot-toast';
|
|||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
import { selectGlobalEnvironment } from 'providers/ReduxStore/slices/global-environments';
|
import { selectGlobalEnvironment } from 'providers/ReduxStore/slices/global-environments';
|
||||||
|
import ToolHint from 'components/ToolHint/index';
|
||||||
|
|
||||||
const EnvironmentSelector = () => {
|
const EnvironmentSelector = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@ -18,12 +19,14 @@ const EnvironmentSelector = () => {
|
|||||||
|
|
||||||
const Icon = forwardRef((props, ref) => {
|
const Icon = forwardRef((props, ref) => {
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className={`current-environment flex flex-row gap-1 rounded-xl text-xs cursor-pointer items-center justify-center select-none ${activeGlobalEnvironmentUid? 'environment-active': ''}`}>
|
<div ref={ref} className={`current-environment flex flex-row gap-1 rounded-xl text-xs cursor-pointer items-center justify-center select-none ${activeGlobalEnvironmentUid? 'environment-active': ''}`}>
|
||||||
<IconWorld className="globe" size={16} strokeWidth={1.5} />
|
<ToolHint text="Global Environments" toolhintId="GlobalEnvironmentsToolhintId" className='flex flex-row'>
|
||||||
{
|
<IconWorld className="globe" size={16} strokeWidth={1.5} />
|
||||||
activeEnvironment ? <div>{activeEnvironment?.name}</div> : null
|
{
|
||||||
}
|
activeEnvironment ? <div>{activeEnvironment?.name}</div> : null
|
||||||
</div>
|
}
|
||||||
|
</ToolHint>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,6 +39,11 @@ const Wrapper = styled.div`
|
|||||||
font-size: 0.8125rem;
|
font-size: 0.8125rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tooltip-mod {
|
||||||
|
font-size: 11px !important;
|
||||||
|
width: 150px !important;
|
||||||
|
}
|
||||||
|
|
||||||
input[type='text'] {
|
input[type='text'] {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: solid 1px transparent;
|
border: solid 1px transparent;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useRef, useEffect } from 'react';
|
import React, { useRef, useEffect } from 'react';
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import { IconTrash } from '@tabler/icons';
|
import { IconTrash, IconAlertCircle } from '@tabler/icons';
|
||||||
import { useTheme } from 'providers/Theme';
|
import { useTheme } from 'providers/Theme';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import SingleLineEditor from 'components/SingleLineEditor';
|
import SingleLineEditor from 'components/SingleLineEditor';
|
||||||
@ -11,6 +11,7 @@ import * as Yup from 'yup';
|
|||||||
import { variableNameRegex } from 'utils/common/regex';
|
import { variableNameRegex } from 'utils/common/regex';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { saveGlobalEnvironment } from 'providers/ReduxStore/slices/global-environments';
|
import { saveGlobalEnvironment } from 'providers/ReduxStore/slices/global-environments';
|
||||||
|
import { Tooltip } from 'react-tooltip';
|
||||||
|
|
||||||
const EnvironmentVariables = ({ environment, setIsModified, originalEnvironmentVariables }) => {
|
const EnvironmentVariables = ({ environment, setIsModified, originalEnvironmentVariables }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@ -62,14 +63,15 @@ const EnvironmentVariables = ({ environment, setIsModified, originalEnvironmentV
|
|||||||
|
|
||||||
const ErrorMessage = ({ name }) => {
|
const ErrorMessage = ({ name }) => {
|
||||||
const meta = formik.getFieldMeta(name);
|
const meta = formik.getFieldMeta(name);
|
||||||
|
const id = uuid();
|
||||||
if (!meta.error || !meta.touched) {
|
if (!meta.error || !meta.touched) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label htmlFor={name} className="text-red-500">
|
<span>
|
||||||
{meta.error}
|
<IconAlertCircle id={id} className="text-red-600 cursor-pointer " size={20} />
|
||||||
</label>
|
<Tooltip className="tooltip-mod" anchorId={id} html={meta.error || ''} />
|
||||||
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,19 +129,21 @@ const EnvironmentVariables = ({ environment, setIsModified, originalEnvironmentV
|
|||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input
|
<div className="flex items-center">
|
||||||
type="text"
|
<input
|
||||||
autoComplete="off"
|
type="text"
|
||||||
autoCorrect="off"
|
autoComplete="off"
|
||||||
autoCapitalize="off"
|
autoCorrect="off"
|
||||||
spellCheck="false"
|
autoCapitalize="off"
|
||||||
className="mousetrap"
|
spellCheck="false"
|
||||||
id={`${index}.name`}
|
className="mousetrap"
|
||||||
name={`${index}.name`}
|
id={`${index}.name`}
|
||||||
value={variable.name}
|
name={`${index}.name`}
|
||||||
onChange={formik.handleChange}
|
value={variable.name}
|
||||||
/>
|
onChange={formik.handleChange}
|
||||||
<ErrorMessage name={`${index}.name`} />
|
/>
|
||||||
|
<ErrorMessage name={`${index}.name`} />
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="flex flex-row flex-nowrap">
|
<td className="flex flex-row flex-nowrap">
|
||||||
<div className="overflow-hidden grow w-full relative">
|
<div className="overflow-hidden grow w-full relative">
|
||||||
|
@ -20,18 +20,17 @@ const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironme
|
|||||||
const prevEnvUids = usePrevious(envUids);
|
const prevEnvUids = usePrevious(envUids);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEnvironment) {
|
if (!environments?.length) {
|
||||||
setOriginalEnvironmentVariables(selectedEnvironment.variables);
|
setSelectedEnvironment(null);
|
||||||
|
setOriginalEnvironmentVariables([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const environment = environments?.find(env => env?.uid === activeEnvironmentUid);
|
const environment = environments?.find(env => env.uid === activeEnvironmentUid) || environments?.[0];
|
||||||
if (environment) {
|
setSelectedEnvironment(environment);
|
||||||
setSelectedEnvironment(environment);
|
setOriginalEnvironmentVariables(environment?.variables || []);
|
||||||
} else {
|
}, [environments, activeEnvironmentUid]);
|
||||||
setSelectedEnvironment(environments && environments.length ? environments[0] : null);
|
|
||||||
}
|
|
||||||
}, [environments, selectedEnvironment]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (prevEnvUids && prevEnvUids.length && envUids.length > prevEnvUids.length) {
|
if (prevEnvUids && prevEnvUids.length && envUids.length > prevEnvUids.length) {
|
||||||
|
@ -62,7 +62,7 @@ const EnvironmentSettings = ({ globalEnvironments, activeGlobalEnvironmentUid, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal size="lg" title="Environments" handleCancel={onClose} hideFooter={true}>
|
<Modal size="lg" title="Global Environments" handleCancel={onClose} hideFooter={true}>
|
||||||
<EnvironmentList
|
<EnvironmentList
|
||||||
environments={globalEnvironments}
|
environments={globalEnvironments}
|
||||||
activeEnvironmentUid={activeGlobalEnvironmentUid}
|
activeEnvironmentUid={activeGlobalEnvironmentUid}
|
||||||
|
@ -69,11 +69,8 @@ const CollectionToolBar = ({ collection }) => {
|
|||||||
</ToolHint>
|
</ToolHint>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<ToolHint text="Global Environments" toolhintId="GlobalEnvironmentsToolhintId">
|
<GlobalEnvironmentSelector />
|
||||||
<GlobalEnvironmentSelector />
|
|
||||||
</ToolHint>
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<EnvironmentSelector collection={collection} />
|
<EnvironmentSelector collection={collection} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,8 @@ const ToolHint = ({
|
|||||||
tooltipStyle = {},
|
tooltipStyle = {},
|
||||||
place = 'top',
|
place = 'top',
|
||||||
offset,
|
offset,
|
||||||
theme = null
|
theme = null,
|
||||||
|
className = ''
|
||||||
}) => {
|
}) => {
|
||||||
const { theme: contextTheme } = useTheme();
|
const { theme: contextTheme } = useTheme();
|
||||||
const appliedTheme = theme || contextTheme;
|
const appliedTheme = theme || contextTheme;
|
||||||
@ -29,7 +30,7 @@ const ToolHint = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<span id={toolhintId}>{children}</span>
|
<span id={toolhintId} className={className}>{children}</span>
|
||||||
<StyledWrapper theme={appliedTheme}>
|
<StyledWrapper theme={appliedTheme}>
|
||||||
<ReactToolHint
|
<ReactToolHint
|
||||||
anchorId={toolhintId}
|
anchorId={toolhintId}
|
||||||
|
Loading…
Reference in New Issue
Block a user