Skip to content

Commit 8ca0a8e

Browse files
committed
activate changes: generic api fail message + new error variant of the Dialog component
CMK-31577 Change-Id: Ifd5ddeeebb1d6afec5d1c36721b707d62af7e033
1 parent ed313a1 commit 8ca0a8e

3 files changed

Lines changed: 78 additions & 9 deletions

File tree

packages/cmk-frontend-vue/demo/components/system-feedback/DemoCmkDialog.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,24 @@ defineProps<{ screenshotMode: boolean }>()
2727
:buttons="[{ title: 'Button 1', onclick: () => console.log('bar'), variant: 'info' }]"
2828
/>
2929
<CmkDialog :message="'Very simple message'" />
30+
31+
<CmkDialog
32+
:title="'Title'"
33+
:message="'Some message, dismissal will be stored in localStorage for this session and sent to backend for retrieval.'"
34+
:buttons="[{ title: 'Button 1', onclick: () => console.log('foo'), variant: 'danger' }]"
35+
:dismissal_button="{ title: 'Dismiss', key: 'immediate_slideout_change' }"
36+
:variant="'error'"
37+
/>
38+
<CmkDialog
39+
:title="'Title'"
40+
:message="'Some message with buttons.'"
41+
:buttons="[{ title: 'Button 1', onclick: () => console.log('foo'), variant: 'danger' }]"
42+
:variant="'error'"
43+
/>
44+
<CmkDialog
45+
:message="'Simple message with a button without title'"
46+
:buttons="[{ title: 'Button 1', onclick: () => console.log('bar'), variant: 'danger' }]"
47+
:variant="'error'"
48+
/>
49+
<CmkDialog :message="'Very simple message'" :variant="'error'" />
3050
</template>

packages/cmk-frontend-vue/src/components/CmkDialog.vue

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This file is part of Checkmk (https://checkmk.com). It is subject to the terms a
44
conditions defined in the file COPYING, which is part of this source code package.
55
-->
66
<script setup lang="ts">
7+
import { cva } from 'class-variance-authority'
78
import type { components } from 'cmk-shared-typing/typescript/openapi_internal'
89
import { onMounted, ref } from 'vue'
910
@@ -21,12 +22,25 @@ export interface CmkDialogProps {
2122
message: TranslatedString
2223
buttons?: { title: TranslatedString; variant: ButtonVariants['variant']; onclick: () => void }[]
2324
dismissal_button?: { title: TranslatedString; key: DismissalButtonKey }
25+
variant?: 'info' | 'error'
2426
}
2527
2628
export type DismissalButtonKey = components['schemas']['UserDismissWarning']['warning']
2729
2830
const props = defineProps<CmkDialogProps>()
2931
32+
const propsCva = cva('', {
33+
variants: {
34+
variant: {
35+
error: 'cmk-dialog__icon-box--error',
36+
info: 'cmk-dialog__icon-box--info'
37+
}
38+
},
39+
defaultVariants: {
40+
variant: 'info'
41+
}
42+
})
43+
3044
const dialogHidden = props.dismissal_button
3145
? usePersistentRef(props.dismissal_button.key, false, (v) => v as boolean, 'session')
3246
: ref(false)
@@ -51,8 +65,12 @@ onMounted(() => {
5165

5266
<template>
5367
<div v-if="!dialogHidden" class="cmk-dialog help">
54-
<div class="info_icon">
55-
<CmkIcon name="info" />
68+
<div :class="['cmk-dialog__icon-box', propsCva({ variant: props.variant })]">
69+
<CmkIcon
70+
:class="'cmk-dialog__icon'"
71+
:name="props.variant === 'error' ? 'host-svc-problems' : 'info'"
72+
:size="'small'"
73+
/>
5674
</div>
5775
<div class="cmk-dialog__content">
5876
<span v-if="props.title" class="cmk-dialog__title">{{ props.title }}<br /></span>
@@ -93,5 +111,24 @@ div.cmk-dialog {
93111
display: block;
94112
}
95113
}
114+
115+
.cmk-dialog__icon-box {
116+
display: flex;
117+
align-items: center;
118+
border-radius: var(--dimension-3) 0 0 var(--dimension-3);
119+
}
120+
121+
.cmk-dialog__icon-box--info {
122+
background-color: var(--color-dark-blue-50);
123+
}
124+
125+
.cmk-dialog__icon-box--error {
126+
background-color: var(--color-dark-red-50);
127+
}
128+
129+
.cmk-dialog__icon {
130+
filter: brightness(0) invert(1);
131+
padding: var(--dimension-4);
132+
}
96133
}
97134
</style>

packages/cmk-frontend-vue/src/main-menu/changes/ChangesApp.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const restAPI = new Api(`api/1.0/`, [['Content-Type', 'application/json']])
5252
const ajaxCall = new Api()
5353
const activateChangesInProgress = ref<boolean>(false)
5454
const alreadyMadeAjaxCall = ref<boolean>(false)
55-
const activationError = ref<string | null>(null)
55+
const activationError = ref<boolean>(false)
5656
5757
const sitesAndChanges = ref<SitesAndChanges>({
5858
sites: [],
@@ -160,10 +160,10 @@ async function activateAllChanges() {
160160
activationPollStartTime.value = Date.now()
161161
void pollActivationStatusUntilComplete(activateChangesResponse.id)
162162
return
163-
} catch (error) {
163+
} catch {
164164
await fetchPendingChangesAjax()
165165
activateChangesInProgress.value = false
166-
activationError.value = `Activation failed: ${error}`
166+
activationError.value = true
167167
}
168168
}
169169
@@ -213,7 +213,7 @@ async function checkIfMenuActive(): Promise<void> {
213213
if (mainMenu.isNavItemActive('changes')) {
214214
if (!alreadyMadeAjaxCall.value) {
215215
recentlyActivatedSites.value = []
216-
activationError.value = null
216+
activationError.value = false
217217
await fetchPendingChangesAjax()
218218
alreadyMadeAjaxCall.value = true
219219
}
@@ -349,9 +349,21 @@ onMounted(async () => {
349349
<CmkAlertBox v-if="!userCanActivateSelectedSites" variant="warning" class="cmk-alert-box">
350350
{{ _t('Sorry, you are not allowed to activate changes of other users.') }}
351351
</CmkAlertBox>
352-
<CmkAlertBox v-if="activationError" variant="error" class="cmk-alert-box">
353-
{{ activationError }}
354-
</CmkAlertBox>
352+
353+
<CmkDialog
354+
v-if="activationError"
355+
:title="_t('Activation of changes failed')"
356+
:message="_t(`Open the full activation page for more details.`)"
357+
:buttons="[
358+
{
359+
title: _t('Open full view'),
360+
variant: 'danger',
361+
onclick: () => openActivateChangesPage()
362+
}
363+
]"
364+
variant="error"
365+
/>
366+
355367
<CmkAlertBox
356368
v-if="sitesAndChanges.licenseMessage !== null"
357369
variant="warning"

0 commit comments

Comments
 (0)