fix: spotlight actions on graphql (#3299)

* fix: spotlight actions for graphql

* fix: environment actions

* fix: gql rename request

* fix: graphql spotlight actions

* fix: tab shortcuts not working properly

* fix: only show download and copy response when there is a response

---------

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2023-08-28 21:10:01 +06:00
committed by GitHub
parent 0eacd6763b
commit b953b32ff4
12 changed files with 240 additions and 108 deletions

View File

@@ -45,8 +45,11 @@ import {
setSelectedEnvironmentIndex,
} from "~/newstore/environments"
import IconCheckCircle from "~/components/app/spotlight/entry/IconSelected.vue"
import IconCircle from "~icons/lucide/circle"
type Doc = {
text: string
text: string | string[]
alternates: string[]
icon: object | Component
excludeFromSearch?: boolean
@@ -88,40 +91,61 @@ export class EnvironmentsSpotlightSearcherService extends StaticSpotlightSearche
private documents: Record<string, Doc> = reactive({
new_environment: {
text: this.t("spotlight.environments.new"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.new"),
],
alternates: ["new", "environment"],
icon: markRaw(IconLayers),
},
new_environment_variable: {
text: this.t("spotlight.environments.new_variable"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.new_variable"),
],
alternates: ["new", "environment", "variable"],
icon: markRaw(IconLayers),
},
edit_selected_env: {
text: this.t("spotlight.environments.edit"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.edit"),
],
alternates: ["edit", "environment"],
icon: markRaw(IconEdit),
excludeFromSearch: computed(() => !this.hasSelectedEnv.value),
},
delete_selected_env: {
text: this.t("spotlight.environments.delete"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.delete"),
],
alternates: ["delete", "environment"],
icon: markRaw(IconTrash2),
excludeFromSearch: computed(() => !this.hasSelectedEnv.value),
},
duplicate_selected_env: {
text: this.t("spotlight.environments.duplicate"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.duplicate"),
],
alternates: ["duplicate", "environment"],
icon: markRaw(IconCopy),
excludeFromSearch: computed(() => !this.hasSelectedEnv.value),
},
edit_global_env: {
text: this.t("spotlight.environments.edit_global"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.edit_global"),
],
alternates: ["edit", "global", "environment"],
icon: markRaw(IconEdit),
},
duplicate_global_env: {
text: this.t("spotlight.environments.duplicate_global"),
text: [
this.t("spotlight.environments.title"),
this.t("spotlight.environments.duplicate_global"),
],
alternates: ["duplicate", "global", "environment"],
icon: markRaw(IconCopy),
},
@@ -245,6 +269,16 @@ export class SwitchEnvSpotlightSearcherService
this.spotlight.registerSearcher(this)
}
private selectedEnvIndex = useStreamStatic(
selectedEnvironmentIndex$,
{
type: "NO_ENV_SELECTED",
},
() => {
/* noop */
}
)[0]
private environmentSearchable = useStreamStatic(
activeActions$.pipe(
map((actions) => actions.includes("modals.environment.add"))
@@ -262,16 +296,25 @@ export class SwitchEnvSpotlightSearcherService
const results = ref<SpotlightSearcherResult[]>([])
const minisearch = new MiniSearch({
fields: ["name"],
fields: ["name", "alternates"],
storeFields: ["name"],
})
if (this.environmentSearchable.value) {
minisearch.addAll(
environmentsStore.value.environments.map((entry, index) => {
let id = `environment-${index}`
if (
this.selectedEnvIndex.value?.type === "MY_ENV" &&
this.selectedEnvIndex.value.index === index
) {
id += "-selected"
}
return {
id: `environment-${index}`,
id,
name: entry.name,
alternates: ["environment", "change", entry.name],
}
})
)
@@ -298,7 +341,9 @@ export class SwitchEnvSpotlightSearcherService
.map((x) => {
return {
id: x.id,
icon: markRaw(IconLayers),
icon: markRaw(
x.id.endsWith("-selected") ? IconCheckCircle : IconCircle
),
score: x.score,
text: {
type: "text",