Skip to content

Commit

Permalink
feat(editor): Do not show error for remote options when credentials a…
Browse files Browse the repository at this point in the history
…ren't specified (#10944)
  • Loading branch information
burivuhster authored Sep 26, 2024
1 parent 6322372 commit 9fc3699
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/5-ndv.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,23 @@ describe('NDV', () => {
ndv.getters.parameterInput('operation').find('input').should('have.value', 'Delete');
});

it('Should show a notice when remote options cannot be fetched because of missing credentials', () => {
cy.intercept('POST', '/rest/dynamic-node-parameters/options', { statusCode: 403 }).as(
'parameterOptions',
);

workflowPage.actions.addInitialNodeToCanvas(NOTION_NODE_NAME, {
keepNdvOpen: true,
action: 'Update a database page',
});

ndv.actions.addItemToFixedCollection('propertiesUi');
ndv.getters
.parameterInput('key')
.find('input')
.should('have.value', 'Set up credential to see options');
});

it('Should show error state when remote options cannot be fetched', () => {
cy.intercept('POST', '/rest/dynamic-node-parameters/options', { statusCode: 500 }).as(
'parameterOptions',
Expand All @@ -684,6 +701,11 @@ describe('NDV', () => {
action: 'Update a database page',
});

clickCreateNewCredential();
setCredentialValues({
apiKey: 'sk_test_123',
});

ndv.actions.addItemToFixedCollection('propertiesUi');
ndv.getters
.parameterInput('key')
Expand Down
10 changes: 10 additions & 0 deletions packages/editor-ui/src/components/ParameterInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ const displayValue = computed(() => {
if (!nodeType.value || nodeType.value?.codex?.categories?.includes(CORE_NODES_CATEGORY)) {
return i18n.baseText('parameterInput.loadOptionsError');
}
if (nodeType.value?.credentials && nodeType.value?.credentials?.length > 0) {
const credentialsType = nodeType.value?.credentials[0];
if (credentialsType.required && !node.value?.credentials) {
return i18n.baseText('parameterInput.loadOptionsCredentialsRequired');
}
}
return i18n.baseText('parameterInput.loadOptionsErrorService', {
interpolate: { service: nodeType.value.displayName },
});
Expand Down Expand Up @@ -1275,6 +1284,7 @@ onUpdated(async () => {
"
:title="displayTitle"
:placeholder="getPlaceholder()"
data-test-id="parameter-input-field"
@update:model-value="(valueChanged($event) as undefined) && onUpdateTextInput($event)"
@keydown.stop
@focus="setFocus"
Expand Down
43 changes: 43 additions & 0 deletions packages/editor-ui/src/components/__tests__/ParameterInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,47 @@ describe('ParameterInput.vue', () => {
// Nothing should be emitted
expect(emitted('update')).toBeUndefined();
});

test('should show message when can not load options without credentials', async () => {
mockNodeTypesState.getNodeParameterOptions = vi.fn(async () => {
throw new Error('Node does not have any credentials set');
});

// @ts-expect-error Readonly property
mockNodeTypesState.getNodeType = vi.fn().mockReturnValue({
displayName: 'Test',
credentials: [
{
name: 'openAiApi',
required: true,
},
],
});

const { emitted, container, getByTestId } = renderComponent(ParameterInput, {
pinia: createTestingPinia(),
props: {
path: 'columns',
parameter: {
displayName: 'Columns',
name: 'columns',
type: 'options',
typeOptions: { loadOptionsMethod: 'getColumnsMultiOptions' },
},
modelValue: 'id',
},
});

await waitFor(() => expect(getByTestId('parameter-input-field')).toBeInTheDocument());

const input = container.querySelector('input') as HTMLInputElement;
expect(input).toBeInTheDocument();

expect(mockNodeTypesState.getNodeParameterOptions).toHaveBeenCalled();

expect(input.value.toLowerCase()).not.toContain('error');
expect(input).toHaveValue('Set up credential to see options');

expect(emitted('update')).toBeUndefined();
});
});
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@
"parameterInput.loadingOptions": "Loading options...",
"parameterInput.loadOptionsErrorService": "Error fetching options from {service}",
"parameterInput.loadOptionsError": "Error fetching options",
"parameterInput.loadOptionsCredentialsRequired": "Set up credential to see options",
"parameterInput.openEditWindow": "Open Edit Window",
"parameterInput.parameter": "Parameter: \"{shortPath}\"",
"parameterInput.parameterHasExpression": "Parameter: \"{shortPath}\" has an expression",
Expand Down

0 comments on commit 9fc3699

Please sign in to comment.