Skip to content

Commit d45714b

Browse files
authored
fix(#4255): convert ApplicationStatusHero to Composition API and improve last update handling (#4281)
1 parent eccabc2 commit d45714b

3 files changed

Lines changed: 34 additions & 53 deletions

File tree

spring-boot-admin-server-ui/src/main/frontend/components/sba-toggle-scope-button.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ const modelValue = defineModel({
5656
default: ActionScope.APPLICATION,
5757
});
5858
59-
const { instanceCount, showInfo = true } = defineProps<{
59+
const {
60+
instanceCount,
61+
showInfo = true,
62+
classNames = '',
63+
} = defineProps<{
6064
instanceCount: number;
6165
showInfo?: boolean;
6266
classNames?: string | string[] | Record<string, boolean>;

spring-boot-admin-server-ui/src/main/frontend/views/applications/ApplicationStatusHero.vue

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
</sba-panel>
7474
</template>
7575

76-
<script>
77-
import { computed } from 'vue';
76+
<script setup lang="ts">
77+
import { computed, ref, watch } from 'vue';
7878
7979
import { useApplicationStore } from '@/composables/useApplicationStore';
8080
import { getStatusInfo } from '@/services/application';
@@ -87,57 +87,34 @@ const options = {
8787
minute: 'numeric',
8888
second: 'numeric',
8989
};
90+
const { applications } = useApplicationStore();
9091
91-
export default {
92-
setup() {
93-
const { applications } = useApplicationStore();
92+
const userLocale = navigator.languages
93+
? navigator.languages[0]
94+
: navigator.language;
95+
const dateTimeFormat = new Intl.DateTimeFormat(userLocale, options);
9496
95-
const statusInfo = computed(() => getStatusInfo(applications.value));
97+
const lastUpdate = ref(dateTimeFormat.format(new Date()));
9698
97-
return { applications, statusInfo };
98-
},
99-
data() {
100-
return {
101-
lastUpdate: new Date(),
102-
dateTimeFormat: new Intl.DateTimeFormat(this.$i18n.locale, options),
103-
};
104-
},
105-
computed: {
106-
someInstancesDown() {
107-
return this.statusInfo.someDown;
108-
},
109-
someInstancesUnknown() {
110-
return this.statusInfo.someUnknown;
111-
},
112-
notUpCount() {
113-
return this.applications.reduce((current, next) => {
114-
return (
115-
current +
116-
next.instances.filter(
117-
(instance) => instance.statusInfo.status !== 'UP',
118-
).length
119-
);
120-
}, 0);
121-
},
122-
applicationsCount() {
123-
return this.applications.length;
124-
},
125-
instancesCount() {
126-
return this.applications.reduce(
127-
(current, next) => current + next.instances.length,
128-
0,
129-
);
130-
},
131-
},
132-
beforeMount() {
133-
this.updateLastUpdateTime();
134-
},
135-
methods: {
136-
updateLastUpdateTime() {
137-
this.lastUpdate = this.dateTimeFormat.format(new Date());
138-
},
139-
},
140-
};
99+
const statusInfo = computed(() => {
100+
return getStatusInfo(applications.value);
101+
});
102+
103+
watch(statusInfo, () => {
104+
lastUpdate.value = dateTimeFormat.format(new Date());
105+
});
106+
107+
const applicationsCount = computed(() => {
108+
return applications.value.length;
109+
});
110+
111+
const someInstancesDown = computed(() => {
112+
return statusInfo.value.someDown;
113+
});
114+
115+
const someInstancesUnknown = computed(() => {
116+
return statusInfo.value.someUnknown;
117+
});
141118
</script>
142119

143120
<style scoped>

spring-boot-admin-server-ui/src/main/frontend/views/instances/details/details-datasource.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
v-text="$t('instances.details.datasource.max_connections')"
5151
/>
5252
<dd
53-
class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"
5453
v-if="current.max >= 0"
54+
class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"
5555
v-text="current.max"
5656
/>
5757
<dd
58-
class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"
5958
v-else
59+
class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"
6060
v-text="$t('instances.details.datasource.unlimited')"
6161
/>
6262
</dl>

0 commit comments

Comments
 (0)