-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(task-field): add OtherTaskField interface and update validation …
…logic Signed-off-by: Wanjin Noh <[email protected]>
- Loading branch information
Showing
8 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 63 additions & 1 deletion
64
apps/web/src/services/ops-flow/task-fields-form/field-templates/DropdownTaskField.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,69 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import { | ||
PFieldGroup, PSelectDropdown, getTextHighlightRegex, | ||
} from '@cloudforet/mirinae'; | ||
import type { AutocompleteHandler, SelectDropdownMenuItem } from '@cloudforet/mirinae/types/controls/dropdown/select-dropdown/type'; | ||
import type { DropdownTaskField } from '@/schema/opsflow/_types/task-field-type'; | ||
import { useTaskFieldValidation } from '@/services/ops-flow/task-fields-form/composables/use-task-field-validation'; | ||
import type { TaskFieldFormProps } from '@/services/ops-flow/task-fields-form/types/task-field-form-type'; | ||
const props = defineProps<TaskFieldFormProps<DropdownTaskField, string[]>>(); | ||
const emit = defineEmits<{(event: 'update:value', value: string[]): void; | ||
}>(); | ||
const { | ||
value, setValue, | ||
isInvalid, invalidText, | ||
} = useTaskFieldValidation<DropdownTaskField, string[]>(props); | ||
interface DropdownItem extends SelectDropdownMenuItem { | ||
label: string; | ||
} | ||
const allItems = computed<DropdownItem[]>(() => { | ||
if (!props.field.options?.enums) return []; | ||
return props.field.options.enums.map((item) => ({ | ||
name: item.key, | ||
label: item.name, | ||
})); | ||
}); | ||
const selectedItems = computed<DropdownItem[]>(() => value.value.map((item) => ({ | ||
name: item, | ||
label: allItems.value.find((i) => i.name === item)?.label ?? item, | ||
}))); | ||
const dropdownItemsHandler: AutocompleteHandler = async (keyword: string, pageStart = 1, pageLimit = 10) => { | ||
const filteredItems = allItems.value.filter((item) => getTextHighlightRegex(keyword).test(item.label)); | ||
const _totalCount = pageStart - 1 + Number(pageLimit); | ||
const _slicedResults = filteredItems.slice(pageStart - 1, _totalCount); | ||
return { | ||
results: _slicedResults, | ||
more: _totalCount < filteredItems.length, | ||
}; | ||
}; | ||
const handleUpdate = (val: DropdownItem[]) => { | ||
setValue(val.map((item) => item.name)); | ||
emit('update:value', val.map((item) => item.name)); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div>DropdownTaskFieldForm</div> | ||
<p-field-group :label="field.name" | ||
:required="field.is_required" | ||
:invalid="isInvalid" | ||
:invalid-text="invalidText" | ||
> | ||
<p-select-dropdown show-select-marker | ||
:selected="selectedItems" | ||
:handler="dropdownItemsHandler" | ||
is-filterable | ||
show-delete-all-button | ||
@update:selected="handleUpdate" | ||
/> | ||
</p-field-group> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters