From b270c4f7c88cc1a7bf89f111aefc9aa312aba01e Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Tue, 30 Dec 2025 21:20:30 +0700 Subject: [PATCH] Fix limits after workspace change (#10340) Signed-off-by: Artem Savchenko --- common/config/rush/pnpm-lock.yaml | 46 ++----------------- plugins/billing-resources/package.json | 1 + .../src/components/LimitsIndicator.svelte | 40 ++++------------ 3 files changed, 15 insertions(+), 72 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 87809b86d1..3d03bfc465 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -16348,6 +16348,9 @@ importers: '@hcengineering/view-resources': specifier: workspace:^0.7.0 version: link:../view-resources + '@hcengineering/workbench': + specifier: workspace:^0.7.0 + version: link:../workbench filesize: specifier: ^8.0.3 version: 8.0.7 @@ -61235,7 +61238,7 @@ snapshots: node-loader@2.0.0(webpack@5.102.1): dependencies: loader-utils: 2.0.4 - webpack: 5.102.1 + webpack: 5.102.1(@swc/core@1.15.1)(esbuild@0.25.12)(webpack-cli@5.1.4) node-localstorage@2.2.1: dependencies: @@ -63266,15 +63269,6 @@ snapshots: optionalDependencies: '@swc/core': 1.15.1 - terser-webpack-plugin@5.3.14(webpack@5.102.1): - dependencies: - '@jridgewell/trace-mapping': 0.3.31 - jest-worker: 27.5.1 - schema-utils: 4.3.3 - serialize-javascript: 6.0.2 - terser: 5.44.1 - webpack: 5.102.1 - terser@5.44.1: dependencies: '@jridgewell/source-map': 0.3.11 @@ -63935,38 +63929,6 @@ snapshots: webpack-sources@3.3.3: {} - webpack@5.102.1: - dependencies: - '@types/eslint-scope': 3.7.7 - '@types/estree': 1.0.8 - '@types/json-schema': 7.0.15 - '@webassemblyjs/ast': 1.14.1 - '@webassemblyjs/wasm-edit': 1.14.1 - '@webassemblyjs/wasm-parser': 1.14.1 - acorn: 8.15.0 - acorn-import-phases: 1.0.4(acorn@8.15.0) - browserslist: 4.27.0 - chrome-trace-event: 1.0.4 - enhanced-resolve: 5.18.3 - es-module-lexer: 1.7.0 - eslint-scope: 5.1.1 - events: 3.3.0 - glob-to-regexp: 0.4.1 - graceful-fs: 4.2.11 - json-parse-even-better-errors: 2.3.1 - loader-runner: 4.3.1 - mime-types: 2.1.35 - neo-async: 2.6.2 - schema-utils: 4.3.3 - tapable: 2.3.0 - terser-webpack-plugin: 5.3.14(webpack@5.102.1) - watchpack: 2.4.4 - webpack-sources: 3.3.3 - transitivePeerDependencies: - - '@swc/core' - - esbuild - - uglify-js - webpack@5.102.1(@swc/core@1.15.1): dependencies: '@types/eslint-scope': 3.7.7 diff --git a/plugins/billing-resources/package.json b/plugins/billing-resources/package.json index 0dcea565ae..587ef8c471 100644 --- a/plugins/billing-resources/package.json +++ b/plugins/billing-resources/package.json @@ -53,6 +53,7 @@ "@hcengineering/login": "workspace:^0.7.0", "@hcengineering/account-client": "workspace:^0.7.21", "@hcengineering/payment-client": "workspace:^0.7.0", + "@hcengineering/workbench": "workspace:^0.7.0", "filesize": "^8.0.3", "svelte": "^4.2.20" } diff --git a/plugins/billing-resources/src/components/LimitsIndicator.svelte b/plugins/billing-resources/src/components/LimitsIndicator.svelte index 991e960b52..81a2e942ee 100644 --- a/plugins/billing-resources/src/components/LimitsIndicator.svelte +++ b/plugins/billing-resources/src/components/LimitsIndicator.svelte @@ -17,21 +17,24 @@ import { checkWorkspaceLimits, upgradePlan, calculateLimits } from '../utils' import { subscriptionStore, resetSubscriptionStore } from '../stores/subscription' import { location, PaletteColorIndexes, Progress, tooltip } from '@hcengineering/ui' + import { addEventListener, removeEventListener } from '@hcengineering/platform' + import workbench from '@hcengineering/workbench' import UsagePopup from './UsagePopup.svelte' let pollInterval: number | undefined - let currentWorkspace: string | undefined - const POLL_INTERVAL_MS = 10 * 60 * 1000 // 10 minutes in milliseconds + const POLL_INTERVAL_MS = 60 * 60 * 1000 // 1 hour in milliseconds $: state = $subscriptionStore $: usageInfo = state.usageInfo $: currentTier = state.currentTier $: workspace = $location.path[1] - // Watch for workspace changes - $: if (workspace !== currentWorkspace) { - handleWorkspaceChange(workspace) + const connectionListener = async (): Promise => { + resetSubscriptionStore() + if (workspace !== undefined) { + void checkWorkspaceLimits() + } } // Calculate usage percentages from store data @@ -46,14 +49,12 @@ $: bandwidthColor = bandwidthPercent >= 0.9 ? PaletteColorIndexes.Firework : undefined onMount(() => { - // Initialize with current workspace - currentWorkspace = workspace + addEventListener(workbench.event.NotifyConnection, connectionListener) // Initial check if workspace exists if (workspace != null) { void checkWorkspaceLimits() - // Set up polling every 10 minutes pollInterval = setInterval(() => { void checkWorkspaceLimits() }, POLL_INTERVAL_MS) @@ -64,33 +65,12 @@ if (pollInterval !== undefined) { clearInterval(pollInterval) } + removeEventListener(workbench.event.NotifyConnection, connectionListener) }) function handleClick (): void { void upgradePlan() } - - function handleWorkspaceChange (newWorkspace: string | undefined): void { - const prevWorkspace = currentWorkspace - currentWorkspace = newWorkspace - - // Only clean up and refetch if workspace actually changed - if (prevWorkspace !== newWorkspace) { - // Clear existing data - resetSubscriptionStore() - if (pollInterval !== undefined) { - clearInterval(pollInterval) - pollInterval = undefined - } - - if (newWorkspace != null) { - void checkWorkspaceLimits() - pollInterval = setInterval(() => { - void checkWorkspaceLimits() - }, POLL_INTERVAL_MS) - } - } - }