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

TSK-1436: change deleting spaces to removing, add action to move all non-valid requests to correct spaces #3149

Merged
merged 5 commits into from
May 10, 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
11 changes: 6 additions & 5 deletions models/hr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ export function createModel (builder: Builder): void {
createAction(
builder,
{
action: view.actionImpl.Delete,
label: view.string.Delete,
icon: view.icon.Delete,
action: view.actionImpl.Archive,
haiodo marked this conversation as resolved.
Show resolved Hide resolved
label: view.string.Archive,
icon: view.icon.Archive,
input: 'any',
category: hr.category.HR,
keyBinding: ['Meta + Backspace', 'Ctrl + Backspace'],
Expand All @@ -339,9 +339,10 @@ export function createModel (builder: Builder): void {
_id: { $nin: [hr.ids.Head] }
},
target: hr.class.Department,
context: { mode: 'context', application: hr.app.HR, group: 'create' }
context: { mode: ['context', 'browser'], group: 'tools' },
override: [view.action.Archive, view.action.Delete]
},
hr.action.DeleteDepartment
hr.action.ArchiveDepartment
)

createAction(
Expand Down
27 changes: 23 additions & 4 deletions models/hr/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
if (department._id === hr.ids.Head) continue
ancestors.set(department._id, department.space)
}
for (const departmentTest of departments) {
const parents: Department[] = parentsWithDepartmentMap.get(departmentTest._id) ?? []
let _id = departmentTest._id
for (const departmentItem of departments) {
const parents: Department[] = parentsWithDepartmentMap.get(departmentItem._id) ?? []
let _id = departmentItem._id
while (true) {
const department = departmentsMap.get(_id)
if (department === undefined) break
Expand All @@ -71,7 +71,7 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
if (next === undefined) break
_id = next
}
parentsWithDepartmentMap.set(departmentTest._id, parents)
parentsWithDepartmentMap.set(departmentItem._id, parents)
}
const staff = await tx.findAll(hr.mixin.Staff, {})
const promises = []
Expand All @@ -93,6 +93,24 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
}
await Promise.all(promises)
}

async function fixInvalidRequests (tx: TxOperations): Promise<void> {
const departments = await tx.findAll(hr.class.Department, {})
const staff = await tx.findAll(hr.mixin.Staff, {})
const staffDepartmentMap = new Map(staff.map((s) => [s._id, s.department]))
const requests = await tx.findAll(hr.class.Request, { space: { $nin: departments.map((d) => d._id) } })
const res = []
for (const request of requests) {
const currentStaffDepartment = staffDepartmentMap.get(request.attachedTo)
if (currentStaffDepartment !== null) {
res.push(tx.update(request, { space: currentStaffDepartment }))
} else {
res.push(tx.update(request, { space: hr.ids.Head }))
}
}
await Promise.all(res)
}

