Files
huly-platform/plugins/board-resources/src/components/selectors/StateSelect.svelte
T
2022-04-26 15:50:46 +07:00

36 lines
1.2 KiB
Svelte

<script lang="ts">
import { IntlString, translate } from '@anticrm/platform'
import { createQuery } from '@anticrm/presentation'
import { DropdownLabels } from '@anticrm/ui'
import { Ref, SortingOrder, Space } from '@anticrm/core'
import { DropdownTextItem } from '@anticrm/ui/src/types'
import task, { State } from '@anticrm/task'
import { Card } from '@anticrm/board'
import board from '../../plugin'
export let object: Card
export let label: IntlString
export let selected: Ref<State>
export let space: Ref<Space>
let states: DropdownTextItem[] = []
const statesQuery = createQuery()
statesQuery.query(
task.class.State,
{ space, isArchived: { $nin: [true] } },
async (result) => {
if (!result) return
states = result.map(({ _id, title }) => ({ id: _id, label: title }))
;[{ _id: selected }] = result
if (object.space === space) {
const index = states.findIndex(({ id }) => id === object.state)
states[index].label = await translate(board.string.Current, { label: states[index].label })
selected = object.state
}
},
{ sort: { rank: SortingOrder.Ascending } }
)
</script>
<DropdownLabels items={states} {label} bind:selected />