Skip to content

Commit

Permalink
fix(editor): Fix RLC not loading when an expression can't resolve (#7295
Browse files Browse the repository at this point in the history
)

Also fixes label (list -> From list)

Github issue / Community forum post (link here to close automatically):
  • Loading branch information
elsmr authored Oct 4, 2023
1 parent 1b4848a commit ddc26c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 83 deletions.
9 changes: 9 additions & 0 deletions cypress/e2e/26-resource-locator.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const credentialsModal = new CredentialsModal();

const NO_CREDENTIALS_MESSAGE = 'Please add your credential';
const INVALID_CREDENTIALS_MESSAGE = 'Please check your credential';
const MODE_SELECTOR_LIST = 'From list';

describe('Resource Locator', () => {
beforeEach(() => {
Expand All @@ -18,6 +19,14 @@ describe('Resource Locator', () => {
workflowPage.actions.addNodeToCanvas('Google Sheets', true, true);
ndv.getters.resourceLocator('documentId').should('be.visible');
ndv.getters.resourceLocator('sheetName').should('be.visible');
ndv.getters
.resourceLocatorModeSelector('documentId')
.find('input')
.should('have.value', MODE_SELECTOR_LIST);
ndv.getters
.resourceLocatorModeSelector('sheetName')
.find('input')
.should('have.value', MODE_SELECTOR_LIST);
});

it('should show appropriate error when credentials are not set', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@
v-for="mode in parameter.modes"
:key="mode.name"
:value="mode.name"
:label="getModeLabel(mode)"
:disabled="isValueExpression && mode.name === 'list'"
:title="
isValueExpression && mode.name === 'list'
? $locale.baseText('resourceLocator.mode.list.disabled.title')
: ''
"
>
{{ getModeLabel(mode.name) || mode.displayName }}
{{ getModeLabel(mode) }}
</n8n-option>
</n8n-select>
</div>
Expand Down Expand Up @@ -143,8 +144,27 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import type { IResourceLocatorReqParams, IResourceLocatorResultExpanded } from '@/Interface';
import DraggableTarget from '@/components/DraggableTarget.vue';
import ExpressionParameterInput from '@/components/ExpressionParameterInput.vue';
import ParameterIssues from '@/components/ParameterIssues.vue';
import { debounceHelper } from '@/mixins/debounce';
import { nodeHelpers } from '@/mixins/nodeHelpers';
import { workflowHelpers } from '@/mixins/workflowHelpers';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import {
getAppNameFromNodeName,
getMainAuthField,
hasOnlyListMode,
isResourceLocatorValue,
} from '@/utils';
import stringify from 'fast-json-stable-stringify';
import type { EventBus } from 'n8n-design-system/utils';
import { createEventBus } from 'n8n-design-system/utils';
import type {
ILoadOptions,
INode,
Expand All @@ -156,29 +176,10 @@ import type {
INodePropertyMode,
NodeParameterValue,
} from 'n8n-workflow';
import ExpressionParameterInput from '@/components/ExpressionParameterInput.vue';
import DraggableTarget from '@/components/DraggableTarget.vue';
import ParameterIssues from '@/components/ParameterIssues.vue';
import ResourceLocatorDropdown from './ResourceLocatorDropdown.vue';
import { mapStores } from 'pinia';
import type { PropType } from 'vue';
import type { IResourceLocatorReqParams, IResourceLocatorResultExpanded } from '@/Interface';
import { debounceHelper } from '@/mixins/debounce';
import stringify from 'fast-json-stable-stringify';
import { workflowHelpers } from '@/mixins/workflowHelpers';
import { nodeHelpers } from '@/mixins/nodeHelpers';
import {
getAppNameFromNodeName,
isResourceLocatorValue,
hasOnlyListMode,
getMainAuthField,
} from '@/utils';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { createEventBus } from 'n8n-design-system/utils';
import type { EventBus } from 'n8n-design-system/utils';
import { defineComponent } from 'vue';
import ResourceLocatorDropdown from './ResourceLocatorDropdown.vue';
interface IResourceLocatorQuery {
results: INodeListSearchItems[];
Expand Down Expand Up @@ -573,12 +574,12 @@ export default defineComponent({
}
return null;
},
getModeLabel(name: string): string | null {
if (name === 'id' || name === 'url' || name === 'list') {
return this.$locale.baseText(`resourceLocator.mode.${name}`);
getModeLabel(mode: INodePropertyMode): string | null {
if (mode.name === 'id' || mode.name === 'url' || mode.name === 'list') {
return this.$locale.baseText(`resourceLocator.mode.${mode.name}`);
}
return null;
return mode.displayName;
},
onInputChange(value: string): void {
const params: INodeParameterResourceLocator = { __rl: true, value, mode: this.selectedMode };
Expand Down
99 changes: 45 additions & 54 deletions packages/editor-ui/src/mixins/workflowHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import {
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
PLACEHOLDER_EMPTY_WORKFLOW_ID,
WEBHOOK_NODE_TYPE,
VIEWS,
EnterpriseEditionFeature,
MODAL_CONFIRM,
PLACEHOLDER_EMPTY_WORKFLOW_ID,
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
VIEWS,
WEBHOOK_NODE_TYPE,
} from '@/constants';
import { mapStores } from 'pinia';
import { defineComponent } from 'vue';

import type {
IConnections,
IDataObject,
IExecuteData,
INode,
INodeConnection,
INodeCredentials,
INodeExecutionData,
INodeIssues,
INodeParameters,
NodeParameterValue,
INodeCredentials,
INodeProperties,
INodeType,
INodeTypes,
IRunExecutionData,
IWorkflowIssues,
IWorkflowDataProxyAdditionalKeys,
Workflow,
IExecuteData,
INodeConnection,
IWebhookDescription,
INodeProperties,
IWorkflowDataProxyAdditionalKeys,
IWorkflowIssues,
IWorkflowSettings,
NodeParameterValue,
Workflow,
} from 'n8n-workflow';
import { NodeConnectionType, ExpressionEvaluatorProxy, NodeHelpers } from 'n8n-workflow';

import type {
ICredentialsResponse,
INodeTypesMaxCount,
INodeUi,
ITag,
IWorkflowData,
IWorkflowDb,
IWorkflowDataUpdate,
XYPosition,
ITag,
IWorkflowDb,
TargetItem,
ICredentialsResponse,
XYPosition,
} from '../Interface';

import { useMessage, useToast } from '@/composables';
import { externalHooks } from '@/mixins/externalHooks';
import { nodeHelpers } from '@/mixins/nodeHelpers';
import { genericHelpers } from '@/mixins/genericHelpers';
import { useToast, useMessage } from '@/composables';
import { nodeHelpers } from '@/mixins/nodeHelpers';

import { isEqual } from 'lodash-es';

import { v4 as uuid } from 'uuid';
import { getSourceItems } from '@/utils';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import type { IPermissions } from '@/permissions';
import { getWorkflowPermissions } from '@/permissions';
import { useEnvironmentsStore } from '@/stores/environments.ee.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useTemplatesStore } from '@/stores/templates.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useWorkflowsEEStore } from '@/stores/workflows.ee.store';
import { useEnvironmentsStore } from '@/stores/environments.ee.store';
import { useTemplatesStore } from '@/stores/templates.store';
import { useUIStore } from '@/stores/ui.store';
import { useUsersStore } from '@/stores/users.store';
import { useWorkflowsEEStore } from '@/stores/workflows.ee.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { getSourceItems } from '@/utils';
import { v4 as uuid } from 'uuid';
import { useSettingsStore } from '@/stores/settings.store';
import { getWorkflowPermissions } from '@/permissions';
import type { IPermissions } from '@/permissions';

export function getParentMainInputNode(workflow: Workflow, node: INode): INode {
const nodeType = useNodeTypesStore().getNodeType(node.type);
Expand Down Expand Up @@ -233,35 +233,26 @@ export function resolveRequiredParameters(
inputBranchIndex?: number;
} = {},
): IDataObject | null {
const loadOptionsDependsOn = currentParameter?.typeOptions?.loadOptionsDependsOn ?? [];

const initial: { required: INodeParameters; nonrequired: INodeParameters } = {
required: {},
nonrequired: {},
};
const loadOptionsDependsOn = new Set(currentParameter?.typeOptions?.loadOptionsDependsOn ?? []);

const { required, nonrequired }: INodeParameters = Object.keys(parameters).reduce(
(accu, name: string) => {
const required = loadOptionsDependsOn.includes(name);
accu[required ? 'required' : 'nonrequired'][name] = parameters[name];
const resolvedParameters = Object.fromEntries(
Object.entries(parameters).map(([name, parameter]): [string, IDataObject | null] => {
const required = loadOptionsDependsOn.has(name);

return accu;
},
initial,
if (required) {
return [name, resolveParameter(parameter as NodeParameterValue, opts)];
} else {
try {
return [name, resolveParameter(parameter as NodeParameterValue, opts)];
} catch (error) {
// ignore any expressions errors for non required parameters
return [name, null];
}
}
}),
);

const resolvedRequired = resolveParameter(required, opts);
let resolvedNonrequired: IDataObject | null = {};
try {
resolvedNonrequired = resolveParameter(nonrequired, opts);
} catch (e) {
// ignore any expression errors for example
}

return {
...resolvedRequired,
...(resolvedNonrequired ?? {}),
};
return resolvedParameters;
}

function getCurrentWorkflow(copyData?: boolean): Workflow {
Expand Down

0 comments on commit ddc26c2

Please sign in to comment.