function toTzDate (date: number): TzDate {
const res = new Date(date)
return {
Expand Down Expand Up @@ -234,5 +252,6 @@ export const hrOperation: MigrateOperation = {
await createSpace(tx)
await fixDuplicatesInDepartments(tx)
await fixDepartmentsFromStaff(tx)
await fixInvalidRequests(tx)
}
}
2 changes: 1 addition & 1 deletion models/hr/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default mergeIds(hrId, hr, {
},
action: {
EditDepartment: '' as Ref<Action>,
DeleteDepartment: '' as Ref<Action>,
ArchiveDepartment: '' as Ref<Action>,
EditRequest: '' as Ref<Action>,
EditRequestType: '' as Ref<Action>,
DeleteRequest: '' as Ref<Action>
Expand Down
5 changes: 2 additions & 3 deletions models/server-hr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export function createModel (builder: Builder): void {
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverHr.trigger.OnDepartmentStaff,
txMatch: {
_class: core.class.TxCollectionCUD,
'tx.objectClass': hr.mixin.Staff,
'tx._class': core.class.TxMixin
_class: core.class.TxMixin,
mixin: hr.mixin.Staff
}
})

Expand Down
3 changes: 2 additions & 1 deletion models/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ export const actionTemplates = template({
context: {
mode: ['context', 'browser'],
group: 'tools'
}
},
override: [view.action.Archive, view.action.Delete]
},
unarchiveSpace: {
label: task.string.Unarchive,
Expand Down
3 changes: 2 additions & 1 deletion models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ export function createModel (builder: Builder): void {
context: {
mode: ['context', 'browser'],
group: 'edit'
}
},
override: [view.action.Archive, view.action.Delete]
},
tracker.action.DeleteProject
)
Expand Down
18 changes: 18 additions & 0 deletions models/view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,24 @@ export function createModel (builder: Builder): void {
view.action.Delete
)

createAction(
builder,
{
action: view.actionImpl.Archive,
label: view.string.Archive,
icon: view.icon.Archive,
category: view.category.General,
input: 'any',
query: {
archived: false
},
target: core.class.Space,
context: { mode: ['context', 'browser'], group: 'tools' },
override: [view.action.Delete]
},
view.action.Archive
)

// Keyboard actions.
createAction(
builder,
Expand Down
1 change: 1 addition & 0 deletions models/view/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import view from '@hcengineering/view-resources/src/plugin'
export default mergeIds(viewId, view, {
actionImpl: {
Delete: '' as ViewAction,
Archive: '' as ViewAction,
Move: '' as ViewAction,
MoveLeft: '' as ViewAction,
MoveRight: '' as ViewAction,
Expand Down
5 changes: 4 additions & 1 deletion plugins/hr-resources/src/components/Structure.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

query.query(
hr.class.Department,
resultQuery,
{
...resultQuery,
archived: false
},
(res) => {
head = res.find((p) => p._id === hr.ids.Head)
descendants.clear()
Expand Down
2 changes: 2 additions & 0 deletions plugins/view-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"Role": "Role",
"DeleteObject": "Delete object",
"DeleteObjectConfirm": "Do you want to delete this {count, plural, =1 {object} other {# objects}}?",
"Archive": "Archive",
"ArchiveConfirm": "Do you want to archive this {count, plural, =1 {object} other {# objects}}?",
"Open": "Open",
"Assignees": "Assignees",
"Labels": "Labels",
Expand Down
4 changes: 3 additions & 1 deletion plugins/view-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"Table": "Таблица",
"Role": "Роль",
"DeleteObject": "Удалить объект",
"DeleteObjectConfirm": "Вы действительно хотите удалить {count, plural, =1 {этот обьект} other {эти # обьекта}}?",
"DeleteObjectConfirm": "Вы действительно хотите удалить {count, plural, =1 {этот объект} other {эти # объекта}}?",
"Archive": "Архивировать",
"ArchiveConfirm": "Вы действительно хотите заархивировать {count, plural, =1 {этот объект} other {эти # объекта}}?",
"Open": "Открыть",
"Assignees": "Исполнители",
"Labels": "Метки",
Expand Down
24 changes: 23 additions & 1 deletion plugins/view-resources/src/actionImpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Class, Doc, DocumentQuery, Hierarchy, Ref } from '@hcengineering/core'
import { Class, Doc, DocumentQuery, Hierarchy, Ref, Space, TxResult } from '@hcengineering/core'
import { Asset, getResource, IntlString, Resource } from '@hcengineering/platform'
import { getClient, MessageBox, updateAttribute } from '@hcengineering/presentation'
import {
Expand Down Expand Up @@ -70,6 +70,27 @@ function Delete (object: Doc | Doc[]): void {
)
}

function Archive (object: Space | Space[]): void {
showPopup(
MessageBox,
{
label: view.string.Archive,
message: view.string.ArchiveConfirm,
params: { count: Array.isArray(object) ? object.length : 1 },
action: async () => {
const objs = Array.isArray(object) ? object : [object]
const client = getClient()
const promises: Array<Promise<TxResult>> = []
for (const obj of objs) {
promises.push(client.update(obj, { archived: true }))
}
await Promise.all(promises)
}
},
undefined
)
}

async function Move (docs: Doc | Doc[]): Promise<void> {
showPopup(MoveView, { selected: docs })
}
Expand Down Expand Up @@ -408,6 +429,7 @@ async function getPopupAlignment (
export const actionImpl = {
CopyTextToClipboard,
Delete,
Archive,
Move,
MoveUp,
MoveDown,
Expand Down
12 changes: 6 additions & 6 deletions plugins/view-resources/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ export function filterActions (
if (role < AccountRole.Maintainer && action.secured === true) {
continue
}
if (action.query !== undefined) {
const r = matchQuery([doc], action.query, doc._class, hierarchy)
if (r.length === 0) {
continue
}
}
if (
(hierarchy.isDerived(doc._class, action.target) && client.getHierarchy().isDerived(action.target, derived)) ||
(hierarchy.isMixin(action.target) && hierarchy.hasMixin(doc, action.target))
) {
if (action.override !== undefined) {
overrideRemove.push(...action.override)
}
if (action.query !== undefined) {
const r = matchQuery([doc], action.query, doc._class, hierarchy)
if (r.length === 0) {
continue
}
}
result.push(action)
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/view-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default mergeIds(viewId, view, {
ChooseAColor: '' as IntlString,
DeleteObject: '' as IntlString,
DeleteObjectConfirm: '' as IntlString,
Archive: '' as IntlString,
ArchiveConfirm: '' as IntlString,
Assignees: '' as IntlString,
Labels: '' as IntlString,
ActionPlaceholder: '' as IntlString,
Expand Down
1 change: 1 addition & 0 deletions plugins/view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ const view = plugin(viewId, {
},
action: {
Delete: '' as Ref<Action>,
Archive: '' as Ref<Action>,
Move: '' as Ref<Action>,
MoveLeft: '' as Ref<Action>,
MoveRight: '' as Ref<Action>,
Expand Down