Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add banner to DeviceBrowser when device limit reached #2670

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions forge/db/models/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ module.exports = {
"members"."TeamId" = "Team"."id"
)`),
'memberCount'
],
[
literal(`(
SELECT COUNT(*)
FROM "Devices" AS "devices"
WHERE
"devices"."TeamId" = "Team"."id"
)`),
'deviceCount'
]
]
}
Expand Down Expand Up @@ -134,6 +143,15 @@ module.exports = {
"members"."TeamId" = "Team"."id"
)`),
'memberCount'
],
[
literal(`(
SELECT COUNT(*)
FROM "Devices" AS "devices"
WHERE
"devices"."TeamId" = "Team"."id"
)`),
'deviceCount'
]
]
}
Expand Down Expand Up @@ -177,6 +195,15 @@ module.exports = {
"members"."TeamId" = "Team"."id"
)`),
'memberCount'
],
[
literal(`(
SELECT COUNT(*)
FROM "Devices" AS "devices"
WHERE
"devices"."TeamId" = "Team"."id"
)`),
'deviceCount'
]
]
}
Expand Down
2 changes: 2 additions & 0 deletions forge/db/views/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function (app) {
instanceCount: { type: 'number' },
instanceCountByType: { type: 'object', additionalProperties: true },
memberCount: { type: 'number' },
deviceCount: { type: 'number' },
createdAt: { type: 'string' },
updatedAt: { type: 'string' },
billing: { type: 'object', additionalProperties: true },
Expand All @@ -51,6 +52,7 @@ module.exports = function (app) {
avatar: result.avatar,
instanceCount: result.projectCount,
memberCount: result.memberCount,
deviceCount: result.deviceCount,
createdAt: result.createdAt,
updatedAt: result.updatedAt,
links: result.links
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/api/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ const getApplicationInstances = async (applicationId, cursor, limit) => {
const getApplicationDevices = async (applicationId, cursor, limit) => {
const url = paginateUrl(`/api/v1/applications/${applicationId}/devices`, cursor, limit)
const res = await client.get(url)
if (!res?.data?.count) {
return []
}

res.data.devices = res.data.devices.map((item) => {
item.createdSince = daysSince(item.createdAt)
item.updatedSince = daysSince(item.updatedAt)
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/DevicesBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
message="Deleting Device..."
/>
<template v-else>
<FeatureUnavailableToTeam v-if="devices.size > 0 && teamDeviceLimitReached" fullMessage="You have reached the device limit for this team." />
<DevicesStatusBar v-if="devices.size > 0" data-el="devicestatus-lastseen" label="Last Seen" :devices="Array.from(devices.values())" property="lastseen" :filter="filter" @filter-selected="applyFilter" />
<DevicesStatusBar v-if="devices.size > 0" data-el="devicestatus-status" label="Last Known Status" :devices="Array.from(devices.values())" property="status" :filter="filter" @filter-selected="applyFilter" />
<ff-data-table
Expand Down Expand Up @@ -47,6 +48,7 @@
class="font-normal"
data-action="register-device"
kind="primary"
:disabled="teamDeviceLimitReached"
@click="showCreateDeviceDialog"
>
<template #icon-left>
Expand Down Expand Up @@ -249,6 +251,7 @@ import Alerts from '../services/alerts.js'
import Dialog from '../services/dialog.js'

import EmptyState from './EmptyState.vue'
import FeatureUnavailableToTeam from './banners/FeatureUnavailableToTeam.vue'
import DevicesStatusBar from './charts/DeviceStatusBar.vue'

const POLL_TIME = 10000
Expand All @@ -260,6 +263,7 @@ export default {
DeviceAssignApplicationDialog,
DeviceAssignInstanceDialog,
DeviceCredentialsDialog,
FeatureUnavailableToTeam,
PlusSmIcon,
SnapshotAssignDialog,
TeamDeviceCreateDialog,
Expand Down Expand Up @@ -369,6 +373,14 @@ export default {
(this.displayingApplication && !!this.application?.id) ||
(this.displayingTeam && !!this.team?.id)
)
},
teamDeviceLimitReached () {
const teamTypeDeviceLimit = this.team.type.properties?.devices?.limit
if (!teamTypeDeviceLimit || teamTypeDeviceLimit < 0) {
return false
}

return this.team.deviceCount >= teamTypeDeviceLimit
}
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
class="ff-page-banner my-4"
class="ff-page-banner mb-4"
data-el="page-banner-feature-unavailable-to-team"
>
<SparklesIcon class="ff-icon mr-2" style="stroke-width: 1px;" />
Expand Down
Loading