mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-24 17:03:47 +01:00
Merge branch 'main' of github.com:usebruno/bruno
This commit is contained in:
commit
1b0495c7b0
@ -24,13 +24,15 @@ class MultiLineEditor extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// Initialize CodeMirror as a single line editor
|
// Initialize CodeMirror as a single line editor
|
||||||
/** @type {import("codemirror").Editor} */
|
/** @type {import("codemirror").Editor} */
|
||||||
|
const variables = getAllVariables(this.props.collection, this.props.item);
|
||||||
|
|
||||||
this.editor = CodeMirror(this.editorRef.current, {
|
this.editor = CodeMirror(this.editorRef.current, {
|
||||||
lineWrapping: false,
|
lineWrapping: false,
|
||||||
lineNumbers: false,
|
lineNumbers: false,
|
||||||
theme: this.props.theme === 'dark' ? 'monokai' : 'default',
|
theme: this.props.theme === 'dark' ? 'monokai' : 'default',
|
||||||
mode: 'brunovariables',
|
mode: 'brunovariables',
|
||||||
brunoVarInfo: {
|
brunoVarInfo: {
|
||||||
variables: getAllVariables(this.props.collection)
|
variables
|
||||||
},
|
},
|
||||||
scrollbarStyle: null,
|
scrollbarStyle: null,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
@ -85,7 +87,7 @@ class MultiLineEditor extends Component {
|
|||||||
}
|
}
|
||||||
this.editor.setValue(String(this.props.value) || '');
|
this.editor.setValue(String(this.props.value) || '');
|
||||||
this.editor.on('change', this._onEdit);
|
this.editor.on('change', this._onEdit);
|
||||||
this.addOverlay();
|
this.addOverlay(variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onEdit = () => {
|
_onEdit = () => {
|
||||||
@ -103,10 +105,10 @@ class MultiLineEditor extends Component {
|
|||||||
// event loop.
|
// event loop.
|
||||||
this.ignoreChangeEvent = true;
|
this.ignoreChangeEvent = true;
|
||||||
|
|
||||||
let variables = getAllVariables(this.props.collection);
|
let variables = getAllVariables(this.props.collection, this.props.item);
|
||||||
if (!isEqual(variables, this.variables)) {
|
if (!isEqual(variables, this.variables)) {
|
||||||
this.editor.options.brunoVarInfo.variables = variables;
|
this.editor.options.brunoVarInfo.variables = variables;
|
||||||
this.addOverlay();
|
this.addOverlay(variables);
|
||||||
}
|
}
|
||||||
if (this.props.theme !== prevProps.theme && this.editor) {
|
if (this.props.theme !== prevProps.theme && this.editor) {
|
||||||
this.editor.setOption('theme', this.props.theme === 'dark' ? 'monokai' : 'default');
|
this.editor.setOption('theme', this.props.theme === 'dark' ? 'monokai' : 'default');
|
||||||
@ -125,10 +127,8 @@ class MultiLineEditor extends Component {
|
|||||||
this.editor.getWrapperElement().remove();
|
this.editor.getWrapperElement().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
addOverlay = () => {
|
addOverlay = (variables) => {
|
||||||
let variables = getAllVariables(this.props.collection);
|
|
||||||
this.variables = variables;
|
this.variables = variables;
|
||||||
|
|
||||||
defineCodeMirrorBrunoVariablesMode(variables, 'text/plain');
|
defineCodeMirrorBrunoVariablesMode(variables, 'text/plain');
|
||||||
this.editor.setOption('mode', 'brunovariables');
|
this.editor.setOption('mode', 'brunovariables');
|
||||||
};
|
};
|
||||||
|
@ -136,6 +136,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleAccessKeyIdChange(val)}
|
onChange={(val) => handleAccessKeyIdChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -148,6 +149,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleSecretAccessKeyChange(val)}
|
onChange={(val) => handleSecretAccessKeyChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -160,6 +162,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleSessionTokenChange(val)}
|
onChange={(val) => handleSessionTokenChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -172,6 +175,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleServiceChange(val)}
|
onChange={(val) => handleServiceChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -184,6 +188,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleRegionChange(val)}
|
onChange={(val) => handleRegionChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -196,6 +201,7 @@ const AwsV4Auth = ({ onTokenChange, item, collection }) => {
|
|||||||
onChange={(val) => handleProfileNameChange(val)}
|
onChange={(val) => handleProfileNameChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
@ -55,6 +55,7 @@ const BasicAuth = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleUsernameChange(val)}
|
onChange={(val) => handleUsernameChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ const BasicAuth = ({ item, collection }) => {
|
|||||||
onChange={(val) => handlePasswordChange(val)}
|
onChange={(val) => handlePasswordChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
@ -42,6 +42,7 @@ const BearerAuth = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleTokenChange(val)}
|
onChange={(val) => handleTokenChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
@ -55,6 +55,7 @@ const DigestAuth = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleUsernameChange(val)}
|
onChange={(val) => handleUsernameChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ const DigestAuth = ({ item, collection }) => {
|
|||||||
onChange={(val) => handlePasswordChange(val)}
|
onChange={(val) => handlePasswordChange(val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
@ -92,6 +92,7 @@ const OAuth2AuthorizationCode = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleChange(key, val)}
|
onChange={(val) => handleChange(key, val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -55,6 +55,7 @@ const OAuth2ClientCredentials = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleChange(key, val)}
|
onChange={(val) => handleChange(key, val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,6 +57,7 @@ const OAuth2AuthorizationCode = ({ item, collection }) => {
|
|||||||
onChange={(val) => handleChange(key, val)}
|
onChange={(val) => handleChange(key, val)}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,6 +110,7 @@ const FormUrlEncodedParams = ({ item, collection }) => {
|
|||||||
allowNewlines={true}
|
allowNewlines={true}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -139,6 +139,7 @@ const MultipartFormParams = ({ item, collection }) => {
|
|||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
allowNewlines={true}
|
allowNewlines={true}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
@ -147,6 +147,7 @@ const QueryParams = ({ item, collection }) => {
|
|||||||
}
|
}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@ -214,6 +215,7 @@ const QueryParams = ({ item, collection }) => {
|
|||||||
}
|
}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -119,6 +119,7 @@ const RequestHeaders = ({ item, collection }) => {
|
|||||||
autocomplete={MimeTypes}
|
autocomplete={MimeTypes}
|
||||||
allowNewlines={true}
|
allowNewlines={true}
|
||||||
collection={collection}
|
collection={collection}
|
||||||
|
item={item}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -788,10 +788,16 @@ export const getTotalRequestCountInCollection = (collection) => {
|
|||||||
|
|
||||||
export const getAllVariables = (collection, item) => {
|
export const getAllVariables = (collection, item) => {
|
||||||
const environmentVariables = getEnvironmentVariables(collection);
|
const environmentVariables = getEnvironmentVariables(collection);
|
||||||
|
let requestVariables = {};
|
||||||
|
if (item?.request) {
|
||||||
|
const requestTreePath = getTreePathFromCollectionToItem(collection, item);
|
||||||
|
requestVariables = mergeFolderLevelVars(item?.request, requestTreePath);
|
||||||
|
}
|
||||||
const pathParams = getPathParams(item);
|
const pathParams = getPathParams(item);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...environmentVariables,
|
...environmentVariables,
|
||||||
|
...requestVariables,
|
||||||
...collection.collectionVariables,
|
...collection.collectionVariables,
|
||||||
pathParams: {
|
pathParams: {
|
||||||
...pathParams
|
...pathParams
|
||||||
@ -814,3 +820,36 @@ export const maskInputValue = (value) => {
|
|||||||
.map(() => '*')
|
.map(() => '*')
|
||||||
.join('');
|
.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getTreePathFromCollectionToItem = (collection, _item) => {
|
||||||
|
let path = [];
|
||||||
|
let item = findItemInCollection(collection, _item?.uid);
|
||||||
|
while (item) {
|
||||||
|
path.unshift(item);
|
||||||
|
item = findParentItemInCollection(collection, item?.uid);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergeFolderLevelVars = (request, requestTreePath = []) => {
|
||||||
|
let requestVariables = {};
|
||||||
|
for (let i of requestTreePath) {
|
||||||
|
if (i.type === 'folder') {
|
||||||
|
let vars = get(i, 'root.request.vars.req', []);
|
||||||
|
vars.forEach((_var) => {
|
||||||
|
if (_var.enabled) {
|
||||||
|
requestVariables[_var.name] = _var.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let vars = get(i, 'request.vars.req', []);
|
||||||
|
vars.forEach((_var) => {
|
||||||
|
if (_var.enabled) {
|
||||||
|
requestVariables[_var.name] = _var.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestVariables;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user