Skip to content

Commit

Permalink
Create and open shortcut (#9890)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear authored Nov 2, 2023
1 parent 0846a0a commit 5d91fa2
Show file tree
Hide file tree
Showing 15 changed files with 536 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/design-system/src/helpers/resourceIconMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@
"name": "resource-type-text",
"color": "var(--oc-color-text-default)"
},
"url": {
"name": "resource-type-url",
"color": "var(--oc-color-text-default)"
},
"vsd": {
"name": "resource-type-document",
"color": "var(--oc-color-icon-document)"
Expand Down
37 changes: 30 additions & 7 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<template>
<create-shortcut-modal
v-if="isCreateNewShortcutModalOpen"
:space="space"
:cancel="closeCreateNewShortcutModal"
/>
<div v-if="showActions" class="create-and-upload-actions oc-flex-inline oc-mr-s">
<template v-if="createFileActionsAvailable">
<span v-oc-tooltip="newButtonTooltip">
Expand Down Expand Up @@ -56,6 +61,12 @@
</oc-button>
</li>
</template>
<li class="create-list-shortcut oc-menu-item-hover">
<oc-button id="new-shortcut-btn" appearance="raw" @click="createNewShortcutAction">
<oc-icon name="external-link" size="medium" />
<span v-text="$gettext('Shortcut')" />
</oc-button>
</li>
</oc-list>
</oc-drop>
</template>
Expand Down Expand Up @@ -123,7 +134,8 @@
:disabled="isActionDisabled(action)"
@click="action.handler"
>
<oc-icon :name="action.icon" fill-type="line" /><span v-text="action.label()"
<oc-icon :name="action.icon" fill-type="line" />
<span v-text="action.label()"
/></oc-button>
</li>
</oc-list>
Expand Down Expand Up @@ -159,16 +171,13 @@
<script lang="ts">
import { mapActions, mapGetters } from 'vuex'
import { useFileActions } from '@ownclouders/web-pkg'
import { useFileActions, useFileActionsCreateNewShortcut } from '@ownclouders/web-pkg'
import { isLocationPublicActive, isLocationSpacesActive } from '@ownclouders/web-pkg'
import { useActiveLocation } from '@ownclouders/web-pkg'
import {
useFileActionsCreateNewFile,
useFileActionsCreateNewFolder,
useFileActionsPaste
} from '@ownclouders/web-pkg'
import {
useFileActionsPaste,
useRequest,
useCapabilityShareJailEnabled,
useCapabilitySpacesEnabled,
Expand All @@ -178,6 +187,8 @@ import {
} from '@ownclouders/web-pkg'
import ResourceUpload from './Upload/ResourceUpload.vue'
import CreateShortcutModal from '@ownclouders/web-pkg/src/components/CreateShortcutModal.vue'
import {
computed,
defineComponent,
Expand All @@ -200,7 +211,8 @@ import { v4 as uuidv4 } from 'uuid'
export default defineComponent({
components: {
ResourceUpload
ResourceUpload,
CreateShortcutModal
},
props: {
space: {
Expand Down Expand Up @@ -256,6 +268,14 @@ export default defineComponent({
})
const createNewFolderAction = computed(() => unref(createNewFolder)[0].handler)
const {
actions: createNewShortcut,
modalOpen: isCreateNewShortcutModalOpen,
closeModal: closeCreateNewShortcutModal
} = useFileActionsCreateNewShortcut({ store })
const createNewShortcutAction = computed(() => unref(createNewShortcut)[0].handler)
const newFileHandlers = computed(() => store.getters.newFileHandlers)
const { actions: createNewFileActions } = useFileActionsCreateNewFile({
Expand Down Expand Up @@ -396,11 +416,14 @@ export default defineComponent({
createNewFolder,
mimetypesAllowedForCreation,
createNewFolderAction,
createNewShortcutAction,
extensionActions,
pasteFileAction,
isActionDisabled,
actionKeySuffix,
showDrop,
isCreateNewShortcutModalOpen,
closeCreateNewShortcutModal,
// HACK: exported for unit tests:
onUploadComplete
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CreateAndUpload component action buttons should show and be enabled if file creation is possible 1`] = `
<!--v-if-->
<div class="create-and-upload-actions oc-flex-inline oc-mr-s">
<span>
<button aria-label="Create a new folder" class="oc-button oc-rounded oc-button-m oc-button-justify-content-center oc-button-gap-m oc-button-primary oc-button-primary-filled" id="new-folder-btn" type="button">
Expand Down Expand Up @@ -34,6 +36,8 @@ exports[`CreateAndUpload component action buttons should show and be enabled if
`;

exports[`CreateAndUpload component file handlers should show additional handlers 1`] = `
<!--v-if-->
<div class="create-and-upload-actions oc-flex-inline oc-mr-s">
<span>
<button aria-label="Create new files or folders" class="oc-button oc-rounded oc-button-m oc-button-justify-content-center oc-button-gap-m oc-button-primary oc-button-primary-filled" id="new-file-menu-btn" type="button">
Expand Down Expand Up @@ -77,6 +81,14 @@ exports[`CreateAndUpload component file handlers should show additional handlers
<span>Draw.io document</span>
</button>
</li>
<li class="create-list-shortcut oc-menu-item-hover">
<button class="oc-button oc-rounded oc-button-m oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw" id="new-shortcut-btn" type="button">
<!--v-if-->
<!-- @slot Content of the button -->
<oc-icon-stub accessiblelabel="" color="" filltype="fill" name="external-link" size="medium" type="span" variation="passive"></oc-icon-stub>
<span>Shortcut</span>
</button>
</li>
</oc-list-stub>
</oc-drop-stub>
<span>
Expand Down
6 changes: 3 additions & 3 deletions packages/web-pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"zod": "^3.22.4"
},
"peerDependencies": {
"@ownclouders/web-client": "workspace:*",
"@casl/ability": "^6.3.3",
"@casl/vue": "^2.2.1",
"@microsoft/fetch-event-source": "^2.0.1",
"@ownclouders/web-client": "workspace:*",
"@uppy/core": "^3.2.0",
"@uppy/drop-target": "^2.0.0",
"@uppy/tus": "^3.1.0",
Expand All @@ -36,16 +36,16 @@
"lodash-es": "^4.17.21",
"luxon": "^2.4.0",
"mark.js": "^8.11.1",
"p-queue": "^6.6.2",
"password-sheriff": "^1.1.1",
"pinia": "^2.1.3",
"p-queue": "^6.6.2",
"qs": "^6.10.3",
"semver": "^7.3.8",
"uuid": "^9.0.0",
"vue-concurrency": "4.0.1",
"vue-router": "4.2.0",
"vue3-gettext": "2.5.0-alpha.1",
"vuex": "4.1.0",
"@microsoft/fetch-event-source": "^2.0.1"
"dompurify": "^3.0.6"
}
}
94 changes: 94 additions & 0 deletions packages/web-pkg/src/components/CreateShortcutModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<portal to="app.runtime.modal">
<oc-modal
:title="$gettext('Create a Shortcut')"
:button-cancel-text="$gettext('Cancel')"
:button-confirm-text="$gettext('Create')"
:button-confirm-disabled="confirmButtonDisabled"
@cancel="cancel"
@confirm="createShortcut"
>
<template #content>
url
<oc-text-input v-model="inputUrl" />
<div class="oc-flex oc-flex-bottom oc-width-1-1 oc-mt-m">
<oc-text-input
v-model="inputFilename"
class="oc-width-1-1"
:label="$gettext('Shortcut name')"
/>
<span class="oc-ml-s">.url</span>
</div>
</template>
</oc-modal>
</portal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref, unref, computed } from 'vue'
import { SpaceResource } from '@ownclouders/web-client'
import { useClientService, useStore } from '../composables'
import { urlJoin } from '@ownclouders/web-client/src/utils'
import { useGettext } from 'vue3-gettext'
import DOMPurify from 'dompurify'
export default defineComponent({
name: 'CreateShortcutModal',
props: {
space: {
type: Object as PropType<SpaceResource>,
required: true
},
cancel: {
type: Function as PropType<(...args: any) => unknown>,
required: true
}
},
setup(props) {
const clientService = useClientService()
const { $gettext } = useGettext()
const store = useStore()
const inputUrl = ref('')
const inputFilename = ref('')
const confirmButtonDisabled = computed(() => !(unref(inputUrl) && unref(inputFilename)))
const currentFolder = computed(() => {
return store.getters['Files/currentFolder']
})
const createShortcut = async () => {
// Closes the modal
props.cancel()
try {
// Omit possible xss code
const sanitizedUrl = DOMPurify.sanitize(unref(inputUrl), { USE_PROFILES: { html: true } })
const content = `[InternetShortcut]\nURL=${unref(sanitizedUrl)}`
const path = urlJoin(unref(currentFolder).path, `${unref(inputFilename)}.url`)
const resource = await clientService.webdav.putFileContents(props.space, {
path,
content
})
store.commit('Files/UPSERT_RESOURCE', resource)
store.dispatch('showMessage', {
title: $gettext('Shortcut was created successfully')
})
} catch (e) {
console.error(e)
store.dispatch('showErrorMessage', {
title: $gettext('Failed to create shortcut'),
error: e
})
}
}
return {
confirmButtonDisabled,
createShortcut,
inputUrl,
inputFilename
}
}
})
</script>
8 changes: 7 additions & 1 deletion packages/web-pkg/src/components/FilesList/ContextActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<script lang="ts">
import ContextActionMenu from '../ContextActions/ContextActionMenu.vue'
import { useFileActionsToggleHideShare, useStore } from '../../composables'
import {
useFileActionsOpenShortcut,
useFileActionsToggleHideShare,
useStore
} from '../../composables'
import { computed, defineComponent, PropType, Ref, toRef, unref } from 'vue'
import {
Expand Down Expand Up @@ -71,6 +75,7 @@ export default defineComponent({
store
})
const { actions: showSharesActions } = useFileActionsShowShares({ store })
const { actions: openShortcutActions } = useFileActionsOpenShortcut({ store })
// type cast to make vue-tsc aware of the type
const actionOptions = toRef(props, 'actionOptions') as Ref<FileActionOptions>
Expand Down Expand Up @@ -107,6 +112,7 @@ export default defineComponent({
const menuItemsActions = computed(() => {
return [
...unref(openShortcutActions),
...unref(downloadArchiveActions),
...unref(downloadFileActions),
...unref(deleteActions),
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { default as SpaceQuota } from './SpaceQuota.vue'
export { default as SearchBarFilter } from './SearchBarFilter.vue'
export { default as ViewOptions } from './ViewOptions.vue'
export { default as PortalTarget } from './PortalTarget.vue'
export { default as CreateShortcutModal } from './CreateShortcutModal.vue'
2 changes: 2 additions & 0 deletions packages/web-pkg/src/composables/actions/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export * from './useFileActionsShowShares'
export * from './useFileActionsCreateSpaceFromResource'
export * from './useFileActionsCreateNewFolder'
export * from './useFileActionsCreateNewFile'
export * from './useFileActionsCreateNewShortcut'
export * from './useFileActionsOpenShortcut'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Action,
FileAction,
FileActionOptions,
useFileActionsOpenShortcut,
useIsSearchActive,
useWindowOpen
} from '../../actions'
Expand Down Expand Up @@ -68,8 +69,10 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
const { actions: restoreActions } = useFileActionsRestore({ store })
const { actions: showEditTagsActions } = useFileActionsShowEditTags({ store })
const { actions: createSpaceFromResource } = useFileActionsCreateSpaceFromResource({ store })
const { actions: openShortcutActions } = useFileActionsOpenShortcut({ store })

const systemActions = computed((): Action[] => [
...unref(openShortcutActions),
...unref(downloadArchiveActions),
...unref(downloadFileActions),
...unref(deleteActions),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Resource } from '@ownclouders/web-client/src/helpers'
import { Store } from 'vuex'
import { computed, unref, ref } from 'vue'
import { useStore } from '../../store'
import { FileAction } from '../../../'
import { useGettext } from 'vue3-gettext'

export const useFileActionsCreateNewShortcut = ({ store }: { store?: Store<any> } = {}) => {
store = store || useStore()
const { $gettext } = useGettext()
const currentFolder = computed((): Resource => store.getters['Files/currentFolder'])

const modalOpen = ref(false)

const closeModal = () => {
modalOpen.value = false
}

const handler = () => {
modalOpen.value = true
}

const actions = computed((): FileAction[] => {
return [
{
name: 'create-shortcut',
icon: 'external-link',
handler,
label: () => {
return $gettext('New Shortcut')
},
isEnabled: () => {
return unref(currentFolder)?.canCreate()
},
componentType: 'button',
class: 'oc-files-actions-create-new-shortcut'
}
]
})

return {
actions,
modalOpen,
closeModal
}
}
Loading

0 comments on commit 5d91fa2

Please sign in to comment.