fix: fix env info popup issues in graphql query editor

This commit is contained in:
Anoop M D 2023-01-21 19:41:37 +05:30
parent 095d7c6bcb
commit dd4fecfd1c
2 changed files with 13 additions and 7 deletions

View File

@ -40,7 +40,10 @@ export default class QueryEditor extends React.Component {
value: this.props.value || '',
lineNumbers: true,
tabSize: 2,
mode: 'graphql',
mode: 'brunovariables',
brunoVarInfo: {
variables: getEnvironmentVariables(this.props.collection),
},
theme: this.props.editorTheme || 'graphiql',
theme: this.props.theme === 'dark' ? 'monokai' : 'default',
keyMap: 'sublime',
@ -159,6 +162,8 @@ export default class QueryEditor extends React.Component {
this.ignoreChangeEvent = false;
let variables = getEnvironmentVariables(this.props.collection);
if (!isEqual(variables, this.variables)) {
this.editor.options.brunoVarInfo.variables = variables;
console.log(variables);
this.addOverlay();
}
}
@ -177,7 +182,7 @@ export default class QueryEditor extends React.Component {
this.variables = variables;
console.log(variables);
defineCodeMirrorBrunoVariablesMode(variables, "text/plain");
defineCodeMirrorBrunoVariablesMode(variables, 'graphql');
this.editor.setOption('mode', 'brunovariables');
}

View File

@ -14,12 +14,13 @@ if (!SERVER_RENDERED) {
const renderVarInfo = (token, options, cm, pos) => {
const str = token.string || '';
if(!str || !str.length || typeof str !== 'string') {
return;
}
// str is of format {{variableName}}, extract variableName
const variableName = str.substring(2, str.length - 2);
// get the value of the variable
const variableValue = options.variables[variableName] || '';
// we are seeing that from the gql query editor, the token string is of format variableName
const variableName = str.replace('{{', '').replace('}}', '').trim();
const variableValue = options.variables[variableName];
const into = document.createElement('div');
const descriptionDiv = document.createElement('div');