Merge pull request #620 from AndrewBastin/feat/quick-query-run
Added shortcut to quickly run the GraphQL query
This commit is contained in:
@@ -5,17 +5,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.show-if-initialized {
|
.show-if-initialized {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|
||||||
&.initialized {
|
&.initialized {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
|
||||||
|
|
||||||
& > * {
|
|
||||||
transition: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -42,6 +42,10 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: "json",
|
default: "json",
|
||||||
},
|
},
|
||||||
|
onRunGQLQuery: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {},
|
||||||
|
},
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: {},
|
default: {},
|
||||||
@@ -65,12 +69,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
theme() {
|
theme() {
|
||||||
this.initialized = false;
|
this.initialized = false
|
||||||
this.editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
this.editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
||||||
this.$nextTick().then(() => {
|
this.$nextTick().then(() => {
|
||||||
this.initialized = true;
|
this.initialized = true
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
lang(value) {
|
lang(value) {
|
||||||
this.editor.getSession().setMode(`ace/mode/${value}`)
|
this.editor.getSession().setMode(`ace/mode/${value}`)
|
||||||
@@ -93,16 +97,16 @@ export default {
|
|||||||
// Set the theme and show the editor only after it's been set to prevent FOUC.
|
// Set the theme and show the editor only after it's been set to prevent FOUC.
|
||||||
editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
||||||
this.$nextTick().then(() => {
|
this.$nextTick().then(() => {
|
||||||
this.initialized = true;
|
this.initialized = true
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
// Set the theme and show the editor only after it's been set to prevent FOUC.
|
// Set the theme and show the editor only after it's been set to prevent FOUC.
|
||||||
editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
editor.setTheme(`ace/theme/${this.defineTheme()}`, () => {
|
||||||
this.$nextTick().then(() => {
|
this.$nextTick().then(() => {
|
||||||
this.initialized = true;
|
this.initialized = true
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
const completer = {
|
const completer = {
|
||||||
getCompletions: (editor, _session, { row, column }, _prefix, callback) => {
|
getCompletions: (editor, _session, { row, column }, _prefix, callback) => {
|
||||||
@@ -134,6 +138,15 @@ export default {
|
|||||||
this.editor = editor
|
this.editor = editor
|
||||||
this.cacheValue = this.value
|
this.cacheValue = this.value
|
||||||
|
|
||||||
|
editor.commands.addCommand({
|
||||||
|
name: "runGQLQuery",
|
||||||
|
exec: () => this.onRunGQLQuery(this.editor.getValue()),
|
||||||
|
bindKey: {
|
||||||
|
mac: "cmd-enter",
|
||||||
|
win: "ctrl-enter",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
editor.on("change", () => {
|
editor.on("change", () => {
|
||||||
const content = editor.getValue()
|
const content = editor.getValue()
|
||||||
this.$emit("input", content)
|
this.$emit("input", content)
|
||||||
@@ -190,7 +203,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.editor.destroy();
|
this.editor.destroy()
|
||||||
}
|
},
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
3
functions/platformutils.js
Normal file
3
functions/platformutils.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function getPlatformSpecialKey() {
|
||||||
|
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) ? "⌘" : "Ctrl"
|
||||||
|
}
|
||||||
@@ -642,6 +642,7 @@ import intializePwa from "../assets/js/pwa"
|
|||||||
import * as version from "../.postwoman/version.json"
|
import * as version from "../.postwoman/version.json"
|
||||||
import { hasExtensionInstalled } from "../functions/strategies/ExtensionStrategy"
|
import { hasExtensionInstalled } from "../functions/strategies/ExtensionStrategy"
|
||||||
import { hasChromeExtensionInstalled } from "../functions/strategies/ChromeStrategy"
|
import { hasChromeExtensionInstalled } from "../functions/strategies/ChromeStrategy"
|
||||||
|
import { getPlatformSpecialKey } from "~/functions/platformutils"
|
||||||
import firebase from "firebase/app"
|
import firebase from "firebase/app"
|
||||||
import { fb } from "../functions/fb"
|
import { fb } from "../functions/fb"
|
||||||
|
|
||||||
@@ -653,9 +654,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getSpecialKey() {
|
getSpecialKey: getPlatformSpecialKey,
|
||||||
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) ? "⌘" : "Ctrl"
|
|
||||||
},
|
|
||||||
linkActive(path) {
|
linkActive(path) {
|
||||||
return {
|
return {
|
||||||
"nuxt-link-exact-active": this.$route.path === path,
|
"nuxt-link-exact-active": this.$route.path === path,
|
||||||
|
|||||||
@@ -153,7 +153,10 @@
|
|||||||
<div class="flex-wrap gqlRunQuery">
|
<div class="flex-wrap gqlRunQuery">
|
||||||
<label for="gqlQuery">{{ $t("query") }}</label>
|
<label for="gqlQuery">{{ $t("query") }}</label>
|
||||||
<div>
|
<div>
|
||||||
<button @click="runQuery()" v-tooltip.bottom="$t('run_query')">
|
<button
|
||||||
|
@click="runQuery()"
|
||||||
|
v-tooltip.bottom="`${$t('run_query')} (${getSpecialKey()}-Enter)`"
|
||||||
|
>
|
||||||
<i class="material-icons">play_arrow</i>
|
<i class="material-icons">play_arrow</i>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@@ -169,6 +172,7 @@
|
|||||||
<QueryEditor
|
<QueryEditor
|
||||||
ref="queryEditor"
|
ref="queryEditor"
|
||||||
v-model="gqlQueryString"
|
v-model="gqlQueryString"
|
||||||
|
:onRunGQLQuery="runQuery"
|
||||||
:options="{
|
:options="{
|
||||||
maxLines: responseBodyMaxLines,
|
maxLines: responseBodyMaxLines,
|
||||||
minLines: '16',
|
minLines: '16',
|
||||||
@@ -327,6 +331,7 @@ import textareaAutoHeight from "../directives/textareaAutoHeight"
|
|||||||
import { commonHeaders } from "../functions/headers"
|
import { commonHeaders } from "../functions/headers"
|
||||||
import AceEditor from "../components/ace-editor"
|
import AceEditor from "../components/ace-editor"
|
||||||
import QueryEditor from "../components/graphql/queryeditor"
|
import QueryEditor from "../components/graphql/queryeditor"
|
||||||
|
import { getPlatformSpecialKey } from "~/functions/platformutils"
|
||||||
import { sendNetworkRequest } from "../functions/network"
|
import { sendNetworkRequest } from "../functions/network"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -424,6 +429,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getSpecialKey: getPlatformSpecialKey,
|
||||||
handleJumpToType(type) {
|
handleJumpToType(type) {
|
||||||
const typesTab = document.getElementById("gqltypes-tab")
|
const typesTab = document.getElementById("gqltypes-tab")
|
||||||
typesTab.checked = true
|
typesTab.checked = true
|
||||||
|
|||||||
Reference in New Issue
Block a user