Skip to content

Commit

Permalink
Add confirmation before updating (#3038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan McClean authored Jan 4, 2021
1 parent ae00d6e commit a3505b7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 47 additions & 2 deletions resources/js/components/updater/Release.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</div>
<div v-if="showActions">
<button v-if="release.type === 'current'" class="btn opacity-50" disabled v-text="__('Current Version')" />
<button v-else-if="release.latest" @click="$emit('install')" class="btn" v-text="__('Update to Latest')" />
<button v-else @click="$emit('install')" class="btn">
<button v-else-if="release.latest" @click="confirmationPrompt = release" class="btn" v-text="__('Update to Latest')" />
<button v-else @click="confirmationPrompt = release" class="btn">
<template v-if="release.type === 'upgrade'">{{ __('Update to :version', { version: release.version }) }}</template>
<template v-if="release.type === 'downgrade'">{{ __('Downgrade to :version', { version: release.version }) }}</template>
</button>
Expand All @@ -18,6 +18,17 @@
<div class="card-body">
<div v-html="release.body"></div>
</div>

<confirmation-modal
v-if="confirmationPrompt"
:title="confirmationTitle"
:bodyText="confirmationText"
:buttonText="__('Confirm')"
:danger="true"
@confirm="confirm"
@cancel="confirmationPrompt = null"
>
</confirmation-modal>
</div>

</template>
Expand All @@ -27,7 +38,41 @@ export default {
props: {
release: { type: Object, required: true },
packageName: { type: String, required: true },
showActions: { type: Boolean }
},
data() {
return {
confirmationPrompt: null,
}
},
computed: {
confirmationTitle() {
let attrs = { name: this.packageName }
return this.confirmationPrompt.type === 'downgrade'
? __('Downgrade :name', attrs)
: __('Update :name', attrs)
},
confirmationText() {
let attrs = { version: this.confirmationPrompt.version }
return this.confirmationPrompt.type === 'downgrade'
? __('Are you sure you want to downgrade to :version?', attrs)
: __('Are you sure you want to update to :version?', attrs)
}
},
methods: {
confirm() {
this.confirmationPrompt = null;
this.$nextTick(() => this.$emit('install'));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/updater/Updater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
v-for="release in unlicensedReleases"
:key="release.version"
:release="release"
:package-name="name"
:show-actions="showActions"
@install="installExplicitVersion(release.version)"
/>
Expand All @@ -45,6 +46,7 @@
v-for="release in licensedReleases"
:key="release.version"
:release="release"
:package-name="name"
:show-actions="showActions"
@install="installExplicitVersion(release.version)"
/>
Expand Down

0 comments on commit a3505b7

Please sign in to comment.