Skip to content

Conversation

@yaelleC
Copy link
Contributor

@yaelleC yaelleC commented Feb 25, 2022

Frontend work for #61
Fixes #61

Description

When listing datasources, a card is composed of a Heading ('Amazon Redshift'), a Figure (the logo) and some meta info. Meta include the datasource typeName, url and isDefault.

This PR uses the endpoint created by #121 to populate the url field

Screenshots

Before After
Screenshot 2022-02-22 at 10 27 20 Screenshot 2022-02-22 at 10 27 45

Test coverage

Running: yarn test:coverage:change

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   88.73 |    84.85 |   87.50 |   88.19 |                   
  ConfigEditor.tsx |   91.23 |    84.09 |   94.74 |    90.2 | 38-43,103-104     
-------------------|---------|----------|---------|---------|-------------------

Comment on lines 1 to 7
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { ConfigEditor } from './ConfigEditor';
import { selectors } from '../selectors';
import { mockDatasourceOptions } from '../__mocks__/datasource';
import { select } from 'react-select-event';

import { mockDatasourceOptions } from '../__mocks__/datasource';
import { selectors } from '../selectors';
import { ConfigEditor } from './ConfigEditor';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto re-organised ;)

Comment on lines 1 to 12
import React, { useState, useEffect, FormEvent } from 'react';
import { ConfigSelect, ConnectionConfig, InlineInput } from '@grafana/aws-sdk';
import { DataSourcePluginOptionsEditorProps, SelectableValue } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import React, { FormEvent, useEffect, useState } from 'react';
import { selectors } from 'selectors';

import {
RedshiftDataSourceOptions,
RedshiftDataSourceSecureJsonData,
RedshiftDataSourceSettings,
RedshiftManagedSecret,
} from '../types';
import { InlineInput, ConfigSelect, ConnectionConfig } from '@grafana/aws-sdk';
import { getBackendSrv } from '@grafana/runtime';
import { AuthTypeSwitch } from './AuthTypeSwitch';
import { selectors } from 'selectors';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto reorg

});
});

it('should allow user to enter a database', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not technically used in this PR but improves coverage :)

@yaelleC yaelleC linked an issue Mar 1, 2022 that may be closed by this pull request

// Description to show in datasource card in list
const { onOptionsChange: propsOnOptionsChange } = props;
useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be done here: it's triggered for every key stroke on clusterIdentifier Input 😞

option 1: do this on save
option 2: use onBlur on input rather than onChange

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, there is no exposed hook for "on save" but we can make it on blur. We need to modify the component in the SDK but it should be simple: https://github.com/grafana/grafana-aws-sdk-react/blob/main/src/sql/ConfigEditor/InlineInput.tsx#L28

In fact, if we can expose all the Input properties there we will avoid this kind of issues in the future.

If you create a PR against that repo, you can just bump the version there and it will be automatically released so you can use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we could instead make clusterId a dropdown by exposing another endpoint (same call without filtering on cluster ID)?
It seems more user friendly to select a cluster rather than typing it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good point, it's actually the experience that you get in the AWS console. The only downside of this is that the API permission that is optional now would become mandatory. We could workaround that allowing people to type the the clusterId anyway in the selector but that also requires changes in the SDK 😅 (since the wrapper around the Select doesn't allow to set the allowCustomValue at the moment).

In any case, since it would be a UX improvement and it's trivial to implement now that we have already the endpoint to get a Cluster I would go for it. I would change the current Cluster endpoint for a its plural and return the list of all the clusters (so no additional API requests are needed). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that sounds good, only having the one API request and get the url from the cluster selected in the dropdown 👍

Re-permissions, are you saying we should also make changes to the SDK to allow custom values for clusterID? Or make the API permission compulsory?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we can avoid the "breaking" change yes, we should modify the SDK to allow that parameter. Basically we would need to modify this Select and modify the props of the wrappers ResourceSelector and ConfigSelect

@yaelleC yaelleC marked this pull request as ready for review March 1, 2022 14:47
@yaelleC yaelleC requested a review from a team as a code owner March 1, 2022 14:47
@yaelleC yaelleC requested review from andresmgot and sunker and removed request for a team March 1, 2022 14:47

// Description to show in datasource card in list
const { onOptionsChange: propsOnOptionsChange } = props;
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, there is no exposed hook for "on save" but we can make it on blur. We need to modify the component in the SDK but it should be simple: https://github.com/grafana/grafana-aws-sdk-react/blob/main/src/sql/ConfigEditor/InlineInput.tsx#L28

In fact, if we can expose all the Input properties there we will avoid this kind of issues in the future.

If you create a PR against that repo, you can just bump the version there and it will be automatically released so you can use it here.

return res;
};
const fetchCluster = async (clusterId: string) => {
const res: Cluster = await getBackendSrv().post(resourcesURL + '/cluster', { clusterIdentifier: clusterId });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and it's curious that if you get a 400 error (e.g. the clusterId does not exists), the error does not appear in the UI but if it's a 404 or a 500 you get it. Since this is optional, I will wrap this in a try {} catch so we don't show the error in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add datasource details in the list

2 participants