Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <[email protected]>
  • Loading branch information
enjeck committed Dec 29, 2023
1 parent 8c95374 commit 4d7ab2a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 61 deletions.
13 changes: 8 additions & 5 deletions cypress/e2e/tables-table.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let localUser
let user1
let targetUserTransfer

describe('Manage a table', () => {

Expand All @@ -8,7 +8,7 @@ describe('Manage a table', () => {
localUser = user
})
cy.createRandomUser().then(user => {
user1 = user
targetUserTransfer = user
})
})

Expand Down Expand Up @@ -72,10 +72,13 @@ describe('Manage a table', () => {
cy.get('[data-cy="editTableModal"] button').contains('Change owner').click()
cy.get('[data-cy="editTableModal"]').should('not.exist')
cy.get('[data-cy="transferTableModal"]').should('be.visible')
cy.get('[data-cy="transferTableModal"] input[type="search"]').clear().type(user1.userId)
cy.get(`.vs__dropdown-menu [user="${user1.userId}"]`).click()
cy.get('[data-cy="transferTableModal"] input[type="search"]').clear().type(targetUserTransfer.userId)
cy.get(`.vs__dropdown-menu [user="${targetUserTransfer.userId}"]`).click()
cy.get('[data-cy="transferTableButton"]').should('be.enabled').click()
cy.wait(10).get('.toastify.toast-success').should('be.visible')
cy.get('.toastify.toast-success').should('be.visible')
cy.get('.app-navigation__list').contains('test table').should('not.exist')
cy.login(targetUserTransfer)
cy.visit('apps/tables')
cy.get('.app-navigation__list').contains('test table')
})
})
20 changes: 2 additions & 18 deletions src/modules/modals/TransferTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,11 @@
</div>
</div>
<div class="row">
<div class="col-4 mandatory space-T">
{{ t('tables', 'Owner') }}
</div>

<!-- We don't need to show this, since the current user will only see this if they're the owner? -->
<div v-if="localTable !== undefined" class="col-3 inline space-T-small">
<NcUserBubble
:margin="4"
:size="30"
:display-name="localTable.ownerDisplayName"
:user="localTable.owner" />
</div>
</div>
<div class="row">
<h3>{{ t('tables', 'Transfer this table to another user') }}</h3>
<NcUserAndGroupPicker :select-users="true" :select-groups="false" :new-owner-user-id.sync="newOwnerUserId" />
</div>
<div class="row">
<div class="fix-col-4 space-T justify-between">
<div class="fix-col-4 space-T end">
<NcButton type="warning" :disabled="newOwnerUserId === ''" data-cy="transferTableButton" @click="transferMe">
{{ t('tables', 'Transfer') }}
</NcButton>
Expand Down Expand Up @@ -90,11 +77,8 @@ export default {
},
methods: {
actionCancel() {
this.reset()
this.$emit('close')
},
reset() {
},
async transferMe() {
const transferId = this.table.id
let activeTableId
Expand Down
69 changes: 31 additions & 38 deletions src/shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div class="row space-B">
<h3>{{ t('tables', 'Transfer this table to another user') }}</h3>
<NcSelect id="transfer-ownership-select" v-model="value" style="width: 100%;" :loading="loading" :options="options" :placeholder="t('tables', 'User…')"
<NcSelect id="transfer-ownership-select" v-model="value" style="width: 100%;" :loading="loading" :options="options" :placeholder="t('tables', `${getShareTypeString()}...`)"
:searchable="true" :get-option-key="(option) => option.key"
label="displayName" :user-select="true"
@search="asyncFind" @input="addTransfer">
Expand All @@ -20,6 +19,8 @@ import debounce from 'debounce'
import { NcSelect } from '@nextcloud/vue'
import formatting from '../../../shared/mixins/formatting.js'
import ShareTypes from '../../mixins/shareTypesMixin.js'
import { showError } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/style.css'
export default {
Expand Down Expand Up @@ -67,7 +68,7 @@ export default {
},
isValidQuery() {
return this.query && this.query.trim() !== '' && this.query.length > this.minSearchStringLength
return this.query?.trim() && this.query.length >= this.minSearchStringLength
},
options() {
Expand Down Expand Up @@ -99,21 +100,25 @@ export default {
},
getShareTypes() {
if (this.selectUsers && this.selectGroups) {
return [
this.SHARE_TYPES.SHARE_TYPE_USER,
this.SHARE_TYPES.SHARE_TYPE_GROUP,
]
} else if (this.selectUsers) {
return [
this.SHARE_TYPES.SHARE_TYPE_USER,
]
} else if (this.selectGroups) {
return [
this.SHARE_TYPES.SHARE_TYPE_GROUP,
]
} else {
return []
const types = []
if (this.selectUsers) {
types.push(this.SHARE_TYPES.SHARE_TYPE_USER)
}
if (this.selectGroups) {
types.push(this.SHARE_TYPES.SHARE_TYPE_GROUP)
}
return types
},
getShareTypeString(){
if (this.selectUsers && !this.selectGroups) {
return 'User'
}
else if (!this.selectUsers && this.selectGroups) {
return 'Group'
}
else {
return 'User or group'
}
},
Expand All @@ -133,7 +138,9 @@ export default {
shareTypeQueryString += `&shareTypes[]=${shareType}`
})
const url = generateOcsUrl('core/autocomplete/get?search={searchQuery}&itemType=%20&itemId=%20{shareTypeQueryString}&limit={limit}', { searchQuery: search, shareTypeQueryString, limit: this.maxAutocompleteResults })
await axios.get(url).then(res => {
try {
const res = await axios.get(url)
const rawSuggestions = res.data.ocs.data.map(autocompleteResult => {
return {
user: autocompleteResult.id,
Expand All @@ -145,33 +152,19 @@ export default {
})
this.suggestions = this.filterOutCurrentUser(rawSuggestions)
this.loading = false
}).catch(err => {
console.debug(err)
})
} catch (err) {
console.debug(err)
showError(t('tables', `Failed to fetch ${this.getShareTypeString().toLowerCase()}`))
}
},
debounceGetSuggestions: debounce(function(...args) {
this.getSuggestions(...args)
}, 300),
filterOutCurrentUser(list) {
return list.reduce((arr, item) => {
if (typeof item !== 'object') {
return arr
}
try {
if (item.isUser && item.user === getCurrentUser().uid) {
return arr
}
arr.push(item)
} catch {
return arr
}
return arr
}, [])
return list.filter((item) => !(item.isUser && item.user === getCurrentUser().uid))
},
},
Expand Down

0 comments on commit 4d7ab2a

Please sign in to comment.