Add translate message action (#6609)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-09-19 22:35:18 +07:00
committed by GitHub
parent c0448a373f
commit 8d9cebdd67
62 changed files with 926 additions and 130 deletions
@@ -19,12 +19,14 @@
import { getClient } from '@hcengineering/presentation'
import { getResource } from '@hcengineering/platform'
import view, { Action as ViewAction } from '@hcengineering/view'
import { Ref } from '@hcengineering/core'
import ActivityMessageAction from './ActivityMessageAction.svelte'
import { savedMessagesStore } from '../activity'
export let message: ActivityMessage | undefined
export let actions: Action[] = []
export let excludedActions: Ref<ViewAction>[] = []
export let withActionMenu = true
export let onOpen: () => void
export let onClose: () => void
@@ -34,7 +36,7 @@
let inlineActions: ViewAction[] = []
let isActionMenuOpened = false
$: void updateInlineActions(message)
$: void updateInlineActions(message, excludedActions)
savedMessagesStore.subscribe(() => {
void updateInlineActions(message)
@@ -51,15 +53,13 @@
}
function showMenu (ev: MouseEvent): void {
const excludedActions = inlineActions.map(({ _id }) => _id)
showPopup(
Menu,
{
object: message,
actions,
baseMenuClass: activity.class.ActivityMessage,
excludedActions
excludedActions: inlineActions.map(({ _id }) => _id).concat(excludedActions)
},
ev.target as HTMLElement,
handleActionMenuClosed
@@ -67,14 +67,14 @@
handleActionMenuOpened()
}
async function updateInlineActions (message?: ActivityMessage): Promise<void> {
async function updateInlineActions (message?: ActivityMessage, excludedAction: Ref<ViewAction>[] = []): Promise<void> {
if (message === undefined) {
inlineActions = []
return
}
inlineActions = (await getActions(client, message, activity.class.ActivityMessage)).filter(
(action) => action.inline
)
inlineActions = (await getActions(client, message, activity.class.ActivityMessage))
.filter((action) => action.inline)
.filter((action) => !excludedAction.includes(action._id))
}
</script>
@@ -20,11 +20,12 @@
} from '@hcengineering/activity'
import { Person } from '@hcengineering/contact'
import { Avatar, EmployeePresenter, SystemAvatar } from '@hcengineering/contact-resources'
import core from '@hcengineering/core'
import core, { Ref } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import { Action, Icon, Label } from '@hcengineering/ui'
import { getActions, restrictionStore, showMenu } from '@hcengineering/view-resources'
import { Asset } from '@hcengineering/platform'
import { Action as ViewAction } from '@hcengineering/view'
import ReactionsPresenter from '../reactions/ReactionsPresenter.svelte'
import ActivityMessagePresenter from './ActivityMessagePresenter.svelte'
@@ -33,6 +34,8 @@
import { savedMessagesStore } from '../../activity'
import MessageTimestamp from '../MessageTimestamp.svelte'
import Replies from '../Replies.svelte'
import { MessageInlineAction } from '../../types'
import InlineAction from './InlineAction.svelte'
export let message: DisplayActivityMessage
export let parentMessage: DisplayActivityMessage | undefined = undefined
@@ -55,6 +58,8 @@
export let hoverStyles: 'borderedHover' | 'filledHover' = 'borderedHover'
export let showDatePreposition = false
export let type: ActivityMessageViewType = 'default'
export let inlineActions: MessageInlineAction[] = []
export let excludedActions: Ref<ViewAction>[] = []
export let onClick: (() => void) | undefined = undefined
export let socialIcon: Asset | undefined = undefined
@@ -223,6 +228,14 @@
<span class="text-sm lower">
<MessageTimestamp date={message.createdOn ?? message.modifiedOn} />
</span>
{#if withActions && inlineActions.length > 0 && !readonly}
<div class="flex-presenter flex-gap-2 ml-2">
{#each inlineActions as item}
<InlineAction {item} />
{/each}
</div>
{/if}
</div>
{/if}
@@ -244,6 +257,7 @@
message={isReactionMessage(message) ? parentMessage : message}
{actions}
{withActionMenu}
{excludedActions}
onOpen={handleActionsOpened}
onClose={handleActionsClosed}
/>
@@ -0,0 +1,45 @@
<!--
// Copyright © 2024 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import { Label } from '@hcengineering/ui'
import { MessageInlineAction } from '../../types'
export let item: MessageInlineAction
</script>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="root" class:clickable={item.onClick !== undefined} on:click={item.onClick}>
<Label label={item.label} />
</div>
<style lang="scss">
.root {
display: flex;
align-items: center;
font-size: 0.75rem;
color: var(--global-secondary-TextColor);
cursor: default;
&.clickable {
cursor: pointer;
&:hover {
color: var(--global-primary-TextColor);
}
}
}
</style>
+1
View File
@@ -41,6 +41,7 @@ import {
shouldScrollToActivity
} from './utils'
export * from './types'
export * from './activity'
export * from './utils'
export * from './activityMessagesUtils'
+20
View File
@@ -0,0 +1,20 @@
//
// Copyright © 2024 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { type IntlString } from '@hcengineering/platform'
export interface MessageInlineAction {
label: IntlString
onClick?: () => Promise<void>
}