fix(editor): Fix delete variable dialog actions (no-changelog) (#6935)

* fix: fix delete variable dialog actions

* fix: small code changes

* fix: fix linting issue
This commit is contained in:
Alex Grozav 2023-08-16 10:29:11 +03:00 committed by GitHub
parent 9687410374
commit 775e73e0c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View file

@ -1,6 +1,8 @@
import type { ElMessageBoxOptions } from 'element-plus';
import { ElMessageBox as MessageBox } from 'element-plus';
export type MessageBoxConfirmResult = 'confirm' | 'cancel';
export function useMessage() {
const handleCancelOrClose = (e: unknown) => {
if (e instanceof Error) throw e;
@ -28,7 +30,7 @@ export function useMessage() {
message: string,
configOrTitle?: string | ElMessageBoxOptions,
config?: ElMessageBoxOptions,
) {
): Promise<MessageBoxConfirmResult> {
const resolvedConfig = {
...(config || (typeof configOrTitle === 'object' ? configOrTitle : {})),
cancelButtonClass: 'btn--cancel',
@ -39,9 +41,13 @@ export function useMessage() {
};
if (typeof configOrTitle === 'string') {
return MessageBox.confirm(message, configOrTitle, resolvedConfig).catch(handleCancelOrClose);
return MessageBox.confirm(message, configOrTitle, resolvedConfig).catch(
handleCancelOrClose,
) as unknown as Promise<MessageBoxConfirmResult>;
}
return MessageBox.confirm(message, resolvedConfig).catch(handleCancelOrClose);
return MessageBox.confirm(message, resolvedConfig).catch(
handleCancelOrClose,
) as unknown as Promise<MessageBoxConfirmResult>;
}
async function prompt(

View file

@ -12,7 +12,7 @@ import { useI18n, useTelemetry, useToast, useMessage } from '@/composables';
import ResourcesListLayout from '@/components/layouts/ResourcesListLayout.vue';
import VariablesRow from '@/components/VariablesRow.vue';
import { EnterpriseEditionFeature } from '@/constants';
import { EnterpriseEditionFeature, MODAL_CONFIRM } from '@/constants';
import type {
DatatableColumn,
EnvironmentVariable,
@ -183,7 +183,7 @@ function cancelEditing(data: EnvironmentVariable | TemporaryEnvironmentVariable)
async function deleteVariable(data: EnvironmentVariable) {
try {
await message.confirm(
const confirmed = await message.confirm(
i18n.baseText('variables.modals.deleteConfirm.message', { interpolate: { name: data.key } }),
i18n.baseText('variables.modals.deleteConfirm.title'),
{
@ -191,11 +191,11 @@ async function deleteVariable(data: EnvironmentVariable) {
cancelButtonText: i18n.baseText('variables.modals.deleteConfirm.cancelButton'),
},
);
} catch (e) {
return;
}
try {
if (confirmed !== MODAL_CONFIRM) {
return;
}
await environmentsStore.deleteVariable(data);
allVariables.value = allVariables.value.filter((variable) => variable.id !== data.id);
} catch (error) {