1
0
Fork 0
mirror of synced 2024-07-05 06:20:55 +12:00

Merge commit

This commit is contained in:
Dean 2022-09-01 15:30:04 +01:00
parent 7afcaadc19
commit 07a838ad72
2 changed files with 67 additions and 2 deletions

View file

@ -20,7 +20,7 @@
import { store, automationStore } from "builderStore"
import { API } from "api"
import { onMount } from "svelte"
import { apps, auth, admin, templates } from "stores/portal"
import { apps, auth, admin, templates, licensing } from "stores/portal"
import download from "downloadjs"
import { goto } from "@roxi/routify"
import AppRow from "components/start/AppRow.svelte"
@ -243,6 +243,10 @@
notifications.error("Error loading apps and templates")
}
loaded = true
//Testing
await licensing.getQuotaUsage()
await licensing.getTestData()
})
</script>

View file

@ -1,5 +1,6 @@
import { writable } from "svelte/store"
import { writable, get } from "svelte/store"
import { API } from "api"
import { auth } from "stores/portal"
export const createLicensingStore = () => {
const DEFAULT = {
@ -18,6 +19,66 @@ export const createLicensingStore = () => {
}
})
},
getTestData: async () => {
const tenantId = get(auth).tenantId
console.log("Tenant ", tenantId)
const license = get(auth).user.license
console.log("User LICENSE ", license)
// Pull out the usage.
const quota = get(store).quotaUsage
console.log("Quota usage", quota)
// Would only initialise the usage elements if the account element is present.
console.log("User account ", get(auth).user.account)
//separate into functions that pass in both the usage and quota
//easier to test
const getMonthlyMetrics = (license, quota) => {
return ["sessions", "queries", "automations"].reduce((acc, key) => {
const quotaLimit = license.quotas.usage.monthly[key].value
acc[key] =
quotaLimit > -1
? (quota.monthly.current[key] / quotaLimit) * 100
: -1
return acc
}, {})
}
const getStaticMetrics = (license, quota) => {
return ["apps", "rows"].reduce((acc, key) => {
const quotaLimit = license.quotas.usage.monthly[key].value
acc[key] =
quotaLimit > -1 ? (quota.usageQuota[key] / quotaLimit) * 100 : -1
return acc
}, {})
}
const modQuotaStr = JSON.stringify(quota)
const cloneQuota = JSON.parse(modQuotaStr)
cloneQuota.monthly.current.sessions = 4
const monthlyMetrics = getMonthlyMetrics(license, cloneQuota)
const staticMetrics = getStaticMetrics(license, cloneQuota)
console.log("Monthly Usage Metrics ", monthlyMetrics)
console.log("Static Usage Metrics ", staticMetrics)
const flagged = Object.keys(monthlyMetrics).filter(key => {
return monthlyMetrics[key] >= 100
})
console.log(flagged)
// store.update(state => {
// return {
// ...state,
// metrics,
// }
// })
},
}
return {