Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Introduce OcResourceLink to reduce code duplication...
Browse files Browse the repository at this point in the history
... and fix icons/thumbnails not being shown if the resource is not clickable.
  • Loading branch information
dschmidt committed Mar 7, 2022
1 parent adf9117 commit b87ac0f
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Icons/Thumbnails were only visible for clickable resources

We fixed that only clickable resources had icons/thumbnails in `OcResource`.
It was fixed by introducing an `OcResourceLink` component that reduces code
complexity and duplication when linking resources.


https://github.com/owncloud/owncloud-design-system/pull/2007
104 changes: 104 additions & 0 deletions src/components/atoms/OcResourceLink/OcResourceLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<template>
<component
:is="componentType"
v-bind="componentProps"
v-if="isResourceClickable"
:target="linkTargetBlank"
:aria-describedby="opensInNewWindowDescriptionId"
@click.stop="emitClick"
@click.native.stop
>
<slot :opensInNewWindowDescriptionId="opensInNewWindowDescriptionId" />
</component>
<span v-else>
<slot />
</span>
</template>

<script>
import uniqueId from "../../../utils/uniqueId"
/**
* Wraps content in a resource link
*/
export default {
name: "OcResourceLink",
status: "prototype",
release: "unreleased",
props: {
/**
* The resource folder link
*/
folderLink: {
type: Object,
required: false,
default: null,
},
/**
* The resource to be displayed
*/
resource: {
type: Object,
required: true,
},
/**
* Asserts whether clicking on the resource name triggers any action
*/
isResourceClickable: {
type: Boolean,
required: false,
default: true,
},
},
computed: {
isFolder() {
return this.resource.isFolder
},
componentType() {
return this.isFolder ? "router-link" : "oc-button"
},
componentProps() {
if (!this.isRouterLink) {
return {
appearance: "raw",
gapSize: "none",
justifyContent: "left",
}
}
return {
to: this.folderLink,
}
},
opensInNewWindowDescriptionId() {
if (this.resource.opensInNewWindow) {
return uniqueId("oc-link-description-")
}
return null
},
isRouterLink() {
return this.isResourceClickable && this.isFolder
},
linkTargetBlank() {
if (this.isRouterLink && this.resource.opensInNewWindow) {
return "_blank"
}
return null
},
},
methods: {
emitClick() {
if (this.isFolder) {
return
}
/**
* Triggered when the resource is a file and the name is clicked
*/
this.$emit("click")
},
},
}
</script>
7 changes: 7 additions & 0 deletions src/components/organisms/OcResource/OcResource.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { mount } from "@vue/test-utils"

import Resource from "./OcResource.vue"
import OcButton from "../../atoms/OcButton/OcButton.vue"

const stubs = {
"oc-button": OcButton,
}
const fileResource = {
name: "forest.jpg",
path: "nature/forest.jpg",
Expand Down Expand Up @@ -51,6 +55,7 @@ describe("OcResource", () => {
propsData: {
resource: fileResource,
},
stubs,
})

wrapper.find(".oc-resource-name").trigger("click")
Expand All @@ -64,6 +69,7 @@ describe("OcResource", () => {
isPathDisplayed: true,
parentFolderLink: {},
},
stubs,
})

expect(wrapper.find(".parent-folder").find("a").exists()).toBeTruthy()
Expand All @@ -76,6 +82,7 @@ describe("OcResource", () => {
resource: fileResource,
isPathDisplayed: true,
},
stubs,
})

expect(wrapper.find(".parent-folder").find("a").exists()).toBeFalsy()
Expand Down
98 changes: 23 additions & 75 deletions src/components/organisms/OcResource/OcResource.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<template>
<div class="oc-resource oc-text-overflow">
<component
:is="componentType"
v-bind="componentProps"
v-if="isResourceClickable"
:target="linkTargetBlank"
:aria-describedby="opensInNewWindowDescriptionId"
@click.stop="emitClick"
@click.native.stop
<oc-resource-link
:resource="resource"
:is-resource-clickable="isResourceClickable"
:folder-link="folderLink"
@click="emitClick"
>
<oc-img
v-if="hasThumbnail"
Expand All @@ -18,17 +15,15 @@
height="40"
/>
<oc-resource-icon v-else :resource="resource" />
</component>
</oc-resource-link>
<div class="oc-resource-details oc-text-overflow">
<component
:is="componentType"
v-bind="componentProps"
v-if="isResourceClickable"
:target="linkTargetBlank"
:aria-describedby="opensInNewWindowDescriptionId"
<oc-resource-link
v-slot="{ opensInNewWindowDescriptionId }"
:resource="resource"
:is-resource-clickable="isResourceClickable"
:folder-link="folderLink"
class="oc-text-overflow"
@click.stop="emitClick"
@click.native.stop
@click="emitClick"
>
<span
v-if="opensInNewWindowDescriptionId"
Expand All @@ -44,15 +39,7 @@
:full-path="resource.path"
:is-path-displayed="isPathDisplayed"
/>
</component>
<oc-resource-name
v-else
:name="resource.name"
:extension="resource.extension"
:type="resource.type"
:full-path="resource.path"
:is-path-displayed="isPathDisplayed"
/>
</oc-resource-link>
<div class="oc-resource-indicators">
<component
:is="parentFolderComponentType"
Expand Down Expand Up @@ -82,7 +69,7 @@ import OcStatusIndicators from "../../molecules/OcStatusIndicators/OcStatusIndic
import OcIcon from "../../atoms/OcIcon/OcIcon.vue"
import OcResourceName from "../../atoms/OcResourceName/OcResourceName.vue"
import OcResourceIcon from "../../atoms/OcResourceIcon/OcResourceIcon.vue"
import uniqueId from "../../../utils/uniqueId"
import OcResourceLink from "../../atoms/OcResourceLink/OcResourceLink.vue"
import * as path from "path"
/**
Expand All @@ -92,7 +79,15 @@ export default {
name: "OcResource",
status: "ready",
release: "2.1.0",
components: { OcButton, OcImg, OcStatusIndicators, OcIcon, OcResourceName, OcResourceIcon },
components: {
OcButton,
OcImg,
OcStatusIndicators,
OcIcon,
OcResourceName,
OcResourceIcon,
OcResourceLink,
},
props: {
/**
* The resource folder link
Expand All @@ -102,7 +97,6 @@ export default {
required: false,
default: null,
},
/**
* The resource parent folder link path
*/
Expand Down Expand Up @@ -160,10 +154,6 @@ export default {
}
},
isFolder() {
return this.resource.type === "folder"
},
hasThumbnail() {
return (
this.isThumbnailDisplayed &&
Expand All @@ -174,52 +164,10 @@ export default {
thumbnail() {
return this.resource.thumbnail
},
componentType() {
return this.isFolder ? "router-link" : "oc-button"
},
isRouterLink() {
return this.isResourceClickable && this.isFolder
},
componentProps() {
if (!this.isRouterLink) {
return {
appearance: "raw",
gapSize: "none",
justifyContent: "left",
}
}
return {
to: this.folderLink,
}
},
opensInNewWindowDescriptionId() {
if (this.resource.opensInNewWindow) {
return uniqueId("oc-link-description-")
}
return null
},
linkTargetBlank() {
if (this.isRouterLink && this.resource.opensInNewWindow) {
return "_blank"
}
return null
},
},
methods: {
emitClick() {
if (this.isFolder) {
return
}
/**
* Triggered when the resource is a file and the name is clicked
*/
Expand Down

0 comments on commit b87ac0f

Please sign in to comment.