2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div @keydown.stop class="collection-parameter">
|
|
|
|
<div class="collection-parameter-wrapper">
|
|
|
|
<div v-if="getProperties.length === 0" class="no-items-exist">
|
2021-12-15 04:16:53 -08:00
|
|
|
<n8n-text size="small">{{ $locale.baseText('collectionParameter.noProperties') }}</n8n-text>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
<parameter-input-list
|
|
|
|
:parameters="getProperties"
|
|
|
|
:nodeValues="nodeValues"
|
|
|
|
:path="path"
|
|
|
|
:hideDelete="hideDelete"
|
|
|
|
:indent="true"
|
|
|
|
:isReadOnly="isReadOnly"
|
|
|
|
@valueChanged="valueChanged"
|
|
|
|
/>
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
<div v-if="parameterOptions.length > 0 && !isReadOnly" class="param-options">
|
|
|
|
<n8n-button
|
|
|
|
v-if="parameter.options.length === 1"
|
2022-05-23 08:56:15 -07:00
|
|
|
type="tertiary"
|
2022-07-20 08:50:39 -07:00
|
|
|
block
|
2021-08-29 04:36:17 -07:00
|
|
|
@click="optionSelected(parameter.options[0].name)"
|
|
|
|
:label="getPlaceholderText"
|
|
|
|
/>
|
|
|
|
<div v-else class="add-option">
|
2022-12-14 01:04:10 -08:00
|
|
|
<n8n-select
|
|
|
|
v-model="selectedOption"
|
|
|
|
:placeholder="getPlaceholderText"
|
|
|
|
size="small"
|
|
|
|
@change="optionSelected"
|
|
|
|
filterable
|
|
|
|
>
|
2021-08-29 04:36:17 -07:00
|
|
|
<n8n-option
|
|
|
|
v-for="item in parameterOptions"
|
|
|
|
:key="item.name"
|
2022-01-07 13:02:21 -08:00
|
|
|
:label="$locale.nodeText().collectionOptionDisplayName(parameter, item, path)"
|
2022-12-14 01:04:10 -08:00
|
|
|
:value="item.name"
|
|
|
|
>
|
2021-08-29 04:36:17 -07:00
|
|
|
</n8n-option>
|
|
|
|
</n8n-select>
|
|
|
|
</div>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { INodeUi, IUpdateInformation } from '@/Interface';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
|
|
|
import { deepCopy } from 'n8n-workflow';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-11-23 04:41:53 -08:00
|
|
|
import { nodeHelpers } from '@/mixins/nodeHelpers';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-02-23 07:16:05 -08:00
|
|
|
import { get } from 'lodash-es';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { Component } from 'vue';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useNDVStore } from '@/stores/ndv.store';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
export default mixins(nodeHelpers).extend({
|
|
|
|
name: 'CollectionParameter',
|
|
|
|
props: [
|
|
|
|
'hideDelete', // boolean
|
|
|
|
'nodeValues', // NodeParameters
|
|
|
|
'parameter', // INodeProperties
|
|
|
|
'path', // string
|
|
|
|
'values', // NodeParameters
|
|
|
|
'isReadOnly', // boolean
|
|
|
|
],
|
|
|
|
components: {
|
|
|
|
ParameterInputList: () => import('./ParameterInputList.vue') as Promise<Component>,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedOption: undefined,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapStores(useNDVStore),
|
|
|
|
getPlaceholderText(): string {
|
|
|
|
const placeholder = this.$locale.nodeText().placeholder(this.parameter, this.path);
|
|
|
|
return placeholder ? placeholder : this.$locale.baseText('collectionParameter.choose');
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
getProperties(): INodeProperties[] {
|
|
|
|
const returnProperties = [];
|
|
|
|
let tempProperties;
|
|
|
|
for (const name of this.propertyNames) {
|
|
|
|
tempProperties = this.getOptionProperties(name);
|
|
|
|
if (tempProperties !== undefined) {
|
|
|
|
returnProperties.push(...tempProperties);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
}
|
|
|
|
return returnProperties;
|
|
|
|
},
|
|
|
|
// Returns all the options which should be displayed
|
|
|
|
filteredOptions(): Array<INodePropertyOptions | INodeProperties> {
|
|
|
|
return (this.parameter.options as Array<INodePropertyOptions | INodeProperties>).filter(
|
|
|
|
(option) => {
|
2019-06-23 03:35:23 -07:00
|
|
|
return this.displayNodeParameter(option as INodeProperties);
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
node(): INodeUi | null {
|
|
|
|
return this.ndvStore.activeNode;
|
|
|
|
},
|
|
|
|
// Returns all the options which did not get added already
|
|
|
|
parameterOptions(): Array<INodePropertyOptions | INodeProperties> {
|
|
|
|
return (this.filteredOptions as Array<INodePropertyOptions | INodeProperties>).filter(
|
|
|
|
(option) => {
|
2019-06-23 03:35:23 -07:00
|
|
|
return !this.propertyNames.includes(option.name);
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
propertyNames(): string[] {
|
|
|
|
if (this.values) {
|
|
|
|
return Object.keys(this.values);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getArgument(argumentName: string): string | number | boolean | undefined {
|
|
|
|
if (this.parameter.typeOptions === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.parameter.typeOptions[argumentName] === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parameter.typeOptions[argumentName];
|
|
|
|
},
|
|
|
|
getOptionProperties(optionName: string): INodeProperties[] {
|
|
|
|
const properties: INodeProperties[] = [];
|
|
|
|
for (const option of this.parameter.options) {
|
|
|
|
if (option.name === optionName) {
|
|
|
|
properties.push(option);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
}
|
2021-05-28 16:13:15 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return properties;
|
|
|
|
},
|
|
|
|
displayNodeParameter(parameter: INodeProperties) {
|
|
|
|
if (parameter.displayOptions === undefined) {
|
|
|
|
// If it is not defined no need to do a proper check
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this.displayParameter(this.nodeValues, parameter, this.path, this.node);
|
|
|
|
},
|
|
|
|
optionSelected(optionName: string) {
|
|
|
|
const options = this.getOptionProperties(optionName);
|
|
|
|
if (options.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const option = options[0];
|
|
|
|
const name = `${this.path}.${option.name}`;
|
|
|
|
|
|
|
|
let parameterData;
|
|
|
|
|
|
|
|
if (option.typeOptions !== undefined && option.typeOptions.multipleValues === true) {
|
|
|
|
// Multiple values are allowed
|
|
|
|
|
|
|
|
let newValue;
|
|
|
|
if (option.type === 'fixedCollection') {
|
|
|
|
// The "fixedCollection" entries are different as they save values
|
|
|
|
// in an object and then underneath there is an array. So initialize
|
|
|
|
// them differently.
|
|
|
|
newValue = get(this.nodeValues, `${this.path}.${optionName}`, {});
|
2019-06-23 03:35:23 -07:00
|
|
|
} else {
|
2022-12-14 01:04:10 -08:00
|
|
|
// Everything else saves them directly as an array.
|
|
|
|
newValue = get(this.nodeValues, `${this.path}.${optionName}`, []);
|
|
|
|
newValue.push(deepCopy(option.default));
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
parameterData = {
|
|
|
|
name,
|
|
|
|
value: newValue,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Add a new option
|
|
|
|
parameterData = {
|
|
|
|
name,
|
|
|
|
value: deepCopy(option.default),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
this.selectedOption = undefined;
|
|
|
|
},
|
|
|
|
valueChanged(parameterData: IUpdateInformation) {
|
|
|
|
this.$emit('valueChanged', parameterData);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
});
|
2019-06-23 03:35:23 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.collection-parameter {
|
2021-10-27 12:55:37 -07:00
|
|
|
padding-left: var(--spacing-s);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
.param-options {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin-top: var(--spacing-xs);
|
2022-07-20 08:50:39 -07:00
|
|
|
|
|
|
|
.button {
|
|
|
|
--button-background-color: var(--color-background-base);
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.no-items-exist {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin: var(--spacing-xs) 0;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
.option {
|
|
|
|
position: relative;
|
|
|
|
padding: 0.25em 0 0.25em 1em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|