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

Fix enums #8168

Merged
merged 1 commit into from
Mar 7, 2025
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
51 changes: 16 additions & 35 deletions plugins/setting-resources/src/components/EditEnum.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
const dispatch = createEventDispatcher()

let matched = false
let newValue = ''

$: matched = values.includes(newValue.trim())

async function save (): Promise<void> {
Expand All @@ -63,18 +65,20 @@
dispatch('close')
}

function add () {
function add (): void {
newValue = newValue.trim()
if (!newValue.length) return
if (newValue.length === 0) return
if (matched) return
values.push(newValue)
values = values
newValue = ''
}
function remove (value: string) {

function remove (value: string): void {
values = values.filter((p) => p !== value)
}
const handleKeydown = (evt: KeyboardEvent) => {

const handleKeydown = (evt: KeyboardEvent): void => {
if (evt.key === 'Enter') {
add()
}
Expand All @@ -85,7 +89,6 @@
}
}

let newValue = ''
let newItem: boolean = false
let opened: boolean = false
let inputFile: HTMLInputElement
Expand All @@ -105,7 +108,7 @@
processText(text)
}

function fileSelected () {
function fileSelected (): void {
const list = inputFile.files
if (list === null || list.length === 0) return
for (let index = 0; index < list.length; index++) {
Expand All @@ -117,7 +120,7 @@
inputFile.value = ''
}

function fileDrop (e: DragEvent) {
function fileDrop (e: DragEvent): void {
dragover = false
const list = e.dataTransfer?.files
if (list === undefined || list.length === 0) return
Expand Down Expand Up @@ -146,28 +149,6 @@
}

let dragover = false
const selection: number = 0

// $: filtered = newValue.length > 0 ? values.filter((it) => it.includes(newValue)) : values

// function onDelete () {
// showPopup(
// MessageBox,
// {
// label: view.string.DeleteObject,
// message: view.string.DeleteObjectConfirm,
// params: { count: filtered.length }
// },
// 'top',
// (result?: boolean) => {
// if (result === true) {
// values = values.filter((it) => !filtered.includes(it))
// newValue = ''
// }
// }
// )
// }

const items: (DropdownIntlItem & { action: () => void })[] = [
{
id: 'import',
Expand Down Expand Up @@ -197,7 +178,7 @@
}
}

async function showConfirmationDialog (): Promise<void> {
function showConfirmationDialog (): void {
const isEnumEmpty = values.length === 0

if (isEnumEmpty) {
Expand Down Expand Up @@ -237,9 +218,7 @@
okLabel={presentation.string.Save}
okAction={save}
canSave={name.trim().length > 0 && values.length > 0}
onCancel={() => {
showConfirmationDialog()
}}
onCancel={showConfirmationDialog}
>
<div class="flex-col">
<ModernEditbox bind:value={name} label={setting.string.EnumTitle} kind={'ghost'} size={'large'} width={'100%'} />
Expand Down Expand Up @@ -289,7 +268,9 @@
<div class="hulyTableAttr-content options">
<EnumValuesList
bind:values
disableMouseOver={newItem}
on:update={(e) => {
values = e.detail
}}
on:remove={(e) => {
remove(e.detail)
}}
Expand All @@ -307,7 +288,7 @@
on:keydown={handleKeydown}
on:blur={() => {
newValue = newValue.trim()
if (!newValue.length) return
if (newValue.length === 0) return
add()
newItem = false
}}
Expand Down
28 changes: 26 additions & 2 deletions plugins/setting-resources/src/components/EnumValuesList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
IconMoreV,
IconMoreV2,
showPopup,
eventToHTMLElement
eventToHTMLElement,
ModernEditbox
} from '@hcengineering/ui'
import type { DropdownIntlItem } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
Expand Down Expand Up @@ -91,6 +92,19 @@
})
}
}

const handleKeydown = (evt: KeyboardEvent): void => {
if (evt.key === 'Enter') {
update()
}
if (evt.key === 'Escape') {
evt.stopPropagation()
}
}

function update (): void {
dispatch('update', values)
}
</script>

{#each values as item, i}
Expand All @@ -116,7 +130,17 @@
<IconMoreV2 size={'small'} />
</button>
<div class="hulyTableAttr-content__row-label font-regular-14 accent">
{item}
<ModernEditbox
kind={'ghost'}
size={'small'}
label={setting.string.EnterOptionTitle}
on:keydown={handleKeydown}
on:blur={() => {
update()
}}
bind:value={values[i]}
width={'100%'}
/>
</div>
<div class="hulyTableAttr-content__row-label grow" />
{#if !disableMouseOver}
Expand Down
2 changes: 1 addition & 1 deletion plugins/view-resources/src/components/EnumEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{size}
{kind}
width={'100%'}
{allowDeselect}
allowDeselect
disabled={readonly}
autoSelect={false}
on:selected={(e) => {
Expand Down