-
Notifications
You must be signed in to change notification settings - Fork 11
Issue 61 : Frontend -Add details in the datasource card #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 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'; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto re-organised ;)
| 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'; |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 :)
src/ConfigEditor/ConfigEditor.tsx
Outdated
|
|
||
| // Description to show in datasource card in list | ||
| const { onOptionsChange: propsOnOptionsChange } = props; | ||
| useEffect(() => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/ConfigEditor/ConfigEditor.tsx
Outdated
|
|
||
| // Description to show in datasource card in list | ||
| const { onOptionsChange: propsOnOptionsChange } = props; | ||
| useEffect(() => { |
There was a problem hiding this comment.
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.
src/ConfigEditor/ConfigEditor.tsx
Outdated
| return res; | ||
| }; | ||
| const fetchCluster = async (clusterId: string) => { | ||
| const res: Cluster = await getBackendSrv().post(resourcesURL + '/cluster', { clusterIdentifier: clusterId }); |
There was a problem hiding this comment.
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.
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
metainfo. Meta include the datasourcetypeName,urlandisDefault.This PR uses the endpoint created by #121 to populate the
urlfieldScreenshots
Test coverage
Running:
yarn test:coverage:change