Skip to content

Commit

Permalink
Fix unit tests & refactor link sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwengerter committed May 23, 2022
1 parent a60dff0 commit cf652df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 52 deletions.
46 changes: 13 additions & 33 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:is-modifiable="canEdit"
:is-password-enforced="isPasswordEnforcedFor(quicklink)"
:link="quicklink"
@updateLink="checkLinkToCreate"
@updateLink="checkLinkToUpdate"
@removePublicLink="deleteLinkConfirmation"
/>
<hr class="link-separator oc-my-m" />
Expand Down Expand Up @@ -80,7 +80,6 @@ import { shareViaLinkHelp } from '../../../helpers/contextualHelpers'
import { getParentPaths } from '../../../helpers/path'
import { ShareTypes, LinkShareRoles, SharePermissions } from '../../../helpers/share'
import { cloneStateObject } from '../../../helpers/store'
import { textUtils } from '../../../helpers/textUtils'
import { showQuickLinkPasswordModal } from '../../../quickActions'
import CreateQuickLink from './Links/CreateQuickLink.vue'
import DetailsAndEdit from './Links/DetailsAndEdit.vue'
Expand Down Expand Up @@ -214,27 +213,24 @@ export default defineComponent({
},
links() {
const nonQuickLinkOutgoingLinks = this.currentFileOutgoingLinks.filter(
(link) => !link.quicklink
)
return [...nonQuickLinkOutgoingLinks, ...this.indirectLinks]
.sort(this.linksComparator)
const nonQuickLinkOutgoingLinks = this.currentFileOutgoingLinks
.filter((link) => !link.quicklink)
.map((share) => {
share.key = 'direct-link-' + share.id
return share
})
.sort((a, b) => {
return b.stime - a.stime
})
return [...nonQuickLinkOutgoingLinks, ...this.indirectLinks]
},
displayLinks() {
const linkShares = this.links
const sortedLinkShares = linkShares.sort((a, b) => {
return b.stime - a.stime
})
if (this.links.length > 3 && this.linkListCollapsed) {
return sortedLinkShares.slice(0, 3)
return this.links.slice(0, 3)
}
return sortedLinkShares
return this.links
},
indirectLinks() {
Expand All @@ -258,7 +254,9 @@ export default defineComponent({
})
}
})
return allShares.sort(this.linksComparator)
return allShares.sort((a, b) => {
return b.stime - a.stime
})
},
resourceIsSpace() {
Expand Down Expand Up @@ -314,24 +312,6 @@ export default defineComponent({
})
},
linksComparator(l1, l2) {
// sorting priority 1: display name (lower case, ascending), 2: creation time (descending)
const name1 = l1.name.toLowerCase().trim()
const name2 = l2.name.toLowerCase().trim()
const l1Direct = !l1.indirect
const l2Direct = !l2.indirect
if (l1Direct === l2Direct) {
if (name1 === name2) {
return l1.stime - l2.stime
}
return textUtils.naturalSortCompare(name1, name2)
}
return l1Direct ? -1 : 1
},
isPasswordEnforcedFor(link) {
const currentRole = LinkShareRoles.getByBitmask(
parseInt(link.permissions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ export default {
},
currentLinkRoleLabel() {
return LinkShareRoles.getByBitmask(
parseInt(this.link.permissions),
this.isFolderShare
).label()
return LinkShareRoles.getByBitmask(parseInt(this.link.permissions), this.isFolderShare).label
},
editButtonLabel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ describe('FileLinks', () => {
highlightedFile: {
path: '/lorem.txt',
type: 'file',
canShare: jest.fn(() => false)
canShare: jest.fn(() => false),
isFolder: false
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ localVue.use(GetTextPlugin, {
silent: true
})

const availableRoleOptions = LinkShareRoles.list(false, true).map((role) => {
return {
role,
name: role.name,
label: role.label
}
})
const availableRoleOptions = LinkShareRoles.list(false, true)

const exampleLink = {
name: 'Example link',
Expand All @@ -46,7 +40,7 @@ describe('DetailsAndEdit component', () => {
})
})

function getShallowMountedWrapper(link, expireDateEnforced = false, modifiable = false) {
function getShallowMountedWrapper(link, expireDateEnforced = false, isModifiable = false) {
return shallowMount(DetailsAndEdit, {
propsData: {
availableRoleOptions,
Expand All @@ -58,12 +52,8 @@ function getShallowMountedWrapper(link, expireDateEnforced = false, modifiable =
max: null
},
link,
modifiable,
passwordEnforced: {
read_only: false,
upload_only: false,
read_write: false
}
isModifiable,
isPasswordEnforced: false
},
store: createStore(),
directives: {
Expand Down

0 comments on commit cf652df

Please sign in to comment.