Skip to content

Commit d260b61

Browse files
authored
Fix issue on opening of the chart config panel. Fixes #27 (#47)
1 parent f939278 commit d260b61

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

vss-extension-dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifestVersion": 1,
33
"id": "GHAzDoWidget-DEV",
4-
"version": "0.2.427",
4+
"version": "0.2.432",
55
"public": false,
66
"name": "Advanced Security dashboard Widgets [DEV]",
77
"description": "[DEV] GitHub Advanced Security for Azure DevOps dashboard widgets",

vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifestVersion": 1,
33
"id": "GHAzDoWidget",
4-
"version": "0.0.1.20",
4+
"version": "0.0.1.21",
55
"public": true,
66
"name": "Advanced Security dashboard Widgets",
77
"description": "GitHub Advanced Security for Azure DevOps dashboard widgets",

widgets/widgets/chart/configuration_2x2.html

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
const $repoDropdown = $("#repo-dropdown");
1818
const $chartTypeDropdown = $("#chart-type");
1919
const $alertTypeDropdown = $("#alert-type");
20-
const repos = await getRepos(VSS, Service, GitWebApi);
2120

2221
function reloadWidget(widgetConfigurationContext) {
2322
const customSettings = getSettings();
@@ -27,28 +26,21 @@
2726
}
2827

2928
function getSettings() {
30-
if (repos) {
31-
// find the repo with this name
32-
const repo = repos.find(r => r.name === $repoDropdown.val());
33-
34-
if (repo) {
35-
var customSettings = {
36-
data: JSON.stringify({
37-
repo: $repoDropdown.val(),
38-
repoId: repo.id,
39-
chartType: $chartTypeDropdown.val(),
40-
alertType: $alertTypeDropdown.val()
41-
})
42-
};
43-
return customSettings;
44-
}
45-
}
4629

47-
return {};
30+
var customSettings = {
31+
data: JSON.stringify({
32+
repo: getSelectedRepoNameFromDropdown($repoDropdown),
33+
repoId: getSelectedRepoIdFromDropdown($repoDropdown),
34+
chartType: $chartTypeDropdown.val(),
35+
alertType: $alertTypeDropdown.val()
36+
})
37+
};
38+
return customSettings;
4839
}
4940

5041
function reloadChartOptions() {
5142
const chartType = $chartTypeDropdown.val();
43+
console.log(`Inside reloadChartOptions with chartType [${chartType}]`);
5244
if (chartType === "1") {
5345
// trend line
5446
$("#alertTypePanel").hide();
@@ -57,39 +49,36 @@
5749
// pie chart
5850
$("#alertTypePanel").show();
5951
}
52+
else if (chartType === "3") {
53+
// pie chart
54+
$("#alertTypePanel").show();
55+
}
6056
}
6157

6258
return {
6359
load: async function (widgetSettings, widgetConfigurationContext) {
6460
var settings = logWidgetSettings(widgetSettings, VSS, "Chart.2x2");
65-
66-
// add all repos as selection options to the dropdown
61+
const repos = await getRepos(VSS, Service, GitWebApi);
6762
if (repos) {
68-
// add a top option to select no repo
69-
$repoDropdown.append(`<option value="">Select a repository</option>`);
70-
// sort the repo alphabetically
71-
repos.sort((a, b) => a.name.localeCompare(b.name));
72-
repos.forEach(r => {
73-
$repoDropdown.append(`<option value=${r.name}>${r.name}</option>`);
74-
});
63+
fillSelectRepoDropdown($repoDropdown, repos);
7564
}
7665

77-
if (settings && settings.repo) {
66+
if (settings && settings.repoId) {
7867
// select the repo that was saved in the settings
79-
$repoDropdown.val(settings.repo);
80-
}
68+
$repoDropdown.val(settings.repoId);
69+
}
8170

82-
if (settings && settings.chartType) {
71+
if (settings && settings.chartType) {
8372
// select the chartType that was saved in the settings
8473
$chartTypeDropdown.val(settings.chartType);
85-
}
74+
}
8675

8776
if (settings && settings.alertType) {
8877
// select the alertType that was saved in the settings
8978
$alertTypeDropdown.val(settings.alertType);
9079
}
9180

92-
// register a change event handler for the dropdowns
81+
// register a change event handler for the dropdowns
9382
$repoDropdown.on("change", function () {
9483
reloadWidget(widgetConfigurationContext)
9584
});
@@ -99,6 +88,9 @@
9988
reloadChartOptions();
10089
});
10190

91+
// call the chartTypeDrowdown change handler to show/hide the alertType dropdown
92+
reloadChartOptions();
93+
10294
$alertTypeDropdown.on("change", function () {
10395
reloadWidget(widgetConfigurationContext)
10496
});
@@ -107,6 +99,12 @@
10799
},
108100
onSave: async function() {
109101
const customSettings = getSettings();
102+
let repoId = getSelectedRepoIdFromDropdown($repoDropdown);
103+
if (repoId == 0 || repoId == 1) { // 0 = select a repo, 1 = all repos
104+
// do not save
105+
console.log(`Not saving the settings because repoId is [${repoId}]`);
106+
return WidgetHelpers.WidgetConfigurationSave.Invalid();
107+
}
110108

111109
console.log(`Saving the Chart.2x2 settings with ${JSON.stringify(customSettings)}`)
112110
return WidgetHelpers.WidgetConfigurationSave.Valid(customSettings);

0 commit comments

Comments
 (0)