mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
refactor(editor): Refactor VariableSelector and VariableSelectorItem to composition API (no-changelog) (#10030)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -59,87 +59,89 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { ref, computed, onMounted } from 'vue';
|
||||||
import type { IVariableSelectorOption, IVariableItemSelected } from '@/Interface';
|
import type { IVariableSelectorOption, IVariableItemSelected } from '@/Interface';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = defineProps<{
|
||||||
name: 'VariableSelectorItem',
|
allowParentSelect?: boolean;
|
||||||
props: ['allowParentSelect', 'extendAll', 'item', 'redactValues'],
|
extendAll?: boolean;
|
||||||
data() {
|
item: IVariableSelectorOption;
|
||||||
return {
|
redactValues?: boolean;
|
||||||
extended: false,
|
}>();
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
itemAddOperations() {
|
|
||||||
const returnOptions = [
|
|
||||||
{
|
|
||||||
command: 'raw',
|
|
||||||
displayName: 'Raw value',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
if (this.item.dataType === 'array') {
|
|
||||||
returnOptions.push({
|
|
||||||
command: 'arrayLength',
|
|
||||||
displayName: 'Length',
|
|
||||||
});
|
|
||||||
returnOptions.push({
|
|
||||||
command: 'arrayValues',
|
|
||||||
displayName: 'Values',
|
|
||||||
});
|
|
||||||
} else if (this.item.dataType === 'object') {
|
|
||||||
returnOptions.push({
|
|
||||||
command: 'objectKeys',
|
|
||||||
displayName: 'Keys',
|
|
||||||
});
|
|
||||||
returnOptions.push({
|
|
||||||
command: 'objectValues',
|
|
||||||
displayName: 'Values',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnOptions;
|
const emit = defineEmits<{
|
||||||
},
|
itemSelected: [value: IVariableItemSelected];
|
||||||
},
|
}>();
|
||||||
mounted() {
|
|
||||||
if (this.extended) return;
|
|
||||||
|
|
||||||
const shouldAutoExtend =
|
const extended = ref(false);
|
||||||
[
|
|
||||||
this.$locale.baseText('variableSelectorItem.currentNode'),
|
|
||||||
this.$locale.baseText('variableSelectorItem.inputData'),
|
|
||||||
this.$locale.baseText('variableSelectorItem.binary'),
|
|
||||||
this.$locale.baseText('variableSelectorItem.json'),
|
|
||||||
].includes(this.item.name) && this.item.key === undefined;
|
|
||||||
|
|
||||||
if (shouldAutoExtend) {
|
const itemAddOperations = computed(() => {
|
||||||
this.extended = true;
|
const returnOptions = [
|
||||||
}
|
{
|
||||||
},
|
command: 'raw',
|
||||||
methods: {
|
displayName: 'Raw value',
|
||||||
optionSelected(command: string, item: IVariableSelectorOption) {
|
|
||||||
// By default it is raw
|
|
||||||
let variable = item.key;
|
|
||||||
if (command === 'arrayValues') {
|
|
||||||
variable = `${item.key}.join(', ')`;
|
|
||||||
} else if (command === 'arrayLength') {
|
|
||||||
variable = `${item.key}.length`;
|
|
||||||
} else if (command === 'objectKeys') {
|
|
||||||
variable = `Object.keys(${item.key}).join(', ')`;
|
|
||||||
} else if (command === 'objectValues') {
|
|
||||||
variable = `Object.values(${item.key}).join(', ')`;
|
|
||||||
}
|
|
||||||
this.$emit('itemSelected', { variable });
|
|
||||||
},
|
},
|
||||||
selectItem(item: IVariableSelectorOption) {
|
];
|
||||||
this.$emit('itemSelected', { variable: item.key });
|
if (props.item.dataType === 'array') {
|
||||||
},
|
returnOptions.push(
|
||||||
forwardItemSelected(eventData: IVariableItemSelected) {
|
{
|
||||||
this.$emit('itemSelected', eventData);
|
command: 'arrayLength',
|
||||||
},
|
displayName: 'Length',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
command: 'arrayValues',
|
||||||
|
displayName: 'Values',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (props.item.dataType === 'object') {
|
||||||
|
returnOptions.push(
|
||||||
|
{
|
||||||
|
command: 'objectKeys',
|
||||||
|
displayName: 'Keys',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
command: 'objectValues',
|
||||||
|
displayName: 'Values',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return returnOptions;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (extended.value) return;
|
||||||
|
|
||||||
|
const shouldAutoExtend =
|
||||||
|
['Current Node', 'Input Data', 'Binary', 'JSON'].includes(props.item.name) &&
|
||||||
|
props.item.key === undefined;
|
||||||
|
|
||||||
|
if (shouldAutoExtend) {
|
||||||
|
extended.value = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const optionSelected = (command: string, item: IVariableSelectorOption) => {
|
||||||
|
let variable = item.key ?? '';
|
||||||
|
if (command === 'arrayValues') {
|
||||||
|
variable = `${item.key}.join(', ')`;
|
||||||
|
} else if (command === 'arrayLength') {
|
||||||
|
variable = `${item.key}.length`;
|
||||||
|
} else if (command === 'objectKeys') {
|
||||||
|
variable = `Object.keys(${item.key}).join(', ')`;
|
||||||
|
} else if (command === 'objectValues') {
|
||||||
|
variable = `Object.values(${item.key}).join(', ')`;
|
||||||
|
}
|
||||||
|
emit('itemSelected', { variable });
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectItem = (item: IVariableSelectorOption) => {
|
||||||
|
emit('itemSelected', { variable: item.key ?? '' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const forwardItemSelected = (eventData: IVariableItemSelected) => {
|
||||||
|
emit('itemSelected', eventData);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user