Skip to content

Commit 6faa960

Browse files
committed
UI fixes:
* fix policyId search slot submitting form * fix that sending a payload `0` as message payload did not work * add form to authentication popup, submitting via enter * open authentication popup when backend responds with error needing authentication
1 parent a4532a2 commit 6faa960

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

ui/modules/api.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,17 @@ export function setAuthHeader(forDevOps) {
307307
}
308308
}
309309

310+
function shouldShowAuthDialog(dittoErr) {
311+
return (dittoErr.status === 400 && dittoErr.error === "jwt:invalid") ||
312+
dittoErr.status === 401;
313+
}
314+
310315
function showDittoError(dittoErr, response) {
311316
if (dittoErr.status && dittoErr.message) {
312317
Utils.showError(dittoErr.description + `\n(${dittoErr.error})`, dittoErr.message, dittoErr.status);
318+
if (shouldShowAuthDialog(dittoErr)) {
319+
document.getElementById('authorize').click();
320+
}
313321
} else {
314322
Utils.showError(JSON.stringify(dittoErr), 'Error', response.status);
315323
}
@@ -343,7 +351,7 @@ export async function callDittoREST(method,
343351
[authHeaderKey]: authHeaderValue,
344352
...additionalHeaders,
345353
},
346-
...(body) && {body: JSON.stringify(body)},
354+
...(method !== 'GET' && method !== 'DELETE' && body !== undefined) && {body: JSON.stringify(body)},
347355
});
348356
} catch (err) {
349357
Utils.showError(err);

ui/modules/environments/authorization.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Authorize
1818
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
1919
</div>
20-
<div class="modal-body">
20+
<form class="modal-body">
2121
<div class="row">
2222
<h5>Main authentication</h5>
2323
<hr />
@@ -104,7 +104,7 @@ <h5>DevOps authentication</h5>
104104
<button class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal"
105105
id="authorizeSubmit">Authorize</button>
106106
</div>
107-
</div>
107+
</form>
108108
</div>
109109
</div>
110110
</div>

ui/modules/environments/authorization.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import * as API from '../api.js';
1515
import * as Utils from '../utils.js';
16+
import authorizationHTML from './authorization.html';
1617
/* eslint-disable prefer-const */
1718
/* eslint-disable require-jsdoc */
1819
import * as Environments from './environments.js';
19-
import authorizationHTML from './authorization.html';
2020

2121
let dom = {
2222
bearer: null,
@@ -41,7 +41,7 @@ export function setForDevops(forDevops) {
4141
export function ready() {
4242
Utils.getAllElementsById(dom);
4343

44-
document.getElementById('authorize').onclick = () => {
44+
document.getElementById('authorize').onclick = (e) => {
4545
let mainAuth = Environments.current().mainAuth;
4646
let devopsAuth = Environments.current().devopsAuth;
4747

@@ -71,7 +71,8 @@ export function ready() {
7171
});
7272
};
7373

74-
document.getElementById('authorizeSubmit').onclick = () => {
74+
document.getElementById('authorizeSubmit').onclick = (e) => {
75+
e.preventDefault();
7576
const mainAuthSelector = document.querySelector('input[name="main-auth"]:checked') as HTMLInputElement;
7677
const mainAuth = mainAuthSelector ? mainAuthSelector.value : undefined;
7778
const devopsAuthSelector = document.querySelector('input[name="devops-auth"]:checked') as HTMLInputElement;

ui/modules/policies/policies.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
* SPDX-License-Identifier: EPL-2.0
1212
*/
1313

14+
import * as API from '../api.js';
15+
import * as Environments from '../environments/environments.js';
16+
import * as Things from '../things/things.js';
1417
/* eslint-disable comma-dangle */
1518
/* eslint-disable prefer-const */
1619
/* eslint-disable no-invalid-this */
1720
/* eslint-disable require-jsdoc */
1821
import * as Utils from '../utils.js';
19-
import * as API from '../api.js';
20-
import * as Things from '../things/things.js';
21-
import * as Environments from '../environments/environments.js';
22-
import {TabHandler} from '../utils/tabHandler.js';
23-
import policyHTML from './policies.html';
24-
import { Observable } from '../utils/observable.js';
2522
import { CrudOperation, CrudToolbar } from '../utils/crudToolbar.js';
23+
import { Observable } from '../utils/observable.js';
24+
import { TabHandler } from '../utils/tabHandler.js';
25+
import policyHTML from './policies.html';
2626

2727
export interface Policy {
2828
policyId: string,
@@ -64,7 +64,8 @@ export function ready() {
6464

6565
dom.tbodyRecentPolicies.addEventListener('click', onRecentPoliciesTableClicked);
6666

67-
dom.buttonLoadPolicy.onclick = () => {
67+
dom.buttonLoadPolicy.onclick = (e) => {
68+
e.preventDefault();
6869
Utils.assert(dom.inputPolicyId.value, 'Please enter a policyId', dom.inputPolicyId);
6970
refreshPolicy(dom.inputPolicyId.value);
7071
};

0 commit comments

Comments
 (0)