Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Graphql: highlight fields on search
leoGeorges76eba3d638e0
diff --git a/components/graphql/field.vue b/components/graphql/field.vueindex a07d72970..ef8896c2b 100644--- a/components/graphql/field.vue+++ b/components/graphql/field.vue@@ -1,6 +1,6 @@<template><div class="p-2 m-2 border-b border-dashed border-brdColor">- <div class="field-title">+ <div class="field-title" :class="{ 'field-highlighted': isHighlighted }">{{ fieldName }}<span v-if="fieldArgs.length > 0">(@@ -25,11 +25,18 @@</div></template>+<style scoped lang="scss">+.field-highlighted {+ color: #ffff00;+}+</style>+<script>export default {props: {gqlField: Object,jumpTypeCallback: Function,+ isHighlighted: { type: Boolean, default: false },},computed: {diff --git a/components/graphql/type.vue b/components/graphql/type.vueindex d5213fc9e..71fd8243e 100644--- a/components/graphql/type.vue+++ b/components/graphql/type.vue@@ -1,23 +1,44 @@<template><div class="p-2 m-2">- <div class="font-bold type-title">{{ gqlType.name }}</div>+ <div class="font-bold type-title" :class="{ 'type-highlighted': isHighlighted }">+ {{ gqlType.name }}+ </div><div class="mt-2 text-fgLightColor type-desc" v-if="gqlType.description">{{ gqlType.description }}</div><div v-if="gqlType.getFields"><h5>{{ $t("fields") }}</h5><div v-for="field in gqlType.getFields()" :key="field.name">- <field :gqlField="field" :jumpTypeCallback="jumpTypeCallback" />+ <field+ :gqlField="field"+ :isHighlighted="isFieldHighlighted({ field })"+ :jumpTypeCallback="jumpTypeCallback"+ /></div></div></div></template>+<style scoped lang="scss">+.type-highlighted {+ color: #ffff00;+}+</style>+<script>export default {props: {gqlType: {},jumpTypeCallback: Function,+ isHighlighted: { type: Boolean, default: false },+ highlightedFields: { type: Array, default: [] },+ },+ methods: {+ isFieldHighlighted({ field }) {+ return !!this.highlightedFields.find(+ (highlightedField) => highlightedField.name === field.name+ )+ },},}</script>diff --git a/pages/graphql.vue b/pages/graphql.vueindex 85605c31b..bd3c57194 100644--- a/pages/graphql.vue+++ b/pages/graphql.vue@@ -295,7 +295,12 @@<tab v-if="gqlTypes.length > 0" :id="'types'" :label="$t('types')" ref="typesTab"><div v-for="type in filteredGqlTypes" :key="type.name" :id="`type_${type.name}`">- <type :gqlType="type" :jumpTypeCallback="handleJumpToType" />+ <type+ :gqlType="type"+ :isHighlighted="isGqlTypeHighlighted({ gqlType: type })"+ :highlightedFields="getGqlTypeHighlightedFields({ gqlType: type })"+ :jumpTypeCallback="handleJumpToType"+ /></div></tab></div>@@ -451,6 +456,28 @@ export default {}},methods: {+ isGqlTypeHighlighted({ gqlType }) {+ if (!this.graphqlFieldsFilterText) return false++ return this.isTextFoundInGraphqlFieldObject({+ text: this.graphqlFieldsFilterText,+ graphqlFieldObject: gqlType,+ })+ },+ getGqlTypeHighlightedFields({ gqlType }) {+ if (!this.graphqlFieldsFilterText) return []++ const fields = Object.values(gqlType._fields || {})++ if (!fields || fields.length === 0) return []++ return fields.filter((field) => {+ return this.isTextFoundInGraphqlFieldObject({+ text: this.graphqlFieldsFilterText,+ graphqlFieldObject: field,+ })+ })+ },isTextFoundInGraphqlFieldObject({ text, graphqlFieldObject }) {const normalizedText = text.toLowerCase()