From 5a91fb53b2524e3081c698aac9c7f3b4e9f71392 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Mon, 21 Aug 2023 20:33:51 +0600 Subject: [PATCH] feat: expanded search capabilities of spotlight (#3255) Co-authored-by: Andrew Bastin --- packages/hoppscotch-common/locales/en.json | 63 +++- .../hoppscotch-common/src/components.d.ts | 15 +- .../src/components/app/ActionHandler.vue | 55 ++- .../src/components/app/Header.vue | 16 + .../src/components/app/Options.vue | 12 +- .../src/components/app/Social.vue | 135 +++++++ .../src/components/app/spotlight/index.vue | 23 ++ .../src/components/environments/index.vue | 5 + .../environments/my/Environment.vue | 2 + .../environments/teams/Environment.vue | 2 +- .../src/components/http/Request.vue | 7 + .../src/components/http/RequestOptions.vue | 13 +- .../src/components/workspace/Selector.vue | 11 + .../hoppscotch-common/src/helpers/actions.ts | 21 ++ .../hoppscotch-common/src/pages/index.vue | 7 + .../searchers/environment.searcher.ts | 356 ++++++++++++++++++ .../spotlight/searchers/general.searcher.ts | 114 ++++++ .../searchers/miscellaneous.searcher.ts | 69 ++++ .../spotlight/searchers/request.searcher.ts | 259 +++++++++++++ .../spotlight/searchers/response.searcher.ts | 101 +++++ .../spotlight/searchers/settings.searcher.ts | 15 +- .../spotlight/searchers/tab.searcher.ts | 91 +++++ .../spotlight/searchers/workspace.searcher.ts | 266 +++++++++++++ 23 files changed, 1633 insertions(+), 25 deletions(-) create mode 100644 packages/hoppscotch-common/src/components/app/Social.vue create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/environment.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/general.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/miscellaneous.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/request.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/response.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/tab.searcher.ts create mode 100644 packages/hoppscotch-common/src/services/spotlight/searchers/workspace.searcher.ts diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 6315e5d2b..1058eab0b 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -69,6 +69,8 @@ "invite": "Invite", "invite_description": "Hoppscotch is an open source API development ecosystem. We designed a simple and intuitive interface for creating and managing your APIs. Hoppscotch is a tool that helps you build, test, document and share your APIs.", "invite_your_friends": "Invite your friends", + "social_links": "Social links", + "social_description": "Follow us on social media to stay updated with the latest news, updates and releases.", "join_discord_community": "Join our Discord community", "keyboard_shortcuts": "Keyboard shortcuts", "name": "Hoppscotch", @@ -203,6 +205,7 @@ "create_new": "Create new environment", "created": "Environment created", "deleted": "Environment deletion", + "duplicated": "Environment duplicated", "edit": "Edit Environment", "global": "Global", "empty_variables": "No variables", @@ -220,6 +223,7 @@ "replace_with_variable": "Replace with variable", "scope": "Scope", "select": "Select environment", + "set": "Set environment", "set_as_environment": "Set as environment", "team_environments": "Team Environments", "title": "Environments", @@ -594,6 +598,9 @@ "delete_method": "Select DELETE method", "get_method": "Select GET method", "head_method": "Select HEAD method", + "rename": "Rename Current Request", + "import_curl": "Import cURL", + "show_code": "Show generated code", "method": "Method", "next_method": "Select Next method", "post_method": "Select POST method", @@ -602,6 +609,7 @@ "reset_request": "Reset Request", "save_to_collections": "Save to Collections", "send_request": "Send Request", + "save_request": "Save Request", "title": "Request" }, "response": { @@ -632,6 +640,55 @@ "url": "URL" }, "spotlight": { + "general": { + "help_menu": "Open help and support menu", + "chat": "Chat with support", + "open_docs": "Open documentation", + "open_keybindings": "Open keyboard shortcuts", + "social": "Social links and GitHub", + "title": "General" + }, + "miscellaneous": { + "invite": "Invite people to Hoppscotch", + "title": "Miscellaneous" + }, + "request": { + "tab_parameters": "Open parameters tab", + "tab_body": "Open body tab", + "tab_headers": "Open headers tab", + "tab_authorization": "Open authorization tab", + "tab_pre_request_script": "Open pre-request script tab", + "tab_tests": "Open tests tab" + }, + "response": { + "copy": "Copy response as JSON", + "download": "Download response as file", + "title": "Response" + }, + "environments": { + "new": "Create new environment", + "new_variable": "Create a new environment variable", + "edit": "Edit selected environment", + "delete": "Delete selected environment", + "duplicate": "Duplicate selected environment", + "edit_global": "Edit global environment", + "duplicate_global": "Duplicate global environment", + "title": "Environments" + }, + "workspace": { + "new": "Create new team", + "edit": "Edit selected team", + "delete": "Delete selected team", + "invite": "Invite people to team", + "switch_to_personal": "Switch to personal workspace", + "title": "Teams" + }, + "tab": { + "close_current": "Close current tab", + "close_others": "Close others tab", + "new_tab": "Open a new tab", + "title": "Tabs" + }, "section": { "user": "User", "theme": "Theme", @@ -649,9 +706,9 @@ "system": "System Mode" }, "font": { - "size_sm": "Change Font Size to Small", - "size_md": "Change Font Size to Medium", - "size_lg": "Change Font Size to Large" + "size_sm": "Change to Small", + "size_md": "Change to Medium", + "size_lg": "Change to Large" }, "change_interceptor": "Change Interceptor", "change_language": "Change Language", diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 4b3dd1425..1bfcbcd9b 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -1,11 +1,11 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// Generated by unplugin-vue-components +// generated by unplugin-vue-components +// We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 +import '@vue/runtime-core' + export {} -declare module 'vue' { +declare module '@vue/runtime-core' { export interface GlobalComponents { AppActionHandler: typeof import('./components/app/ActionHandler.vue')['default'] AppAnnouncement: typeof import('./components/app/Announcement.vue')['default'] @@ -24,10 +24,13 @@ declare module 'vue' { AppShortcutsEntry: typeof import('./components/app/ShortcutsEntry.vue')['default'] AppShortcutsPrompt: typeof import('./components/app/ShortcutsPrompt.vue')['default'] AppSidenav: typeof import('./components/app/Sidenav.vue')['default'] + AppSocial: typeof import('./components/app/Social.vue')['default'] AppSpotlight: typeof import('./components/app/spotlight/index.vue')['default'] AppSpotlightEntry: typeof import('./components/app/spotlight/Entry.vue')['default'] AppSpotlightEntryGQLHistory: typeof import('./components/app/spotlight/entry/GQLHistory.vue')['default'] + AppSpotlightEntryGQLRequest: typeof import('./components/app/spotlight/entry/GQLRequest.vue')['default'] AppSpotlightEntryRESTHistory: typeof import('./components/app/spotlight/entry/RESTHistory.vue')['default'] + AppSpotlightEntryRESTRequest: typeof import('./components/app/spotlight/entry/RESTRequest.vue')['default'] AppSupport: typeof import('./components/app/Support.vue')['default'] ButtonPrimary: typeof import('./../../hoppscotch-ui/src/components/button/Primary.vue')['default'] ButtonSecondary: typeof import('./../../hoppscotch-ui/src/components/button/Secondary.vue')['default'] @@ -81,6 +84,7 @@ declare module 'vue' { HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary'] HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary'] HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor'] + HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete'] HoppSmartCheckbox: typeof import('@hoppscotch/ui')['HoppSmartCheckbox'] HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal'] HoppSmartExpand: typeof import('@hoppscotch/ui')['HoppSmartExpand'] @@ -210,4 +214,5 @@ declare module 'vue' { WorkspaceCurrent: typeof import('./components/workspace/Current.vue')['default'] WorkspaceSelector: typeof import('./components/workspace/Selector.vue')['default'] } + } diff --git a/packages/hoppscotch-common/src/components/app/ActionHandler.vue b/packages/hoppscotch-common/src/components/app/ActionHandler.vue index 6f1cfa547..1ca90fa93 100644 --- a/packages/hoppscotch-common/src/components/app/ActionHandler.vue +++ b/packages/hoppscotch-common/src/components/app/ActionHandler.vue @@ -1,17 +1,57 @@ diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vue index bcb434827..2c6100c94 100644 --- a/packages/hoppscotch-common/src/components/app/Header.vue +++ b/packages/hoppscotch-common/src/components/app/Header.vue @@ -382,6 +382,22 @@ const settings = ref(null) const logout = ref(null) const accountActions = ref(null) +defineActionHandler("modals.team.edit", () => { + // TODO: Remove this hack + setTimeout(() => { + handleTeamEdit() + }, 100) +}) + +defineActionHandler("modals.team.invite", () => { + if ( + selectedTeam.value?.myRole === "OWNER" || + selectedTeam.value?.myRole === "EDITOR" + ) { + inviteTeam({ name: selectedTeam.value.name }, selectedTeam.value.id) + } +}) + defineActionHandler( "user.login", () => { diff --git a/packages/hoppscotch-common/src/components/app/Options.vue b/packages/hoppscotch-common/src/components/app/Options.vue index 590fdcf97..4834c03fb 100644 --- a/packages/hoppscotch-common/src/components/app/Options.vue +++ b/packages/hoppscotch-common/src/components/app/Options.vue @@ -130,13 +130,12 @@ @click="nativeShare()" /> - + + diff --git a/packages/hoppscotch-common/src/components/app/spotlight/index.vue b/packages/hoppscotch-common/src/components/app/spotlight/index.vue index 49feb1630..cbe94438a 100644 --- a/packages/hoppscotch-common/src/components/app/spotlight/index.vue +++ b/packages/hoppscotch-common/src/components/app/spotlight/index.vue @@ -98,6 +98,19 @@ import { UserSpotlightSearcherService } from "~/services/spotlight/searchers/use import { NavigationSpotlightSearcherService } from "~/services/spotlight/searchers/navigation.searcher" import { SettingsSpotlightSearcherService } from "~/services/spotlight/searchers/settings.searcher" import { CollectionsSpotlightSearcherService } from "~/services/spotlight/searchers/collections.searcher" +import { MiscellaneousSpotlightSearcherService } from "~/services/spotlight/searchers/miscellaneous.searcher" +import { TabSpotlightSearcherService } from "~/services/spotlight/searchers/tab.searcher" +import { GeneralSpotlightSearcherService } from "~/services/spotlight/searchers/general.searcher" +import { ResponseSpotlightSearcherService } from "~/services/spotlight/searchers/response.searcher" +import { RequestSpotlightSearcherService } from "~/services/spotlight/searchers/request.searcher" +import { + EnvironmentsSpotlightSearcherService, + SwitchEnvSpotlightSearcherService, +} from "~/services/spotlight/searchers/environment.searcher" +import { + SwitchWorkspaceSpotlightSearcherService, + WorkspaceSpotlightSearcherService, +} from "~/services/spotlight/searchers/workspace.searcher" const t = useI18n() @@ -116,6 +129,15 @@ useService(UserSpotlightSearcherService) useService(NavigationSpotlightSearcherService) useService(SettingsSpotlightSearcherService) useService(CollectionsSpotlightSearcherService) +useService(MiscellaneousSpotlightSearcherService) +useService(TabSpotlightSearcherService) +useService(GeneralSpotlightSearcherService) +useService(ResponseSpotlightSearcherService) +useService(RequestSpotlightSearcherService) +useService(EnvironmentsSpotlightSearcherService) +useService(SwitchEnvSpotlightSearcherService) +useService(WorkspaceSpotlightSearcherService) +useService(SwitchWorkspaceSpotlightSearcherService) const search = ref("") @@ -242,3 +264,4 @@ function newUseArrowKeysForNavigation() { return { selectedEntry } } +~/services/spotlight/searchers/workspace.searcher diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index 632681b4e..773d7393f 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -198,6 +198,11 @@ const resetSelectedData = () => { editingEnvironmentIndex.value = null } +defineActionHandler("modals.environment.new", () => { + action.value = "new" + showModalDetails.value = true +}) + defineActionHandler( "modals.my.environment.edit", ({ envName, variableName }) => { diff --git a/packages/hoppscotch-common/src/components/environments/my/Environment.vue b/packages/hoppscotch-common/src/components/environments/my/Environment.vue index 25c029c22..aa762b0cf 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Environment.vue @@ -158,5 +158,7 @@ const duplicateEnvironments = () => { cloneDeep(getGlobalVariables()) ) } else duplicateEnvironment(props.environmentIndex) + + toast.success(`${t("environment.duplicated")}`) } diff --git a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue index 9b20e960a..0f353415d 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue @@ -154,7 +154,7 @@ const duplicateEnvironments = () => { toast.error(`${getErrorMessage(err)}`) }, () => { - toast.success(`${t("team_environment.duplicate")}`) + toast.success(`${t("environment.duplicated")}`) } ) )() diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index 3832cb41e..39f99e373 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -630,6 +630,13 @@ defineActionHandler("request.method.put", () => updateMethod("PUT")) defineActionHandler("request.method.delete", () => updateMethod("DELETE")) defineActionHandler("request.method.head", () => updateMethod("HEAD")) +defineActionHandler("request.import-curl", () => { + showCurlImportModal.value = true +}) +defineActionHandler("request.show-code", () => { + showCodegenModal.value = true +}) + const isCustomMethod = computed(() => { return ( tab.value.document.request.method === "CUSTOM" || diff --git a/packages/hoppscotch-common/src/components/http/RequestOptions.vue b/packages/hoppscotch-common/src/components/http/RequestOptions.vue index 2281ab42a..0ed5237e8 100644 --- a/packages/hoppscotch-common/src/components/http/RequestOptions.vue +++ b/packages/hoppscotch-common/src/components/http/RequestOptions.vue @@ -1,6 +1,6 @@