-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[full-ci] Create space from resource #8730
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c23ed76
Init
8ab083e
Enhacement
e635b58
Refactor
ee73c85
Refactor
f1fc622
Refactor
c569bd2
Implement copy
ef57e14
Implement copy
f6d6ab7
Implement edge case
8d103e4
Lint
9dc692b
Update snapshots
c147a9a
Add missing .
4501743
Reset file selection after space creation is done
ffa0b70
Fix unit tests
e519cde
Add changelog item
f97120e
fix unit test
64623da
fix unit test
05aa0a5
Fix order
00d2680
Fix code smell
161fd32
Implement create space from folder e2e test
lookacat de56192
Implement second e2e test
lookacat 9a7d166
WIP e2e
ab66358
Fix e2e tests
lookacat e7c6b0e
Add unit tests for useSpaceHelpers
JammingBen 75eaead
Fix e2e tag test
JammingBen dcc1fc4
Update tests/e2e/cucumber/features/smoke/createSpaceFromSelection.oci…
JammingBen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Enhancement: Create Space from selection | ||
|
||
We've added a new action 'Create Space from selection' to the users | ||
personal home so they can create a Space with the copied content of their | ||
selected files and folders. | ||
|
||
https://github.com/owncloud/web/pull/8730 | ||
https://github.com/owncloud/web/issues/8735 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...ages/web-app-files/src/composables/actions/files/useFileActionsCreateSpaceFromResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Store } from 'vuex' | ||
import { computed, unref } from 'vue' | ||
import { useGettext } from 'vue3-gettext' | ||
import { FileAction, FileActionOptions } from 'web-pkg/src/composables/actions' | ||
import { useAbility, useClientService, useLoadingService, useRouter } from 'web-pkg/src/composables' | ||
import { isPersonalSpaceResource } from 'web-client/src/helpers' | ||
import { isLocationSpacesActive } from 'web-app-files/src/router' | ||
import { useCreateSpace } from 'web-app-files/src/composables/spaces' | ||
import { useSpaceHelpers } from 'web-pkg/src/composables/spaces' | ||
import PQueue from 'p-queue' | ||
|
||
export const useFileActionsCreateSpaceFromResource = ({ store }: { store?: Store<any> } = {}) => { | ||
const { can } = useAbility() | ||
const { $gettext, $ngettext } = useGettext() | ||
const loadingService = useLoadingService() | ||
const { createSpace } = useCreateSpace() | ||
const { checkSpaceNameModalInput } = useSpaceHelpers() | ||
const { webdav } = useClientService() | ||
const router = useRouter() | ||
const hasCreatePermission = computed(() => can('create-all', 'Space')) | ||
|
||
const confirmAction = async ({ spaceName, resources, space }) => { | ||
store.dispatch('hideModal') | ||
const queue = new PQueue({ concurrency: 4 }) | ||
const copyOps = [] | ||
|
||
try { | ||
const createdSpace = await createSpace(spaceName) | ||
store.commit('runtime/spaces/UPSERT_SPACE', createdSpace) | ||
|
||
if (resources.length === 1 && resources[0].isFolder) { | ||
//If a single folder is selected we copy it's content to the Space's root folder | ||
resources = (await webdav.listFiles(space, { path: resources[0].path })).children | ||
} | ||
|
||
for (const resource of resources) { | ||
copyOps.push( | ||
queue.add(() => webdav.copyFiles(space, resource, createdSpace, { path: resource.name })) | ||
) | ||
} | ||
|
||
await Promise.all(copyOps) | ||
store.dispatch('Files/resetFileSelection') | ||
store.dispatch('showMessage', { | ||
title: $gettext('Space was created successfully') | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
store.dispatch('showMessage', { | ||
title: $gettext('Creating space failed…'), | ||
status: 'danger' | ||
}) | ||
} | ||
} | ||
const handler = ({ resources, space }: FileActionOptions) => { | ||
const modal = { | ||
variation: 'passive', | ||
title: $ngettext( | ||
'Create Space from "%{resourceName}"', | ||
'Create Space from selection', | ||
resources.length, | ||
{ | ||
resourceName: resources[0].name | ||
} | ||
), | ||
message: $ngettext( | ||
'Create Space with the content of "%{resourceName}". The content will be copied.', | ||
'Create Space with the selected files. The content will be copied.', | ||
resources.length, | ||
{ | ||
resourceName: resources[0].name | ||
} | ||
), | ||
cancelText: $gettext('Cancel'), | ||
confirmText: $gettext('Create'), | ||
hasInput: true, | ||
inputLabel: $gettext('Space name'), | ||
onInput: checkSpaceNameModalInput, | ||
onCancel: () => store.dispatch('hideModal'), | ||
onConfirm: (spaceName) => | ||
loadingService.addTask(() => confirmAction({ spaceName, space, resources })) | ||
} | ||
|
||
store.dispatch('createModal', modal) | ||
} | ||
|
||
const actions = computed((): FileAction[] => { | ||
return [ | ||
{ | ||
name: 'create-space-from-resource', | ||
icon: 'layout-grid', | ||
handler, | ||
label: () => { | ||
return $gettext('Create Space from selection') | ||
}, | ||
isEnabled: ({ resources, space }) => { | ||
if (!resources.length) { | ||
return false | ||
} | ||
|
||
if (!unref(hasCreatePermission)) { | ||
return false | ||
} | ||
|
||
if ( | ||
!isLocationSpacesActive(router, 'files-spaces-generic') || | ||
!isPersonalSpaceResource(space) | ||
) { | ||
return false | ||
} | ||
|
||
return true | ||
}, | ||
componentType: 'button', | ||
class: 'oc-files-actions-create-space-from-resource-trigger' | ||
} | ||
] | ||
}) | ||
|
||
return { | ||
actions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useCreateSpace' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what if the space was created partially?
Like 3 out of 5 files were copied: do we want to keep the broken space or would it potentially make sense to delete it?
I would really like to avoid that users somehow miss the error message, see the space was created and then delete the source files because they think their data is in the space now.
@tbsbdr what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #8775 to follow up on this (very valid!) point. However, IMO that's not a merge blocker for now as we're heading towards the finish line for this sprint.