Skip to content

Commit 0c22ded

Browse files
authored
Merge pull request #2266 from Particular/john/month_usage
Add displaying of usage per month
2 parents 99c30b6 + 64d6446 commit 0c22ded

File tree

7 files changed

+70
-33
lines changed

7 files changed

+70
-33
lines changed

src/Frontend/src/components/configuration/PlatformLicense.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defineEmits<{
1818
}>();
1919
2020
const loading = computed(() => {
21-
return !license;
21+
return !license || license.status === "";
2222
});
2323
2424
const configuration = useConfiguration();

src/Frontend/src/composables/serviceLicense.ts

+30-27
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ interface License extends LicenseInfo {
1313
formattedInstanceName: ComputedRef<string>;
1414
}
1515

16-
const emptyLicense: License = {
17-
edition: "",
18-
expiration_date: "",
19-
upgrade_protection_expiration: "",
20-
license_type: "",
21-
instance_name: "",
22-
trial_license: true,
23-
registered_to: "",
24-
status: "",
25-
license_status: LicenseStatus.Unavailable,
26-
license_extension_url: "",
27-
licenseEdition: computed(() => {
28-
return `${license.license_type}${license.edition ? `, ${license.edition}` : ""}`;
29-
}),
30-
formattedInstanceName: computed(() => {
31-
return license.instance_name || "Upgrade ServiceControl to v3.4.0+ to see more information about this license";
32-
}),
33-
formattedExpirationDate: computed(() => {
34-
return license.expiration_date ? new Date(license.expiration_date.replace("Z", "")).toLocaleDateString() : "";
35-
}),
36-
formattedUpgradeProtectionExpiration: computed(() => {
37-
return license.upgrade_protection_expiration ? new Date(license.upgrade_protection_expiration.replace("Z", "")).toLocaleDateString() : "";
38-
}),
39-
};
40-
41-
const license = reactive<License>(emptyLicense);
16+
class emptyLicense implements License {
17+
edition = "";
18+
expiration_date = "";
19+
upgrade_protection_expiration = "";
20+
license_type = "";
21+
instance_name = "";
22+
trial_license = true;
23+
registered_to = "";
24+
status = "";
25+
license_status = LicenseStatus.Unavailable;
26+
license_extension_url = "";
27+
licenseEdition = computed(() => {
28+
return `${this.license_type}${this.edition ? `, ${this.edition}` : ""}`;
29+
});
30+
formattedInstanceName = computed(() => {
31+
return this.instance_name || "Upgrade ServiceControl to v3.4.0+ to see more information about this license";
32+
});
33+
formattedExpirationDate = computed(() => {
34+
return this.expiration_date ? new Date(this.expiration_date.replace("Z", "")).toLocaleDateString() : "";
35+
});
36+
formattedUpgradeProtectionExpiration = computed(() => {
37+
return this.upgrade_protection_expiration ? new Date(this.upgrade_protection_expiration.replace("Z", "")).toLocaleDateString() : "";
38+
});
39+
}
40+
41+
const license = reactive<License>(new emptyLicense());
4242

