diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 593041153..bd7a18364 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -98,8 +98,8 @@ declare module '@vue/runtime-core' { HttpTestResultReport: typeof import('./components/http/TestResultReport.vue')['default'] HttpTests: typeof import('./components/http/Tests.vue')['default'] HttpURLEncodedParams: typeof import('./components/http/URLEncodedParams.vue')['default'] + IconLucideAlertTriangle: typeof import('~icons/lucide/alert-triangle')['default'] IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'] - IconLucideBrush: typeof import('~icons/lucide/brush')['default'] IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default'] IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] IconLucideGlobe: typeof import('~icons/lucide/globe')['default'] @@ -108,7 +108,6 @@ declare module '@vue/runtime-core' { IconLucideInfo: typeof import('~icons/lucide/info')['default'] IconLucideLayers: typeof import('~icons/lucide/layers')['default'] IconLucideMinus: typeof import('~icons/lucide/minus')['default'] - IconLucideRss: typeof import('~icons/lucide/rss')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default'] IconLucideUser: typeof import('~icons/lucide/user')['default'] IconLucideUsers: typeof import('~icons/lucide/users')['default'] diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index 979630df7..dd59e1115 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -234,6 +234,7 @@ import { getFoldersByPath, resolveSaveContextOnCollectionReorder, updateSaveContextForAffectedRequests, + resetTeamRequestsContext, } from "~/helpers/collection/collection" import { currentReorderingStatus$ } from "~/newstore/reordering" @@ -990,10 +991,10 @@ const removeCollection = (id: string) => { * since folder is treated as collection in the BE. * @param collectionID - ID of the collection or folder to be deleted. */ -const removeTeamCollectionOrFolder = (collectionID: string) => { +const removeTeamCollectionOrFolder = async (collectionID: string) => { modalLoadingState.value = true - pipe( + await pipe( deleteCollection(collectionID), TE.match( (err: GQLError) => { @@ -1047,7 +1048,9 @@ const onRemoveCollection = () => { emit("select", null) } - removeTeamCollectionOrFolder(collectionID) + removeTeamCollectionOrFolder(collectionID).then(() => { + resetTeamRequestsContext() + }) } } @@ -1099,7 +1102,9 @@ const onRemoveFolder = () => { emit("select", null) } - removeTeamCollectionOrFolder(collectionID) + removeTeamCollectionOrFolder(collectionID).then(() => { + resetTeamRequestsContext() + }) } } diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index f868390b5..22016ce71 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -255,15 +255,6 @@ watch( } ) -watch( - () => environmentType.value.selectedTeam, - (newTeam) => { - if (newTeam) { - adapter.changeTeamID(newTeam.id) - } - } -) - const switchToMyEnvironments = () => { environmentType.value.selectedTeam = undefined updateEnvironmentType("my-environments") @@ -282,17 +273,10 @@ const updateEnvironmentType = (newEnvironmentType: EnvironmentType) => { } watch( - () => environmentType.value.selectedTeam?.id, - (newTeamID) => { - adapter.changeTeamID(newTeamID) - } -) - -watch( - () => currentUser.value, - (newValue) => { - if (!newValue) { - switchToMyEnvironments() + () => environmentType.value.selectedTeam, + (newTeam) => { + if (newTeam) { + adapter.changeTeamID(newTeam.id) } } ) @@ -320,6 +304,15 @@ watch( } ) +watch( + () => currentUser.value, + (newValue) => { + if (!newValue) { + switchToMyEnvironments() + } + } +) + const showModalDetails = ref(false) const action = ref<"new" | "edit">("edit") const editingEnvironmentIndex = ref<"Global" | null>(null) diff --git a/packages/hoppscotch-common/src/components/environments/teams/index.vue b/packages/hoppscotch-common/src/components/environments/teams/index.vue index 3d281c408..45d46a568 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/index.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/index.vue @@ -125,14 +125,14 @@ import { useColorMode } from "~/composables/theming" import IconPlus from "~icons/lucide/plus" import IconArchive from "~icons/lucide/archive" import IconHelpCircle from "~icons/lucide/help-circle" -import { Team } from "~/helpers/backend/graphql" import { defineActionHandler } from "~/helpers/actions" +import { GetMyTeamsQuery } from "~/helpers/backend/graphql" const t = useI18n() const colorMode = useColorMode() -type SelectedTeam = Team | undefined +type SelectedTeam = GetMyTeamsQuery["myTeams"][number] | undefined const props = defineProps<{ team: SelectedTeam diff --git a/packages/hoppscotch-common/src/helpers/collection/collection.ts b/packages/hoppscotch-common/src/helpers/collection/collection.ts index 63a904813..ddbe5afc3 100644 --- a/packages/hoppscotch-common/src/helpers/collection/collection.ts +++ b/packages/hoppscotch-common/src/helpers/collection/collection.ts @@ -1,6 +1,9 @@ import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { getTabsRefTo } from "../rest/tab" import { getAffectedIndexes } from "./affectedIndex" +import { GetSingleRequestDocument } from "../backend/graphql" +import { runGQLQuery } from "../backend/GQLClient" +import * as E from "fp-ts/Either" /** * Resolve save context on reorder @@ -115,6 +118,33 @@ function resetSaveContextForAffectedRequests(folderPath: string) { } } +/** + * Reset save context to null if requests are deleted from the team collection or its folder + * only runs when collection or folder is deleted + */ + +export async function resetTeamRequestsContext() { + const tabs = getTabsRefTo((tab) => { + return tab.document.saveContext?.originLocation === "team-collection" + }) + + for (const tab of tabs) { + if (tab.value.document.saveContext?.originLocation === "team-collection") { + const data = await runGQLQuery({ + query: GetSingleRequestDocument, + variables: { + requestID: tab.value.document.saveContext?.requestID, + }, + }) + + if (E.isRight(data) && data.right.request === null) { + tab.value.document.saveContext = null + tab.value.document.isDirty = true + } + } + } +} + export function getFoldersByPath( collections: HoppCollection[], path: string diff --git a/packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts b/packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts index 7ed676625..90a0966b4 100644 --- a/packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts +++ b/packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts @@ -45,6 +45,7 @@ export default class TeamEnvironmentAdapter { this.teamEnvironmentCreated$ = null this.teamEnvironmentDeleted$ = null this.teamEnvironmentUpdated$ = null + this.teamEnvironmentCreatedSub = null this.teamEnvironmentDeletedSub = null this.teamEnvironmentUpdatedSub = null @@ -56,6 +57,7 @@ export default class TeamEnvironmentAdapter { this.teamEnvironmentCreated$?.unsubscribe() this.teamEnvironmentDeleted$?.unsubscribe() this.teamEnvironmentUpdated$?.unsubscribe() + this.teamEnvironmentCreatedSub?.unsubscribe() this.teamEnvironmentDeletedSub?.unsubscribe() this.teamEnvironmentUpdatedSub?.unsubscribe() diff --git a/packages/hoppscotch-common/src/pages/r/_id.vue b/packages/hoppscotch-common/src/pages/r/_id.vue index a810409bb..64b917981 100644 --- a/packages/hoppscotch-common/src/pages/r/_id.vue +++ b/packages/hoppscotch-common/src/pages/r/_id.vue @@ -59,8 +59,8 @@ - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a1f26c4c..8be4f84e6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9215,7 +9215,7 @@ packages: hasBin: true /after@0.8.2: - resolution: {integrity: sha512-QbJ0NTQ/I9DI3uSJA4cbexiwQeRAfjPScqIbSjUDd9TOrcg6pTkdgziesOqxBMBzit8vFCTwrP27t13vFOORRA==} + resolution: {integrity: sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=} dev: false /agent-base@6.0.2: @@ -9827,7 +9827,7 @@ packages: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} /base64-arraybuffer@0.1.4: - resolution: {integrity: sha512-a1eIFi4R9ySrbiMuyTGx5e92uRH5tQY6kArNcFaKBUleIoLjdjBg7Zxm3Mqm3Kmkf27HLR/1fnxX9q8GQ7Iavg==} + resolution: {integrity: sha1-mBjHngWbE1X5fgQooBfIOOkLqBI=} engines: {node: '>= 0.6.0'} dev: false @@ -10473,14 +10473,14 @@ packages: dev: true /component-bind@1.0.0: - resolution: {integrity: sha512-WZveuKPeKAG9qY+FkYDeADzdHyTYdIboXS59ixDeRJL5ZhxpqUnxSOwop4FQjMsiYm3/Or8cegVbpAHNA7pHxw==} + resolution: {integrity: sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=} dev: false /component-emitter@1.3.0: resolution: {integrity: sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==} /component-inherit@0.0.3: - resolution: {integrity: sha512-w+LhYREhatpVqTESyGFg3NlP6Iu0kEKUHETY9GoZP/pQyW4mHFZuFWRUCIqVPZ36ueVLtoOEZaAqbCF2RDndaA==} + resolution: {integrity: sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=} dev: false /concat-map@0.0.1: @@ -13726,7 +13726,7 @@ packages: dev: false /has-cors@1.1.0: - resolution: {integrity: sha512-g5VNKdkFuUuVCP9gYfDJHjK2nqdQJ7aDLTnycnc2+RvsOQbuLdF5pm7vuE5J76SEBIQjs4kQY/BWq74JUmjbXA==} + resolution: {integrity: sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=} dev: false /has-flag@3.0.0: @@ -14119,7 +14119,7 @@ packages: engines: {node: '>=8'} /indexof@0.0.1: - resolution: {integrity: sha512-i0G7hLJ1z0DE8dsqJa2rycj9dBmNKgXBvotXtZYXakU9oivfB9Uj2ZBC27qqef2U58/ZLwalxa1X/RDCdkHtVg==} + resolution: {integrity: sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=} dev: false /inflight@1.0.6: @@ -19813,7 +19813,7 @@ packages: dev: true /to-array@0.1.4: - resolution: {integrity: sha512-LhVdShQD/4Mk4zXNroIQZJC+Ap3zgLcDuwEdcmLv9CCO73NWockQDwyUnW/m8VX/EElfL6FcYx7EeutN4HJA6A==} + resolution: {integrity: sha1-F+bBH3PdTz10zaek/zI46a2b+JA=} dev: false /to-fast-properties@2.0.0: @@ -22404,7 +22404,7 @@ packages: dev: false /yeast@0.1.2: - resolution: {integrity: sha512-8HFIh676uyGYP6wP13R/j6OJ/1HwJ46snpvzE7aHAN3Ryqh2yX6Xox2B4CUmTwwOIzlG3Bs7ocsP5dZH/R1Qbg==} + resolution: {integrity: sha1-AI4G2AlDIMNy28L47XagymyKxBk=} dev: false /yn@3.1.1: