Skip to content

Commit

Permalink
feat(editLocallyAction): Handle possible no local client scenario
Browse files Browse the repository at this point in the history
Resolves: #46438

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Jul 11, 2024
1 parent ead87df commit 3f4cd16
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
30 changes: 28 additions & 2 deletions apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { encodePath } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { FileAction, Permission, type Node } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { showError, spawnDialog } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'

import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw'
import ConfirmLocalEditDialog from '../components/dialogs/ConfirmLocalEditDialog.vue'

var openingLocally: Boolean = false

Check failure on line 15 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected var, use let or const instead

Check failure on line 15 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'openingLocally' is assigned a value but never used

Check failure on line 15 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Don't use `Boolean` as a type. Use boolean instead

const startOpenLocalProcess = async function (path: string) {

Check failure on line 17 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'startOpenLocalProcess' is assigned a value but never used

Check failure on line 17 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
showConfirmLocalEditModal(path)
}
const openLocalClient = async function(path: string) {
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'

Expand All @@ -27,6 +32,27 @@ const openLocalClient = async function(path: string) {
}
}


Check failure on line 35 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

More than 1 blank line not allowed
const showConfirmLocalEditModal = async function(path: string, fileName: string = '') {
spawnDialog(
ConfirmLocalEditDialog,
{
name: t('files', 'Open file locally'),
description: t('files', 'The file should now open locally. If you don\'t see this happening, make sure that the desktop client is installed on your system.'),
confirmButtonText: t('files', 'Retry to open locally'),
cancelButtonText: t('files', 'Continue editing online'),
},
(decision) => {
if (!decision) {
window.OCA.Viewer.open({ path: fileName })
return
}
openingLocally = true
openLocalClient

Check failure on line 51 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Expected an assignment or function call and instead saw an expression
},
)
}

export const action = new FileAction({
id: 'edit-locally',
displayName: () => t('files', 'Edit locally'),
Expand Down
1 change: 1 addition & 0 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export default defineComponent({
},

async onActionClick(action, isSubmenu = false) {
debugger

Check failure on line 265 in apps/files/src/components/FileEntry/FileEntryActions.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected 'debugger' statement
// Skip click on loading
if (this.isLoading || this.loading !== '') {
return
Expand Down
55 changes: 55 additions & 0 deletions apps/files/src/components/dialogs/ConfirmLocalEditDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<div>
<NcDialog :open.sync="showDialog" :name="name" :message="description" :buttons="buttons" />

Check failure on line 3 in apps/files/src/components/dialogs/ConfirmLocalEditDialog.vue

View workflow job for this annotation

GitHub Actions / NPM lint

':buttons' should be on a new line
<p>Last response: {{ lastResponse }}</p>
</div>
</template>
<script>
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import IconCancel from '@mdi/svg/svg/cancel.svg?raw'
import IconCheck from '@mdi/svg/svg/check.svg?raw'
export default {
name: 'ConfirmLocalEditDialog',
props: {
name: {
type: String,
default: '',
},
description: {
type: String,
default: '',
},
confirmButtonText: {
type: String,
default: t('files', 'Confirm'),
},
cancelButtonText: {
type: String,
default: t('files', 'Cancel'),
},
},
components: {
NcDialog,
},
data() {
return {
showDialog: false,
lastResponse: 'None',
buttons: [
{
label: this.confirmButtonText,
icon: IconCancel,
callback: () => { this.lastResponse = 'Pressed "Cancel"' },
},
{
label: this.cancelButtonText,
type: 'primary',
icon: IconCheck,
callback: () => { this.lastResponse = 'Pressed "Ok"' },
}
]
}
},
}
</script>

0 comments on commit 3f4cd16

Please sign in to comment.