Skip to content

Commit 65347a5

Browse files
EyedPeasulischulte
andauthored
#2167: Added a new confirmation modal for jmx operations without arguments (#2168) (#2180)
Co-authored-by: Ulrich Schulte <[email protected]>
1 parent c14c3ec commit 65347a5

File tree

5 files changed

+122
-22
lines changed

5 files changed

+122
-22
lines changed

spring-boot-admin-server-ui/src/main/frontend/components/sba-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</p>
1010
<button class="delete" aria-label="close" @click="close" />
1111
</header>
12-
<section class="modal-card-body">
12+
<section class="modal-card-body" v-if="$slots.body">
1313
<slot name="body" />
1414
</section>
1515
<footer class="modal-card-foot" v-if="$slots.footer">

spring-boot-admin-server-ui/src/main/frontend/views/instances/jolokia/i18n.de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"domains": "Domains",
77
"execute": "Execute",
88
"executing": "Führe aus...",
9+
"execute_modal_header": "<code>{name}</code> ausführen?",
910
"execution_failed": "Ausführung fehlgeschlagen.",
1011
"execution_successful": "Ausführung erfolgreich.",
1112
"fetch_failed": "Das Laden der JMX-Beans ist fehlgeschlagen.",

spring-boot-admin-server-ui/src/main/frontend/views/instances/jolokia/i18n.en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"domains": "Domains",
77
"execute": "Execute",
88
"executing": "Executing...",
9+
"execute_modal_header": "Execute <code>{name}</code>?",
910
"execution_failed": "Execution failed.",
1011
"execution_successful": "Execution successful.",
1112
"fetch_failed": "Fetching JMX Beans failed.",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2014-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { render } from '@/test-utils';
18+
import userEvent from '@testing-library/user-event';
19+
import { screen, waitFor } from '@testing-library/vue';
20+
import MBeanOperation from '@/views/instances/jolokia/m-bean-operation';
21+
22+
describe('m-bean-operation.vue', () => {
23+
it('should open confirmation modal if operation contains no arguments', async () => {
24+
const wrapper = render(MBeanOperation, {
25+
props: {
26+
name: 'doIt()',
27+
descriptor: { args: [], ret: 'java.sth.doIt()' },
28+
},
29+
});
30+
31+
await userEvent.click(screen.getByText('doIt()'));
32+
33+
await waitFor(() => {
34+
screen.findByRole('dialog');
35+
});
36+
37+
await screen.findAllByTestId('mBeanOperationModal');
38+
39+
const buttonOK = screen.queryByRole('button', { name: 'OK' });
40+
await userEvent.click(buttonOK);
41+
42+
expect(wrapper.emitted().click).toBeDefined();
43+
});
44+
45+
it('should not open confirmation modal if operation contains arguments', async () => {
46+
render(MBeanOperation, {
47+
props: {
48+
name: 'doIt()',
49+
descriptor: { args: [{ property1: '' }], ret: 'java.sth.doIt()' },
50+
},
51+
});
52+
53+
await userEvent.click(screen.getByText('doIt()'));
54+
await waitFor(() => {
55+
screen.findByRole('dialog');
56+
});
57+
58+
expect(screen.queryByTestId('mBeanOperationModal')).toBeNull();
59+
});
60+
});

spring-boot-admin-server-ui/src/main/frontend/views/instances/jolokia/m-bean-operation.vue

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,76 @@
1717
<template>
1818
<div class="field">
1919
<div class="control">
20-
<button class="button is-light is-fullwidth columns has-text-left" @click="$emit('click', $event)">
21-
<small class="is-light is-muted column is-flex-grow-0 is-flex-shrink-0 p-1" v-text="shortenedRet" :title="descriptor.ret" />
22-
<span class="column is-flex-grow-1 is-flex-shrink-0 p-1 is-truncated" v-text="shortenedName" :title="name" />
20+
<button class="button is-light is-fullwidth columns has-text-left" @click="execute($event)">
21+
<small class="is-light is-muted column is-flex-grow-0 is-flex-shrink-0 p-1" v-text="shortenedRet"
22+
:title="descriptor.ret"/>
23+
<span class="column is-flex-grow-1 is-flex-shrink-0 p-1 is-truncated" v-text="shortenedName" :title="name"/>
2324
</button>
24-
<p class="help" v-text="descriptor.desc" />
25+
<p class="help" v-text="descriptor.desc"/>
2526
</div>
27+
<sba-modal v-model="isModalOpen" data-testid="mBeanOperationModal">
28+
<template v-slot:header>
29+
<span v-html="$t('instances.jolokia.execute_modal_header', {name: shortenedName})"/>
30+
</template>
31+
<template v-slot:footer>
32+
<button class="button is-light" @click="closeModal">
33+
Cancel
34+
</button>
35+
<button class="button is-success" @click="executeOperation($event)">
36+
OK
37+
</button>
38+
</template>
39+
</sba-modal>
2640
</div>
41+
2742
</template>
2843

2944
<script>
30-
import {truncateJavaType} from '@/views/instances/jolokia/utils';
45+
import {truncateJavaType} from '@/views/instances/jolokia/utils';
46+
import SbaModal from '@/components/sba-modal';
3147
32-
export default {
33-
props: {
34-
name: {
35-
type: String,
36-
required: true
37-
},
38-
descriptor: {
39-
type: Object,
40-
required: true
41-
}
48+
export default {
49+
components: {SbaModal},
50+
props: {
51+
name: {
52+
type: String,
53+
required: true
54+
},
55+
descriptor: {
56+
type: Object,
57+
required: true
58+
}
59+
},
60+
data() {
61+
return {
62+
isModalOpen: false,
63+
}
64+
},
65+
computed: {
66+
shortenedName() {
67+
return truncateJavaType(this.name);
4268
},
43-
computed: {
44-
shortenedName() {
45-
return truncateJavaType(this.name);
46-
},
47-
shortenedRet() {
48-
return truncateJavaType(this.descriptor.ret);
69+
shortenedRet() {
70+
return truncateJavaType(this.descriptor.ret);
71+
}
72+
},
73+
methods: {
74+
closeModal() {
75+
this.isModalOpen = false;
76+
},
77+
executeOperation(event) {
78+
this.$emit('click', event);
79+
this.isModalOpen = false;
80+
},
81+
execute(event) {
82+
if (this.descriptor.args.length === 0) {
83+
this.isModalOpen = true;
84+
} else {
85+
this.executeOperation(event);
4986
}
5087
}
5188
}
89+
}
5290
</script>
5391

5492
<style>

0 commit comments

Comments
 (0)