Fix limits after workspace change (#10340)

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artyom Savchenko
2025-12-30 21:20:30 +07:00
committed by GitHub
parent 56e5d6f6d8
commit b270c4f7c8
3 changed files with 15 additions and 72 deletions
+4 -42
View File
@@ -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
+1
View File
@@ -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"
}
@@ -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<void> => {
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)
}
}
}
</script>
<button