Skip to content
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

Update Key to KeyName to avoid conflict in the Explore tab #112

Merged
merged 1 commit into from
Dec 21, 2020
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
2 changes: 1 addition & 1 deletion pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type dataModel struct {
type queryModel struct {
Type string `json:"type"`
Query string `json:"query"`
Key string `json:"key"`
Key string `json:"keyName"`
Field string `json:"field"`
Filter string `json:"filter"`
Command string `json:"command"`
Expand Down
10 changes: 5 additions & 5 deletions src/components/query-editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AggregationValue, InfoSectionValue, QueryTypeValue, RedisQuery } from '
* Query
*/
const getQuery = (overrideQuery: object = {}): RedisQuery => ({
key: '',
keyName: '',
aggregation: AggregationValue.NONE,
bucket: 0,
legend: '',
Expand Down Expand Up @@ -219,28 +219,28 @@ describe('QueryEditor', () => {
});

it('Should set value from query', () => {
const query = getQuery({ type: QueryTypeValue.COMMAND, command: 'get', key: '123' });
const query = getQuery({ type: QueryTypeValue.COMMAND, command: 'get', keyName: '123' });
const wrapper = shallow<QueryEditor>(
<QueryEditor datasource={{} as any} query={query} onRunQuery={onRunQuery} onChange={onChange} />
);
const testedComponent = getComponent(wrapper);
expect(testedComponent.prop('value')).toEqual(query.key);
expect(testedComponent.prop('value')).toEqual(query.keyName);
});

it('Should call onKeyChange method when onChange prop was called', () => {
const query = getQuery({ type: QueryTypeValue.COMMAND, command: 'get' });
const wrapper = shallow<QueryEditor>(
<QueryEditor datasource={{} as any} query={query} onRunQuery={onRunQuery} onChange={onChange} />
);
const testedMethod = jest.spyOn(wrapper.instance(), 'onKeyChange');
const testedMethod = jest.spyOn(wrapper.instance(), 'onKeyNameChange');
wrapper.instance().forceUpdate();
const testedComponent = getComponent(wrapper);
const newValue = '1234';
testedComponent.simulate('change', { target: { value: newValue } });
expect(testedMethod).toHaveBeenCalledWith({ target: { value: newValue } });
expect(onChange).toHaveBeenCalledWith({
...query,
key: newValue,
keyName: newValue,
});
});
});
Expand Down
14 changes: 7 additions & 7 deletions src/components/query-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type Props = QueryEditorProps<DataSource, RedisQuery, RedisDataSourceOptions>;
*/
export class QueryEditor extends PureComponent<Props> {
/**
* Key change
* Key name change
*
* @param {ChangeEvent<HTMLInputElement>} event Event
*/
onKeyChange = (event: ChangeEvent<HTMLInputElement>) => {
onKeyNameChange = (event: ChangeEvent<HTMLInputElement>) => {
const { onChange, query } = this.props;
onChange({ ...query, key: event.target.value });
onChange({ ...query, keyName: event.target.value });
};

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ export class QueryEditor extends PureComponent<Props> {
*/
render() {
const {
key,
keyName,
aggregation,
bucket,
legend,
Expand Down Expand Up @@ -204,12 +204,12 @@ export class QueryEditor extends PureComponent<Props> {

{type !== QueryTypeValue.CLI && command && (
<div className="gf-form">
{CommandParameters.key.includes(command) && (
{CommandParameters.keyName.includes(command) && (
<FormField
labelWidth={8}
inputWidth={30}
value={key}
onChange={this.onKeyChange}
value={keyName}
onChange={this.onKeyNameChange}
label="Key"
tooltip="Key name"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DataSource extends DataSourceWithBackend<RedisQuery, RedisDataSourc
*/
return {
...query,
key: query.key ? templateSrv.replace(query.key, scopedVars) : '',
keyName: query.keyName ? templateSrv.replace(query.keyName, scopedVars) : '',
query: query.query ? templateSrv.replace(query.query, scopedVars) : '',
field: query.field ? templateSrv.replace(query.field, scopedVars) : '',
filter: query.filter ? templateSrv.replace(query.filter, scopedVars) : '',
Expand Down
2 changes: 1 addition & 1 deletion src/redis/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const CommandParameters = {
aggregation: ['ts.range', 'ts.mrange'],
field: ['hget','hmget'],
filter: ['ts.mrange', 'ts.queryindex'],
key: [
keyName: [
'get',
'hget',
'hgetall',
Expand Down
2 changes: 1 addition & 1 deletion src/redis/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface RedisQuery extends DataQuery {
*
* @type {string}
*/
key?: string;
keyName?: string;

/**
* Value label
Expand Down