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

UBER-417: replace AddSavedView with select popup, allow renaming #3423

Merged
merged 1 commit into from
Jun 12, 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
1 change: 1 addition & 0 deletions plugins/view-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"AddSavedView": "Add saved view",
"Public": "Public",
"Hide": "Hide",
"Rename": "Rename",
"SaveAs": "Save as",
"And": "and",
"Between": "is between",
Expand Down
1 change: 1 addition & 0 deletions plugins/view-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"BetweenDates": "Между датами",
"Public": "Публичный",
"Hide": "Спрятать",
"Rename": "Переименовать",
"SaveAs": "Сохранить как",
"And": "и",
"Between": "между",
Expand Down
75 changes: 0 additions & 75 deletions plugins/view-resources/src/components/filter/AddSavedView.svelte

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
export let selected = false
export let bold = false
export let shortDropbox = false
export let actions: () => Promise<Action[]> = async () => []
export let actions: (originalEvent?: MouseEvent) => Promise<Action[]> = async () => []
export let indent: 'default' | 'ml-2' | 'ml-4' | 'ml-8' = 'default'

let hovered = false
async function onMenuClick (ev: MouseEvent) {
showPopup(Menu, { actions: await actions(), ctx: _id }, ev.target as HTMLElement, () => {
showPopup(Menu, { actions: await actions(ev), ctx: _id }, ev.target as HTMLElement, () => {
hovered = false
})
hovered = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
export let icon: Asset | undefined = undefined
export let title: string
export let notifications = 0
export let actions: () => Promise<Action[]> = async () => []
export let actions: (originalEvent?: MouseEvent) => Promise<Action[]> = async () => []
export let selected: boolean = false
export let bold = false
export let indent: 'default' | 'ml-2' | 'ml-4' | 'ml-8' = 'default'
Expand Down
1 change: 0 additions & 1 deletion plugins/view-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ import { AggregationMiddleware } from './middleware'
import { grouppingStatusManager, StatusAggregationManager } from './status'
export { getActions, invokeAction } from './actions'
export { default as ActionHandler } from './components/ActionHandler.svelte'
export { default as AddSavedView } from './components/filter/AddSavedView.svelte'
export { default as FilterButton } from './components/filter/FilterButton.svelte'
export { default as FixedColumn } from './components/FixedColumn.svelte'
export { default as SourcePresenter } from './components/inference/SourcePresenter.svelte'
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 @@ -824,6 +824,7 @@ const view = plugin(viewId, {
Timeline: '' as IntlString,
Public: '' as IntlString,
Hide: '' as IntlString,
Rename: '' as IntlString,
Assigned: '' as IntlString,
Open: '' as IntlString,
Created: '' as IntlString,
Expand Down
62 changes: 54 additions & 8 deletions plugins/workbench-resources/src/components/SavedView.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<script lang="ts">
import { Ref, getCurrentAccount } from '@hcengineering/core'
import { Ref, getCurrentAccount, toIdMap } from '@hcengineering/core'
import { createQuery, getClient } from '@hcengineering/presentation'
import setting from '@hcengineering/setting'
import { Action, IconAdd, Location, eventToHTMLElement, location, navigate, showPopup } from '@hcengineering/ui'
import {
Action,
IconAdd,
Location,
eventToHTMLElement,
location,
navigate,
showPopup,
SelectPopup,
getEventPopupPositionElement
} from '@hcengineering/ui'
import view, { Filter, FilteredView, ViewOptions, Viewlet } from '@hcengineering/view'
import {
AddSavedView,
TreeItem,
TreeNode,
activeViewlet,
Expand All @@ -16,11 +25,13 @@
setActiveViewletId,
setFilters,
setViewOptions,
viewOptionStore
viewOptionStore,
EditBoxPopup
} from '@hcengineering/view-resources'
import { Application } from '@hcengineering/workbench'
import copy from 'fast-copy'
import { createEventDispatcher } from 'svelte'
import contact from '@hcengineering/contact'

export let currentApplication: Application | undefined

Expand Down Expand Up @@ -48,8 +59,33 @@
]
}

async function viewAction (filteredView: FilteredView): Promise<Action[]> {
if (filteredView.createdBy === me) return await removeAction(filteredView)
async function renameAction (object: FilteredView, originalEvent: MouseEvent | undefined): Promise<Action[]> {
return [
{
icon: contact.icon.Edit,
label: view.string.Rename,
action: async (ctx: any, evt: Event) => {
showPopup(
EditBoxPopup,
{ value: object.name, format: 'text' },
getEventPopupPositionElement(originalEvent ?? evt),
async (res) => {
if (res !== undefined) {
await client.update(object, { name: res })
}
}
)
}
}
]
}

async function viewAction (filteredView: FilteredView, originalEvent: MouseEvent | undefined): Promise<Action[]> {
const rename = await renameAction(filteredView, originalEvent)
if (filteredView.createdBy === me) {
const remove = await removeAction(filteredView)
return [...remove, ...rename]
}
return await hideAction(filteredView)
}

Expand Down Expand Up @@ -142,11 +178,21 @@

async function getActions (availableFilteredViews: FilteredView[]): Promise<Action[]> {
if (availableFilteredViews.length > 0) {
const filteredViewsIdMap = toIdMap(availableFilteredViews)
const pushMeToFV = async (id: Ref<FilteredView>) => {
if (id === undefined) return
const filteredView = filteredViewsIdMap.get(id)
if (filteredView) await client.update(filteredView, { $push: { users: me } })
}
const value = availableFilteredViews.map((p) => ({
id: p._id,
text: p.name
}))
const add: Action = {
label: view.string.AddSavedView,
icon: IconAdd,
action: async (_, e): Promise<void> => {
showPopup(AddSavedView, { attachedTo: currentApplication?.alias }, eventToHTMLElement(e as MouseEvent))
showPopup(SelectPopup, { value, searchable: true }, eventToHTMLElement(e as MouseEvent), pushMeToFV)
}
}
return [add]
Expand All @@ -164,7 +210,7 @@
title={fv.name}
selected={selectedId === fv._id}
on:click={() => load(fv)}
actions={() => viewAction(fv)}
actions={(ov) => viewAction(fv, ov)}
/>
{/each}
</TreeNode>
Expand Down