2022-05-04 15:08:24 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 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">
|
2022-09-21 08:08:25 +00:00
|
|
|
import { AttachedData } from '@hcengineering/core'
|
|
|
|
import { getClient } from '@hcengineering/presentation'
|
2023-03-24 10:23:44 +00:00
|
|
|
import { Issue, IssueDraft, IssuePriority, IssueTemplateData } from '@hcengineering/tracker'
|
2022-10-05 06:41:02 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ButtonKind,
|
|
|
|
ButtonSize,
|
|
|
|
eventToHTMLElement,
|
|
|
|
Icon,
|
|
|
|
Label,
|
|
|
|
SelectPopup,
|
|
|
|
showPopup
|
|
|
|
} from '@hcengineering/ui'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-05-04 15:08:24 +00:00
|
|
|
import tracker from '../../plugin'
|
2022-06-17 08:28:31 +00:00
|
|
|
import { defaultPriorities, issuePriorities } from '../../utils'
|
2022-05-04 15:08:24 +00:00
|
|
|
|
2023-03-24 10:23:44 +00:00
|
|
|
export let value: Issue | AttachedData<Issue> | IssueTemplateData | IssueDraft
|
2022-05-04 15:08:24 +00:00
|
|
|
export let isEditable: boolean = true
|
|
|
|
export let shouldShowLabel: boolean = false
|
|
|
|
|
2022-05-09 11:37:34 +00:00
|
|
|
export let kind: ButtonKind = 'link'
|
|
|
|
export let size: ButtonSize = 'large'
|
|
|
|
export let justify: 'left' | 'center' = 'left'
|
2022-06-17 08:28:31 +00:00
|
|
|
export let width: string | undefined = undefined
|
2023-04-27 11:35:25 +00:00
|
|
|
export let focusIndex: number | undefined = undefined
|
2022-05-09 11:37:34 +00:00
|
|
|
|
2022-05-04 15:08:24 +00:00
|
|
|
const client = getClient()
|
2022-06-15 03:01:21 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
2022-06-17 08:28:31 +00:00
|
|
|
const prioritiesInfo = defaultPriorities.map((p) => ({ id: p, ...issuePriorities[p] }))
|
2022-05-04 15:08:24 +00:00
|
|
|
|
2022-06-17 08:28:31 +00:00
|
|
|
const handlePriorityEditorOpened = (event: MouseEvent) => {
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
if (!isEditable) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
showPopup(
|
|
|
|
SelectPopup,
|
|
|
|
{ value: prioritiesInfo, placeholder: tracker.string.SetPriority, searchable: true },
|
|
|
|
eventToHTMLElement(event),
|
|
|
|
changePriority
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const changePriority = async (newPriority: IssuePriority | undefined) => {
|
2022-05-16 10:38:51 +00:00
|
|
|
if (!isEditable || newPriority === undefined || value.priority === newPriority) {
|
2022-05-04 15:08:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-15 03:01:21 +00:00
|
|
|
dispatch('change', newPriority)
|
|
|
|
|
2023-03-24 10:23:44 +00:00
|
|
|
if ('_class' in value) {
|
2022-06-15 03:01:21 +00:00
|
|
|
await client.update(value, { priority: newPriority })
|
|
|
|
}
|
2022-05-04 15:08:24 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if value}
|
2022-08-25 03:11:10 +00:00
|
|
|
{#if kind === 'list' || kind === 'list-header'}
|
2023-01-18 05:14:59 +00:00
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
2022-06-20 14:11:14 +00:00
|
|
|
<div class="priority-container" on:click={handlePriorityEditorOpened}>
|
|
|
|
<div class="icon">
|
2022-06-24 12:36:08 +00:00
|
|
|
{#if issuePriorities[value.priority]?.icon}<Icon icon={issuePriorities[value.priority]?.icon} {size} />{/if}
|
2022-06-20 14:11:14 +00:00
|
|
|
</div>
|
|
|
|
{#if shouldShowLabel}
|
2022-08-25 03:11:10 +00:00
|
|
|
<span
|
2023-05-05 05:21:40 +00:00
|
|
|
class="{kind === 'list' ? 'ml-2 text-md' : 'ml-3 text-base'} overflow-label disabled fs-bold content-color"
|
2022-08-25 03:11:10 +00:00
|
|
|
>
|
2022-06-24 12:36:08 +00:00
|
|
|
<Label label={issuePriorities[value.priority]?.label} />
|
2022-06-20 14:11:14 +00:00
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<Button
|
|
|
|
showTooltip={isEditable ? { label: tracker.string.SetPriority } : undefined}
|
2022-06-24 12:36:08 +00:00
|
|
|
label={shouldShowLabel ? issuePriorities[value.priority]?.label : undefined}
|
|
|
|
icon={issuePriorities[value.priority]?.icon}
|
2022-06-20 14:11:14 +00:00
|
|
|
{justify}
|
2023-04-27 11:35:25 +00:00
|
|
|
{focusIndex}
|
2022-06-20 14:11:14 +00:00
|
|
|
{width}
|
|
|
|
{size}
|
|
|
|
{kind}
|
|
|
|
disabled={!isEditable}
|
|
|
|
on:click={handlePriorityEditorOpened}
|
|
|
|
/>
|
|
|
|
{/if}
|
2022-05-04 15:08:24 +00:00
|
|
|
{/if}
|
2022-06-20 14:11:14 +00:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.priority-container {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-shrink: 0;
|
|
|
|
min-width: 0;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
flex-shrink: 0;
|
|
|
|
width: 1rem;
|
|
|
|
height: 1rem;
|
2023-04-23 17:37:24 +00:00
|
|
|
color: var(--theme-caption-color);
|
2022-06-20 14:11:14 +00:00
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.icon {
|
2023-04-23 17:37:24 +00:00
|
|
|
color: var(--theme-caption-color) !important;
|
2022-06-20 14:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|