Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/redshift/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *API) Execute(ctx context.Context, input *api.ExecuteQueryInput) (*api.E
DbUser: commonInput.DbUser,
SecretArn: commonInput.SecretARN,
Sql: aws.String(input.Query),
WithEvent: aws.Bool(c.settings.WithEvent),
}

output, err := c.DataClient.ExecuteStatementWithContext(ctx, redshiftInput)
Expand Down Expand Up @@ -352,7 +353,7 @@ func (c *API) Clusters() ([]models.RedshiftCluster, error) {
}
res := []models.RedshiftCluster{}
for _, r := range out.Clusters {
if (r != nil && r.ClusterIdentifier != nil && r.Endpoint != nil && r.Endpoint.Address != nil && r.Endpoint.Port != nil && r.DBName != nil) {
if r != nil && r.ClusterIdentifier != nil && r.Endpoint != nil && r.Endpoint.Address != nil && r.Endpoint.Port != nil && r.DBName != nil {
res = append(res, models.RedshiftCluster{
ClusterIdentifier: *r.ClusterIdentifier,
Endpoint: models.RedshiftEndpoint{
Expand Down
12 changes: 6 additions & 6 deletions pkg/redshift/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ func Test_GetClusters(t *testing.T) {
expectedClusters: []models.RedshiftCluster{*expectedCluster1, *expectedCluster2},
},
{
c: errC,
desc: "Error with DescribeCluster",
errMsg: "Boom!",
c: errC,
desc: "Error with DescribeCluster",
errMsg: "Boom!",
},
{
c: nilC,
desc: "DescribeCluster returned nil",
errMsg: "missing clusters content",
c: nilC,
desc: "DescribeCluster returned nil",
errMsg: "missing clusters content",
},
}
for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions pkg/redshift/models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type RedshiftDataSourceSettings struct {
ClusterIdentifier string `json:"clusterIdentifier"`
Database string `json:"database"`
UseManagedSecret bool `json:"useManagedSecret"`
WithEvent bool `json:"withEvent"`
DBUser string `json:"dbUser"`
ManagedSecret ManagedSecret
}
Expand Down
15 changes: 15 additions & 0 deletions src/ConfigEditor/ConfigEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ describe('ConfigEditor', () => {
});
});

it('should enable WithEvent when it is toggled on', async () => {
const onChange = jest.fn();
render(<ConfigEditor {...props} onOptionsChange={onChange} />);
const withEventField = screen.getByTestId(selectors.components.ConfigEditor.WithEvent.testID);
expect(withEventField).toBeInTheDocument();

fireEvent.click(withEventField);

expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith({
...props.options,
jsonData: { ...props.options.jsonData, withEvent: true },
});
});

it('should populate the `url` prop when clusterIdentifier is selected', async () => {
const onChange = jest.fn();
render(
Expand Down
22 changes: 22 additions & 0 deletions src/ConfigEditor/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RedshiftManagedSecret,
} from '../types';
import { AuthTypeSwitch } from './AuthTypeSwitch';
import { InlineField, Switch } from '@grafana/ui';

export type Props = DataSourcePluginOptionsEditorProps<RedshiftDataSourceOptions, RedshiftDataSourceSecureJsonData>;

Expand Down Expand Up @@ -209,6 +210,27 @@ export function ConfigEditor(props: Props) {
label={selectors.components.ConfigEditor.Database.input}
data-testid={selectors.components.ConfigEditor.Database.testID}
/>
<InlineField
{...props}
label={selectors.components.ConfigEditor.WithEvent.input}
labelWidth={28}
style={{ alignItems: 'center' }}
>
<Switch
value={props.options.jsonData.withEvent ?? false}
onChange={(e) =>
props.onOptionsChange({
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a simple test for this? If you go to ConfigEditor.test.tsx you can take inspiration from the test should allow user to enter a database. You will need to add a data-testid to this Switch to test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andresmgot I have added test for this, If you see the test currently fails because the onChange is not getting triggered. I am unable to find a reason for this. Need your help in getting this test case passing. Thanks in advance! :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's because how Switch is internally implemented, if you do fireEvent.click(withEventField); rather than fireEvent.change(withEventField, { target: { checked: true } }); it should work.

...props.options,
jsonData: {
...props.options.jsonData,
withEvent: e.currentTarget.checked,
},
})
}
css={undefined}
data-testid={selectors.components.ConfigEditor.WithEvent.testID}
/>
</InlineField>
</div>
);
}
4 changes: 4 additions & 0 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const Components = {
input: 'Column',
testID: 'data-testid column',
},
WithEvent: {
input: 'Send events to Amazon EventBridge',
testID: 'data-testid withEvent',
},
},
QueryEditor: {
CodeEditor: {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const defaultQuery: Partial<RedshiftQuery> = {
* These are options configured for each DataSource instance
*/
export interface RedshiftDataSourceOptions extends AwsAuthDataSourceJsonData {
withEvent?: boolean;
useManagedSecret?: boolean;
clusterIdentifier?: string;
database?: string;
Expand Down