|
105 | 105 | header |
106 | 106 | /> |
107 | 107 | <!-- DROPDOWN MENU FOR SELECT SOURCE --> |
108 | | - <!-- TODO(Wendy) - currently we hide this menu if the prop is set manually since you can't select another option yet --> |
109 | 108 | <template |
110 | 109 | v-if=" |
111 | | - propSource !== 'manually' && |
112 | | - attributeDef.value?.ancestorManual && |
| 110 | + validAttributeValueSources.length > 1 && |
113 | 111 | featureFlagsStore.INDICATORS_MANUAL_FUNCTION_SOCKET |
114 | 112 | " |
115 | 113 | > |
|
125 | 123 | <Icon name="chevron--down" size="sm" /> |
126 | 124 | </div> |
127 | 125 | </div> |
| 126 | + |
128 | 127 | <DropdownMenu ref="sourceSelectMenuRef"> |
129 | | - <!-- TODO(Wendy) - Currently you can't switch to anything but manually --> |
130 | | - <template v-for="source in sourceKinds" :key="source"> |
| 128 | + <template |
| 129 | + v-for="source in validAttributeValueSources" |
| 130 | + :key="source" |
| 131 | + > |
131 | 132 | <DropdownMenuItem |
132 | | - v-if="source === 'manually' || propSource === source" |
133 | 133 | :checked="propSource === source" |
134 | 134 | :label="source" |
135 | 135 | @click="setSource(source)" |
|
330 | 330 | <template v-else-if="widgetKind === 'text'"> |
331 | 331 | <input |
332 | 332 | v-model="newValueString" |
333 | | - spellcheck="false" |
334 | 333 | :class="`${propLabelParts[0]}${propLabelParts[1]}`" |
| 334 | + spellcheck="false" |
335 | 335 | type="text" |
336 | 336 | @blur="onBlur" |
337 | 337 | @focus="onFocus" |
@@ -614,9 +614,6 @@ import SecretsModal from "../SecretsModal.vue"; |
614 | 614 | import SourceIconWithTooltip from "./SourceIconWithTooltip.vue"; |
615 | 615 | import CodeViewer from "../CodeViewer.vue"; |
616 | 616 |
|
617 | | -const sourceKinds = ["manually", "via socket", "via attribute func"] as const; |
618 | | -export type SourceKind = (typeof sourceKinds)[number]; |
619 | | -
|
620 | 617 | const props = defineProps({ |
621 | 618 | parentPath: { type: String }, |
622 | 619 | attributeDef: { type: Object as PropType<AttributeTreeItem>, required: true }, |
@@ -767,12 +764,60 @@ const propManual = computed( |
767 | 764 | propSetByDynamicFunc.value |
768 | 765 | ), |
769 | 766 | ); |
770 | | -const propSource = computed<SourceKind>(() => { |
771 | | - if (propHasSocket.value || propPopulatedBySocket.value) return "via socket"; |
772 | | - else if (propSetByDynamicFunc.value) return "via attribute func"; |
773 | | - else return "manually"; |
| 767 | +
|
| 768 | +enum AttributeValueSource { |
| 769 | + Manual = "manually", |
| 770 | + Socket = "via socket", |
| 771 | + NonSocketAttributeFunc = "via attribute func", |
| 772 | +} |
| 773 | +
|
| 774 | +const validAttributeValueSources = computed(() => { |
| 775 | + const sources = []; |
| 776 | +
|
| 777 | + // TODO(victor): Get if default function is dynamic from the api to show NonSocketAttributeFunc option on the dropdown |
| 778 | +
|
| 779 | + if (props.attributeDef.propDef.defaultCanBeSetBySocket) { |
| 780 | + sources.push(AttributeValueSource.Socket); |
| 781 | + } |
| 782 | +
|
| 783 | + if (props.attributeDef.value?.isControlledByAncestor === false) { |
| 784 | + sources.push(AttributeValueSource.Manual); |
| 785 | + } |
| 786 | + if (!sources.includes(propSource.value)) { |
| 787 | + sources.push(propSource.value); |
| 788 | + } |
| 789 | +
|
| 790 | + return sources; |
| 791 | +}); |
| 792 | +
|
| 793 | +const propSource = computed<AttributeValueSource>(() => { |
| 794 | + if (propHasSocket.value || propPopulatedBySocket.value) |
| 795 | + return AttributeValueSource.Socket; |
| 796 | + else if (propSetByDynamicFunc.value) |
| 797 | + return AttributeValueSource.NonSocketAttributeFunc; |
| 798 | + else return AttributeValueSource.Manual; |
774 | 799 | }); |
775 | 800 |
|
| 801 | +const setSource = (source: AttributeValueSource) => { |
| 802 | + if (source === AttributeValueSource.Manual) { |
| 803 | + const value = props.attributeDef.value?.value ?? null; |
| 804 | +
|
| 805 | + attributesStore.UPDATE_PROPERTY_VALUE({ |
| 806 | + update: { |
| 807 | + attributeValueId: props.attributeDef.valueId, |
| 808 | + parentAttributeValueId: props.attributeDef.parentValueId, |
| 809 | + propId: props.attributeDef.propId, |
| 810 | + componentId, |
| 811 | + value, |
| 812 | + }, |
| 813 | + }); |
| 814 | + } else { |
| 815 | + attributesStore.RESET_PROPERTY_VALUE({ |
| 816 | + attributeValueId: props.attributeDef.valueId, |
| 817 | + }); |
| 818 | + } |
| 819 | +}; |
| 820 | +
|
776 | 821 | const sourceIcon = computed(() => { |
777 | 822 | if (propPopulatedBySocket.value) return "circle-full"; |
778 | 823 | else if (propSetByDynamicFunc.value) return "func"; |
@@ -997,28 +1042,6 @@ const confirmEdit = () => { |
997 | 1042 | const editOverride = ref(false); |
998 | 1043 |
|
999 | 1044 | const sourceSelectMenuRef = ref<InstanceType<typeof DropdownMenu>>(); |
1000 | | -
|
1001 | | -const setSource = (source: SourceKind) => { |
1002 | | - if (source === "manually") { |
1003 | | - const value = props.attributeDef.value?.value ?? null; |
1004 | | -
|
1005 | | - // console.log(value); |
1006 | | -
|
1007 | | - attributesStore.UPDATE_PROPERTY_VALUE({ |
1008 | | - update: { |
1009 | | - attributeValueId: props.attributeDef.valueId, |
1010 | | - parentAttributeValueId: props.attributeDef.parentValueId, |
1011 | | - propId: props.attributeDef.propId, |
1012 | | - componentId, |
1013 | | - value, |
1014 | | - }, |
1015 | | - }); |
1016 | | - } else if (source === "via socket") { |
1017 | | - // TODO(Wendy) - Here's where we can put logic for selecting a socket to connect to this prop |
1018 | | - } else { |
1019 | | - // TODO(Wendy) - Here's where we can put logic for selecting an attribute function to populate this prop |
1020 | | - } |
1021 | | -}; |
1022 | 1045 | </script> |
1023 | 1046 |
|
1024 | 1047 | <style lang="less"> |
|
0 commit comments