4343
const licenseStatus = reactive({
4444
isSubscriptionLicense: false,
@@ -64,6 +64,9 @@ function useLicense() {
6464

6565
async function getOrUpdateLicenseStatus() {
6666
const lic = await getLicense();
67+
if (lic === null) {
68+
return;
69+
}
6770
license.license_type = lic.license_type;
6871
license.expiration_date = lic.expiration_date;
6972
license.trial_license = lic.trial_license;
@@ -152,6 +155,6 @@ async function getLicense() {
152155
return data;
153156
} catch (err) {
154157
console.log(err);
155-
return emptyLicense;
158+
return null;
156159
}
157160
}

src/Frontend/src/resources/EndpointThroughputSummary.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ interface EndpointThroughputSummary {
33
is_known_endpoint: boolean;
44
user_indicator: string;
55
max_daily_throughput: number;
6+
max_monthly_throughput?: number;
67
}
78

89
export default EndpointThroughputSummary;

src/Frontend/src/resources/LicenseInfo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default interface LicenseInfo {
1515

1616
export function typeText(license: LicenseInfo, configuration: Configuration | null) {
1717
if (license.trial_license && configuration?.mass_transit_connector) {
18-
return "Early Access";
18+
return "Early Access ";
1919
}
2020
}
2121

src/Frontend/src/views/throughputreport/endpoints/DetectedListView.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ describe("DetectedListView tests", () => {
205205

206206
let throughput = 0;
207207
for (const row of within(table).getAllByRole("row").slice(1)) {
208-
expect(within(row).getByRole("cell", { name: "maximum daily throughput" }).textContent).toBe(`${throughput++}`);
208+
expect(within(row).getByRole("cell", { name: "maximum usage throughput" }).textContent).toBe(`${throughput++}`);
209209
}
210210

211211
await user.click(screen.getByRole("button", { name: /Sort by/i }));
212212
await user.click(screen.getByRole("link", { name: "throughput (Descending)" }));
213213

214214
throughput = dataLength - 1;
215215
for (const row of within(table).getAllByRole("row").slice(1)) {
216-
expect(within(row).getByRole("cell", { name: "maximum daily throughput" }).textContent).toBe(`${throughput--}`);
216+
expect(within(row).getByRole("cell", { name: "maximum usage throughput" }).textContent).toBe(`${throughput--}`);
217217
}
218218
});
219219

src/Frontend/src/views/throughputreport/endpoints/DetectedListView.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { userIndicatorMapper } from "./userIndicatorMapper";
1111
import ConfirmDialog from "@/components/ConfirmDialog.vue";
1212
import { useShowToast } from "@/composables/toast";
1313
import ResultsCount from "@/components/ResultsCount.vue";
14+
import { useHiddenFeature } from "./useHiddenFeature";
15+
import { license } from "@/composables/serviceLicense";
1416
1517
enum NameFilterType {
1618
beginsWith = "Begins with",
@@ -66,6 +68,9 @@ const filteredData = computed(() => {
6668
})
6769
.sort(sortItem?.comparer);
6870
});
71+
// We can remove this hidden toggle once we have new edition licenses.
72+
const hiddenFeatureToggle = useHiddenFeature(["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown"]);
73+
const showMonthly = computed(() => license.edition === "MonthlyUsage" || hiddenFeatureToggle.value);
6974
7075
onMounted(async () => {
7176
await loadData();
@@ -221,7 +226,8 @@ async function save() {
221226
<thead>
222227
<tr>
223228
<th scope="col">{{ props.columnTitle }}</th>
224-
<th scope="col" class="text-end formatThroughputColumn">Maximum daily throughput</th>
229+
<th v-if="showMonthly" scope="col" class="text-end formatThroughputColumn">Highest monthly throughput <i class="fa fa-info-circle text-primary" v-tippy="'In the last 12 months'" /></th>
230+
<th v-else scope="col" class="text-end formatThroughputColumn">Maximum daily throughput <i class="fa fa-info-circle text-primary" v-tippy="'In the last 12 months'" /></th>
225231
<th scope="col">Endpoint Type <i class="fa fa-info-circle text-primary" v-tippy="'Pick the most correct option'" /></th>
226232
</tr>
227233
</thead>
@@ -233,7 +239,8 @@ async function save() {
233239
<td class="col" aria-label="name">
234240
{{ row.name }}
235241
</td>
236-
<td class="col text-end formatThroughputColumn" style="width: 250px" aria-label="maximum daily throughput">{{ row.max_daily_throughput.toLocaleString() }}</td>
242+
<td v-if="showMonthly" class="col text-end formatThroughputColumn" style="width: 250px" aria-label="maximum usage throughput">{{ row.max_monthly_throughput ? row.max_monthly_throughput.toLocaleString() : "0" }}</td>
243+
<td v-else class="col text-end formatThroughputColumn" style="width: 250px" aria-label="maximum usage throughput">{{ row.max_daily_throughput.toLocaleString() }}</td>
237244
<td class="col" style="width: 350px" aria-label="endpoint type">
238245
<select class="form-select endpointType format-text" @change="(event) => updateIndicator(event, row.name)">
239246
<option v-if="props.showEndpointTypePlaceholder" value="">Pick the most appropriate option</option>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ref, watchEffect } from "vue";
2+
3+
const keys = ref<string[]>([]);
4+
const hiddenFeatureEnabled = ref(false);
5+
const keyHandler = (event: KeyboardEvent) => {
6+
keys.value.push(event.key);
7+
};
8+
9+
watchEffect((onCleanup) => {
10+
if (keys.value.length > 0) {
11+
const timeout = window.setTimeout(() => keys.value.splice(0), 5000);
12+
onCleanup(() => clearTimeout(timeout));
13+
}
14+
});
15+
16+
window.document.addEventListener("keydown", keyHandler);
17+
18+
export function useHiddenFeature(keyCombo: string[]) {
19+
watchEffect(() => {
20+
if (keys.value.toString() === keyCombo.toString()) {
21+
hiddenFeatureEnabled.value = true;
22+
}
23+
});
24+
25+
return hiddenFeatureEnabled;
26+
}

0 commit comments

Comments
 (0)