|
| 1 | +<script> |
| 2 | +import AsyncButton from '@shell/components/AsyncButton'; |
| 3 | +import { CATALOG } from '@shell/config/types'; |
| 4 | +import { UI_PLUGIN_NAMESPACE } from '@shell/config/uiplugins'; |
| 5 | +
|
| 6 | +/** |
| 7 | + * Dialog shown when user tries to install an extension that is already installed from a different source. |
| 8 | + * Prompts the user to uninstall the existing version first before installing from the new source. |
| 9 | + */ |
| 10 | +export default { |
| 11 | + emits: ['close'], |
| 12 | +
|
| 13 | + components: { AsyncButton }, |
| 14 | +
|
| 15 | + props: { |
| 16 | + /** |
| 17 | + * The installed plugin that needs to be uninstalled |
| 18 | + */ |
| 19 | + installedPlugin: { |
| 20 | + type: Object, |
| 21 | + default: () => {}, |
| 22 | + required: true |
| 23 | + }, |
| 24 | + /** |
| 25 | + * Callback to update install status on extensions main screen |
| 26 | + */ |
| 27 | + updateStatus: { |
| 28 | + type: Function, |
| 29 | + default: () => {}, |
| 30 | + required: true |
| 31 | + }, |
| 32 | + /** |
| 33 | + * Callback when modal is closed |
| 34 | + */ |
| 35 | + closed: { |
| 36 | + type: Function, |
| 37 | + default: () => {}, |
| 38 | + required: true |
| 39 | + } |
| 40 | + }, |
| 41 | +
|
| 42 | + data() { |
| 43 | + return { busy: false }; |
| 44 | + }, |
| 45 | +
|
| 46 | + methods: { |
| 47 | + closeDialog(result) { |
| 48 | + this.closed(result); |
| 49 | + this.$emit('close'); |
| 50 | + }, |
| 51 | + async uninstall() { |
| 52 | + this.busy = true; |
| 53 | +
|
| 54 | + const plugin = this.installedPlugin; |
| 55 | +
|
| 56 | + this.updateStatus(plugin.id, 'uninstall'); |
| 57 | +
|
| 58 | + // Delete the CR if this is a developer plugin (there is no Helm App, so need to remove the CRD ourselves) |
| 59 | + if (plugin.uiplugin?.isDeveloper) { |
| 60 | + // Delete the custom resource |
| 61 | + await plugin.uiplugin.remove(); |
| 62 | + } |
| 63 | +
|
| 64 | + // Find the app for this plugin using direct lookup (more efficient than findAll) |
| 65 | + let pluginApp = null; |
| 66 | +
|
| 67 | + try { |
| 68 | + const appId = `${ UI_PLUGIN_NAMESPACE }/${ plugin.name }`; |
| 69 | +
|
| 70 | + pluginApp = await this.$store.dispatch('management/find', { |
| 71 | + type: CATALOG.APP, |
| 72 | + id: appId |
| 73 | + }); |
| 74 | + } catch (e) { |
| 75 | + // If the app cannot be found (e.g. already removed), proceed without error |
| 76 | + pluginApp = null; |
| 77 | + } |
| 78 | +
|
| 79 | + if (pluginApp) { |
| 80 | + try { |
| 81 | + await pluginApp.remove(); |
| 82 | + } catch (e) { |
| 83 | + this.$store.dispatch('growl/error', { |
| 84 | + title: this.t('plugins.error.generic'), |
| 85 | + message: e.message ? e.message : e, |
| 86 | + timeout: 10000 |
| 87 | + }, { root: true }); |
| 88 | +
|
| 89 | + this.busy = false; |
| 90 | +
|
| 91 | + return; |
| 92 | + } |
| 93 | +
|
| 94 | + await this.$store.dispatch('management/findAll', { type: CATALOG.OPERATION }); |
| 95 | + } |
| 96 | +
|
| 97 | + // Close the dialog |
| 98 | + this.closeDialog({ uninstalled: true, plugin }); |
| 99 | + } |
| 100 | + } |
| 101 | +}; |
| 102 | +</script> |
| 103 | +
|
| 104 | +<template> |
| 105 | + <div class="plugin-install-dialog"> |
| 106 | + <h4 class="mt-10"> |
| 107 | + {{ t('plugins.install.alreadyInstalledTitle') }} |
| 108 | + </h4> |
| 109 | + <div class="mt-10 dialog-panel"> |
| 110 | + <div class="dialog-info"> |
| 111 | + <p> |
| 112 | + {{ t('plugins.install.alreadyInstalledPrompt') }} |
| 113 | + </p> |
| 114 | + </div> |
| 115 | + <div class="dialog-buttons"> |
| 116 | + <button |
| 117 | + :disabled="busy" |
| 118 | + class="btn role-secondary" |
| 119 | + data-testid="uninstall-existing-ext-modal-cancel-btn" |
| 120 | + @click="closeDialog(false)" |
| 121 | + > |
| 122 | + {{ t('generic.cancel') }} |
| 123 | + </button> |
| 124 | + <AsyncButton |
| 125 | + mode="uninstall" |
| 126 | + :action-label="t('plugins.install.uninstallExisting')" |
| 127 | + data-testid="uninstall-existing-ext-modal-uninstall-btn" |
| 128 | + @click="uninstall()" |
| 129 | + /> |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | +</template> |
| 134 | +
|
| 135 | +<style lang="scss" scoped> |
| 136 | + @import '@shell/assets/styles/base/_mixins.scss'; |
| 137 | +
|
| 138 | + .plugin-install-dialog { |
| 139 | + @include extension-dialog; |
| 140 | + } |
| 141 | +</style> |
0 commit comments