From 8d051a1aabf7730d0d940484bc9ac77dde0eff3e Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 25 May 2022 13:08:26 +0700 Subject: [PATCH] Board: Update actions (#1859) Signed-off-by: Anna No --- models/board/src/index.ts | 43 ++++++++++++++----- models/task/src/index.ts | 2 +- packages/ui/src/components/Menu.svelte | 4 +- packages/ui/src/popups.ts | 36 +++++++++++++++- packages/ui/src/types.ts | 16 +++++++ .../src/components/EditCard.svelte | 20 +++++++-- .../src/components/KanbanCard.svelte | 15 +++++-- .../src/components/ListHeader.svelte | 4 +- .../components/editor/CardChecklist.svelte | 4 +- .../board-resources/src/utils/PopupUtils.ts | 28 ------------ plugins/board/src/index.ts | 1 + plugins/view-resources/src/actionImpl.ts | 40 ++++++++++++++--- .../view-resources/src/components/Menu.svelte | 5 ++- plugins/view-resources/src/index.ts | 8 ++++ plugins/view/src/index.ts | 8 +++- 15 files changed, 172 insertions(+), 62 deletions(-) delete mode 100644 plugins/board-resources/src/utils/PopupUtils.ts diff --git a/models/board/src/index.ts b/models/board/src/index.ts index 15bc8b84a8..cca9e9217f 100644 --- a/models/board/src/index.ts +++ b/models/board/src/index.ts @@ -280,17 +280,34 @@ export function createModel (builder: Builder): void { ) // card actions + createAction( + builder, + { + action: view.actionImpl.ShowPanel, + actionProps: { + component: board.component.EditCard + }, + label: view.string.Open, + icon: board.icon.Card, + input: 'any', + category: board.category.Card, + target: board.class.Card, + context: { mode: 'context', application: board.app.Board, group: 'top' } + }, + board.action.Open + ) createAction( builder, { action: view.actionImpl.ShowPopup, actionProps: { component: board.component.LabelsActionPopup, - element: 'top' + element: view.popup.PositionElementAlignment }, label: board.string.Labels, icon: board.icon.Card, input: 'any', + inline: true, category: board.category.Card, target: board.class.Card, context: { mode: 'context', application: board.app.Board, group: 'top' } @@ -303,11 +320,12 @@ export function createModel (builder: Builder): void { action: view.actionImpl.ShowPopup, actionProps: { component: board.component.DatesActionPopup, - element: 'top' + element: view.popup.PositionElementAlignment }, label: board.string.Dates, icon: board.icon.Card, input: 'any', + inline: true, category: board.category.Card, target: board.class.Card, context: { mode: 'context', application: board.app.Board, group: 'top' } @@ -320,12 +338,13 @@ export function createModel (builder: Builder): void { action: view.actionImpl.ShowPopup, actionProps: { component: board.component.CoverActionPopup, - element: 'top', + element: view.popup.PositionElementAlignment, value: 'object' }, label: board.string.Cover, icon: board.icon.Card, input: 'any', + inline: true, category: board.category.Card, target: board.class.Card, context: { mode: 'context', application: board.app.Board, group: 'top' } @@ -339,12 +358,13 @@ export function createModel (builder: Builder): void { action: view.actionImpl.ShowPopup, actionProps: { component: board.component.MoveActionPopup, - element: 'top' + element: view.popup.PositionElementAlignment }, input: 'any', + inline: true, category: board.category.Card, target: board.class.Card, - context: { mode: 'context', application: board.app.Board, group: 'tools' } + context: { mode: ['context', 'editor'], application: board.app.Board, group: 'tools' } }, board.action.Move ) @@ -354,14 +374,15 @@ export function createModel (builder: Builder): void { action: view.actionImpl.ShowPopup, actionProps: { component: board.component.CopyActionPopup, - element: 'top' + element: view.popup.PositionElementAlignment }, label: board.string.Copy, icon: board.icon.Card, input: 'any', + inline: true, category: board.category.Card, target: board.class.Card, - context: { mode: 'context', application: board.app.Board, group: 'tools' } + context: { mode: ['context', 'editor'], application: board.app.Board, group: 'tools' } }, board.action.Copy ) @@ -381,11 +402,11 @@ export function createModel (builder: Builder): void { isArchived: { $nin: [true] } }, label: board.string.Archive, - icon: board.icon.Card, + icon: view.icon.Archive, input: 'any', category: board.category.Card, target: board.class.Card, - context: { mode: 'context', application: board.app.Board, group: 'tools' } + context: { mode: ['context', 'editor'], application: board.app.Board, group: 'tools' } }, board.action.Archive ) @@ -405,7 +426,7 @@ export function createModel (builder: Builder): void { input: 'any', category: board.category.Card, target: board.class.Card, - context: { mode: 'context', application: board.app.Board, group: 'tools' } + context: { mode: ['context', 'editor'], application: board.app.Board, group: 'tools' } }, board.action.SendToBoard ) @@ -423,7 +444,7 @@ export function createModel (builder: Builder): void { category: board.category.Card, input: 'any', target: board.class.Card, - context: { mode: 'context', application: board.app.Board, group: 'tools' } + context: { mode: ['context', 'editor'], application: board.app.Board, group: 'tools' } }, board.action.Delete ) diff --git a/models/task/src/index.ts b/models/task/src/index.ts index c75cd66851..f294d96145 100644 --- a/models/task/src/index.ts +++ b/models/task/src/index.ts @@ -532,7 +532,7 @@ export function createModel (builder: Builder): void { isArchived: { $nin: [true] } }, label: task.string.Archive, - icon: task.icon.TaskState, + icon: view.icon.Archive, input: 'any', category: task.category.Task, target: task.class.State, diff --git a/packages/ui/src/components/Menu.svelte b/packages/ui/src/components/Menu.svelte index 63f4ae645e..afcd3ef4bc 100644 --- a/packages/ui/src/components/Menu.svelte +++ b/packages/ui/src/components/Menu.svelte @@ -68,7 +68,9 @@ evt.currentTarget.focus() }} on:click={(evt) => { - dispatch('close') + if (!action.inline) { + dispatch('close') + } action.action(ctx, evt) }} > diff --git a/packages/ui/src/popups.ts b/packages/ui/src/popups.ts index 3c1841d369..c2a0187aa2 100644 --- a/packages/ui/src/popups.ts +++ b/packages/ui/src/popups.ts @@ -1,4 +1,12 @@ -import type { AnySvelteComponent, AnyComponent, PopupAlignment, PopupPositionElement, PopupOptions } from './types' +import type { + AnySvelteComponent, + AnyComponent, + HorizontalAlignment, + PopupAlignment, + PopupPositionElement, + PopupOptions, + VerticalAlignment +} from './types' import { getResource } from '@anticrm/platform' import { writable } from 'svelte/store' @@ -262,3 +270,29 @@ export function fitPopupElement ( export function eventToHTMLElement (evt: MouseEvent): HTMLElement { return evt.target as HTMLElement } + +export function getEventPopupPositionElement ( + e?: Event, + position?: { v: VerticalAlignment, h: HorizontalAlignment } +): PopupAlignment | undefined { + if (e == null || e.target == null) { + return undefined + } + const target = e.target as HTMLElement + return getPopupPositionElement(target, position) +} + +export function getPopupPositionElement ( + el: HTMLElement | undefined, + position?: { v: VerticalAlignment, h: HorizontalAlignment } +): PopupAlignment | undefined { + if (el?.getBoundingClientRect != null) { + const result = el.getBoundingClientRect() + return { + getBoundingClientRect: () => result, + position + } + } + + return undefined +} diff --git a/packages/ui/src/types.ts b/packages/ui/src/types.ts index f232e30121..750a6cb0ae 100644 --- a/packages/ui/src/types.ts +++ b/packages/ui/src/types.ts @@ -43,6 +43,7 @@ export interface Action { label: IntlString icon: Asset | AnySvelteComponent action: (props: any, ev: Event) => Promise + inline?: boolean } export interface IPopupItem { @@ -74,7 +75,22 @@ export interface PopupPositionElement { h: HorizontalAlignment } } + export type PopupPosAlignment = 'right' | 'top' | 'float' | 'account' | 'full' | 'content' | 'middle' + +export function isPopupPosAlignment (x: any): x is PopupPosAlignment { + return ( + typeof x === 'string' && + (x === 'right' || + x === 'top' || + x === 'float' || + x === 'account' || + x === 'full' || + x === 'content' || + x === 'middle') + ) +} + export type PopupAlignment = PopupPosAlignment | PopupPositionElement | null export type TooltipAlignment = 'top' | 'bottom' | 'left' | 'right' diff --git a/plugins/board-resources/src/components/EditCard.svelte b/plugins/board-resources/src/components/EditCard.svelte index e97772128c..4e2c9237fe 100644 --- a/plugins/board-resources/src/components/EditCard.svelte +++ b/plugins/board-resources/src/components/EditCard.svelte @@ -22,13 +22,21 @@ import type { State, TodoItem } from '@anticrm/task' import task from '@anticrm/task' import { StyledTextBox } from '@anticrm/text-editor' - import { Button, CircleButton, EditBox, IconAdd, IconMoreH, Label, showPopup } from '@anticrm/ui' + import { + Button, + CircleButton, + EditBox, + getEventPopupPositionElement, + IconAdd, + IconMoreH, + Label, + showPopup + } from '@anticrm/ui' import { ContextMenu, DocAttributeBar, invokeAction, UpDownNavigator } from '@anticrm/view-resources' import { createEventDispatcher, onMount } from 'svelte' import board from '../plugin' import { getCardActions } from '../utils/CardActionUtils' import { updateCard } from '../utils/CardUtils' - import { getPopupAlignment } from '../utils/PopupUtils' import CardActions from './editor/CardActions.svelte' import CardChecklist from './editor/CardChecklist.svelte' import AddChecklist from './popups/AddChecklist.svelte' @@ -57,7 +65,7 @@ } function addChecklist (e: Event) { - showPopup(AddChecklist, { value: object }, getPopupAlignment(e)) + showPopup(AddChecklist, { value: object }, getEventPopupPositionElement(e)) } $: cardQuery.query(_class, { _id }, (result) => { @@ -124,7 +132,11 @@ kind="transparent" size="medium" on:click={(e) => { - showPopup(ContextMenu, { object }, getPopupAlignment(e)) + showPopup( + ContextMenu, + { object, baseMenuClass: board.class.Card, mode: 'editor' }, + getEventPopupPositionElement(e) + ) }} /> diff --git a/plugins/board-resources/src/components/KanbanCard.svelte b/plugins/board-resources/src/components/KanbanCard.svelte index 721f79e469..e6f76045a8 100644 --- a/plugins/board-resources/src/components/KanbanCard.svelte +++ b/plugins/board-resources/src/components/KanbanCard.svelte @@ -22,13 +22,22 @@ import notification from '@anticrm/notification' import view from '@anticrm/view' import { getClient, UserBoxList } from '@anticrm/presentation' - import { Button, Component, EditBox, Icon, IconEdit, Label, numberToHexColor, showPopup } from '@anticrm/ui' + import { + Button, + Component, + EditBox, + getPopupPositionElement, + Icon, + IconEdit, + Label, + numberToHexColor, + showPopup + } from '@anticrm/ui' import { ContextMenu } from '@anticrm/view-resources' import board from '../plugin' import CardLabels from './editor/CardLabels.svelte' import DatePresenter from './presenters/DatePresenter.svelte' import { hasDate, openCardPanel, updateCard, updateCardMembers } from '../utils/CardUtils' - import { getElementPopupAlignment } from '../utils/PopupUtils' import CheckListsPresenter from './presenters/ChecklistsPresenter.svelte' import NotificationPresenter from './presenters/NotificationPresenter.svelte' @@ -47,7 +56,7 @@ function enterEditMode (): void { isEditMode = true - showPopup(ContextMenu, { object }, getElementPopupAlignment(ref, { h: 'right', v: 'top' }), exitEditMode) + showPopup(ContextMenu, { object }, getPopupPositionElement(ref, { h: 'right', v: 'top' }), exitEditMode) } function showCard () { diff --git a/plugins/board-resources/src/components/ListHeader.svelte b/plugins/board-resources/src/components/ListHeader.svelte index 6d3176ae59..031b2b78da 100644 --- a/plugins/board-resources/src/components/ListHeader.svelte +++ b/plugins/board-resources/src/components/ListHeader.svelte @@ -1,5 +1,5 @@