Skip to content
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

feat: show modal when creating links in embed mode #10076

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/design-system/src/components/OcRadio/OcRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineComponent({
**/
// eslint-disable-next-line vue/require-prop-types
modelValue: {
type: [String, Number, Boolean, Object],
required: false,
default: false
},
Expand Down Expand Up @@ -127,7 +128,7 @@ export default defineComponent({
-webkit-appearance: none;
-moz-appearance: none;

border: 1px solid var(--oc-color-input-border);
border: 1px solid var(--oc-color-swatch-brand-default);
border-radius: 50%;
box-sizing: border-box;
background-color: var(--oc-color-input-bg);
Expand All @@ -148,7 +149,7 @@ export default defineComponent({
}

&:checked {
background-color: var(--oc-color-swatch-brand-default);
background-color: var(--oc-color-background-highlight);
}

&.oc-radio-s {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export default defineComponent({
return tooltip
}
if (!this.createFileActionsAvailable) {
return this.$gettext('Create a new folder')
return this.$gettext('New folder')
}
return this.$gettext('Create new files or folders')
},
Expand Down
90 changes: 16 additions & 74 deletions packages/web-app-files/src/components/EmbedActions/EmbedActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
data-testid="button-share"
variation="inverse"
appearance="filled"
:disabled="areSelectActionsDisabled || !canCreatePublicLinks"
@click="sharePublicLinks"
:disabled="
areSelectActionsDisabled || !createLinkAction.isEnabled({ resources: selectedFiles, space })
"
@click="createLinkAction.handler({ resources: selectedFiles, space })"
>{{ $gettext('Share links') }}</oc-button
>
<oc-button
Expand All @@ -25,30 +27,25 @@
</template>

<script lang="ts">
import { computed } from 'vue'
import { computed, unref } from 'vue'
import {
createQuicklink,
getDefaultLinkPermissions,
showQuickLinkPasswordModal,
FileAction,
useAbility,
useClientService,
useEmbedMode,
usePasswordPolicyService,
useFileActionsCreateLink,
useStore
} from '@ownclouders/web-pkg'
import { Resource } from '@ownclouders/web-client'
import { Resource, SpaceResource } from '@ownclouders/web-client'
import { useGettext } from 'vue3-gettext'
import { SharePermissionBit } from '@ownclouders/web-client/src/helpers'
export default {
setup() {
const store = useStore()
const ability = useAbility()
const clientService = useClientService()
const passwordPolicyService = usePasswordPolicyService()
const language = useGettext()
const { isLocationPicker, postMessage } = useEmbedMode()
const space = computed<SpaceResource>(() => store.getters['runtime/spaces/currentSpace'])
const selectedFiles = computed<Resource[]>(() => {
if (isLocationPicker.value) {
return [store.getters['Files/currentFolder']]
Expand All @@ -57,6 +54,9 @@ export default {
return store.getters['Files/selectedFiles']
})
const { actions: createLinkActions } = useFileActionsCreateLink({ store })
const createLinkAction = computed<FileAction>(() => unref(createLinkActions)[0])
const areSelectActionsDisabled = computed<boolean>(() => selectedFiles.value.length < 1)
const canCreatePublicLinks = computed<boolean>(() => ability.can('create-all', 'PublicLink'))
Expand All @@ -76,74 +76,16 @@ export default {
postMessage<null>('owncloud-embed:cancel', null)
}
const emitShare = (links: string[]): void => {
if (!canCreatePublicLinks.value) return
postMessage<string[]>('owncloud-embed:share', links)
}
const sharePublicLinks = async (): Promise<string[]> => {
if (!canCreatePublicLinks.value) return
try {
const passwordEnforced: boolean =
store.getters.capabilities?.files_sharing?.public?.password?.enforced_for?.read_only ===
true
const permissions = getDefaultLinkPermissions({ ability, store })
if (passwordEnforced && permissions > SharePermissionBit.Internal) {
showQuickLinkPasswordModal(
{ store, $gettext: language.$gettext, passwordPolicyService },
async (password) => {
const links: string[] = await Promise.all(
selectedFiles.value.map(
async (resource) =>
(
await createQuicklink({
ability,
resource,
clientService,
language,
store,
password
})
).url
)
)
emitShare(links)
}
)
return
}
const links: string[] = await Promise.all(
selectedFiles.value.map(
async (resource) =>
(await createQuicklink({ ability, resource, clientService, language, store })).url
)
)
emitShare(links)
} catch (error) {
console.error(error)
store.dispatch('showErrorMessage', {
title: language.$gettext('Sharing links failed...'),
error
})
}
}
return {
selectedFiles,
areSelectActionsDisabled,
canCreatePublicLinks,
isLocationPicker,
selectLabel,
sharePublicLinks,
emitCancel,
emitSelect
emitSelect,
space,
createLinkAction
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/web-app-files/src/views/spaces/GenericSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<oc-button
v-if="isEmbedModeEnabled"
key="new-folder-btn"
v-oc-tooltip="limitedScreenSpace ? $gettext('Create a new folder') : ''"
v-oc-tooltip="limitedScreenSpace ? $gettext('New folder') : ''"
data-testid="btn-new-folder"
:aria-label="$gettext('Create a new folder')"
:aria-label="$gettext('New folder')"
appearance="filled"
variation="primary"
:disabled="!canUpload"
@click="createNewFolderAction"
>
<oc-icon name="add" />
<span v-if="!limitedScreenSpace" v-text="$gettext('Create a new folder')" />
<span v-if="!limitedScreenSpace" v-text="$gettext('New folder')" />
</oc-button>

<create-and-upload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`CreateAndUpload component action buttons should show and be enabled 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">
<button aria-label="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">
<!--v-if-->
<!-- @slot Content of the button -->
<oc-icon-stub accessiblelabel="" color="" filltype="fill" name="resource-type-folder" size="medium" type="span" variation="passive"></oc-icon-stub>
Expand Down
Loading