-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from LordTocs/dev
Beta Build
- Loading branch information
Showing
39 changed files
with
799 additions
and
198 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
2 changes: 1 addition & 1 deletion
2
libs/castmate-ui-core/src/components/automation/DefaultActionComponent.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
68 changes: 68 additions & 0 deletions
68
libs/castmate-ui-core/src/components/data/views/EnumableDataView.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<span class="data-label" v-if="schema.name">{{ schema.name }}: </span>{{ dataView }} | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { SchemaBase, Enumable, EnumItem } from "castmate-schema" | ||
import { SharedDataViewProps } from "../../../main" | ||
import { computed, ref, watch, onMounted } from "vue" | ||
import _isFunction from "lodash/isFunction" | ||
const props = defineProps< | ||
{ | ||
modelValue: any | ||
schema: SchemaBase & Enumable<any> | ||
} & SharedDataViewProps | ||
>() | ||
const fetching = ref(false) | ||
const dynamicItem = ref<EnumItem<any>>() | ||
function findItem(arr: Array<EnumItem<any>>) { | ||
return arr.find((v) => { | ||
if (typeof v == "object" && "value" in v) return v.value == props.modelValue | ||
return v == props.modelValue | ||
}) | ||
} | ||
onMounted(() => { | ||
watch( | ||
() => props.modelValue, | ||
() => { | ||
fetchItem() | ||
}, | ||
{ immediate: true } | ||
) | ||
}) | ||
//TODO: Is there a better way to | ||
async function fetchItem() { | ||
const enumable = props.schema as Enumable<any> | ||
if (!enumable.enum) return | ||
if (!_isFunction(enumable.enum)) { | ||
const item = findItem(enumable.enum) | ||
dynamicItem.value = item | ||
return | ||
} | ||
console.log("Do Fetch ITEM!") | ||
fetching.value = true | ||
try { | ||
const items = await enumable.enum(props.context) | ||
console.log("ITEMS", items, props.context) | ||
const item = findItem(items) | ||
dynamicItem.value = item | ||
return | ||
} catch (err) { | ||
console.error("FETCH ERROR", err) | ||
} | ||
fetching.value = false | ||
} | ||
const dataView = computed(() => { | ||
if (props.schema.enum == null) return props.modelValue | ||
return dynamicItem.value?.name ?? dynamicItem.value ?? props.modelValue | ||
}) | ||
</script> |
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
Oops, something went wrong.