Skip to content

Commit e50b5b1

Browse files
author
Stephen McCann
committed
add front end async postback function (This is a port of PR #30)
1 parent 2fb06e8 commit e50b5b1

5 files changed

Lines changed: 121 additions & 7 deletions

File tree

src/QueryEditor.tsx

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ type State = {
5656
firstWhere: boolean;
5757
whereOperators: SelectableValue<string>[];
5858
groupBy: string;
59+
useAsyncFunction: boolean;
60+
asyncField: string;
61+
useCustomPostback: boolean;
62+
postbackFunction: string;
5963
};
6064

6165
type WhereSegment = {
@@ -175,6 +179,10 @@ export class QueryEditor extends PureComponent<Props, State> {
175179
firstWhere: true,
176180
selectSegments: selectSegments,
177181
groupBy: query.groupingField,
182+
asyncField: query.asyncProcTypes,
183+
useAsyncFunction: query.useAsyncFunction,
184+
useCustomPostback: query.useCustomPostback,
185+
postbackFunction: query.postbackFunction,
178186
};
179187
// run the default query immediately to get default look
180188
onRunQuery();
@@ -809,7 +817,40 @@ export class QueryEditor extends PureComponent<Props, State> {
809817

810818
return values;
811819
}
820+
useAsyncFunction(checked){
821+
const { onChange, query, onRunQuery } = this.props;
822+
if(!checked){
823+
onChange({ ...query, useAsyncFunction: checked });
824+
onRunQuery();
825+
this.setState({ useAsyncFunction: checked });
826+
}else{
827+
onChange({ ...query, useAsyncFunction: checked, asyncProcTypes: '' });
828+
onRunQuery();
829+
this.setState({ useAsyncFunction: checked, asyncField: '' });
830+
}
831+
}
832+
833+
asyncFieldChanged(asyncField){
834+
const { onChange, query, onRunQuery } = this.props;
835+
836+
onChange({ ...query, asyncProcTypes: asyncField});
837+
onRunQuery();
838+
839+
this.setState({asyncField: asyncField})
840+
}
812841

842+
useCustomPostback(checked){
843+
const { onChange, query, onRunQuery } = this.props;
844+
if(!checked){
845+
onChange({ ...query, useCustomPostback: checked });
846+
onRunQuery();
847+
this.setState({ useCustomPostback: checked });
848+
}else{
849+
onChange({ ...query, useCustomPostback: checked, postbackFunction: '' });
850+
onRunQuery();
851+
this.setState({ useCustomPostback: checked, postbackFunction: '' });
852+
}
853+
}
813854

814855
render() {
815856

@@ -1108,10 +1149,63 @@ export class QueryEditor extends PureComponent<Props, State> {
11081149
)}
11091150
{this.state.queryTypeStr && this.state.queryTypeStr !== 'kdbSideQuery' && (
11101151
<div>
1152+
{this.state.queryTypeStr && this.state.queryTypeStr == 'functionQuery' && (
1153+
<div>
1154+
<div className="gf-form-inline">
1155+
<div className="gf-form">
1156+
<InlineFormLabel className="gf-form-label query-keyword width-15" tooltip="This allows use of asynchronous functions provided they utilise a postback function. Enable 'Custom Postback' if using non-TorQ Gateway.">
1157+
<span>
1158+
<input type="checkbox" className="width-2" checked={this.state.useAsyncFunction} onChange={(e) => this.useAsyncFunction(e.currentTarget.checked)}/>
1159+
</span>Use Async with Postback</InlineFormLabel>
1160+
</div>
1161+
{this.state.useAsyncFunction && (
1162+
<div className="gf-form">
1163+
<InlineFormLabel className="query-keyword">Proc Types:</InlineFormLabel>
1164+
<SegmentInput
1165+
placeholder="Proc"
1166+
value={this.state.asyncField || ''}
1167+
onChange={(e: string) => {
1168+
this.asyncFieldChanged(e);
1169+
}}
1170+
/>
1171+
</div>
1172+
)}
1173+
{this.state.useAsyncFunction && (
1174+
<div className="gf-form">
1175+
<InlineFormLabel className="gf-form-label query-keyword width-15" tooltip="This allows use of asynchronous functions provided they utilise a postback function. Enable 'Custom Postback' if using non-TorQ Gateway.">
1176+
<span>
1177+
<input type="checkbox" className="width-2" checked={this.state.useCustomPostback} onChange={(e) => this.useCustomPostback(e.currentTarget.checked)}/>
1178+
</span>Custom Postback</InlineFormLabel>
1179+
</div>
1180+
)}
1181+
<div className="gf-form gf-form--grow">
1182+
<div className="gf-form-label gf-form-label--grow"></div>
1183+
</div>
1184+
</div>
1185+
{this.state.useAsyncFunction && this.state.useCustomPostback && (
1186+
<div className="gf-form-inline" style={{ height: '111px;'}}>
1187+
<span className="gf-form-label query-keyword width-10" style={{ height: '111px' }}/>
1188+
<div style={{ height: '111px;'}}>
1189+
<textarea
1190+
className="gf-form-textarea width-30"
1191+
rows={5}
1192+
style={{ background: '#0b0c0e' }}
1193+
value={this.state.postbackFunction}
1194+
placeholder="Enter custom postback function"
1195+
onChange={this.asyncFieldChanged}
1196+
/>
1197+
</div>
1198+
<div className="gf-form gf-form--grow">
1199+
<div className="gf-form-label gf-form-label--grow" style={{ height: '111px'}}></div>
1200+
</div>
1201+
</div>
1202+
)}
1203+
</div>
1204+
)}
11111205
{this.state.formatAs && this.state.formatAs !== 'table' && (
11121206
<div className="gf-form-inline">
11131207
<div className="gf-form">
1114-
<InlineFormLabel className="gf-form-label query-keyword width-13" tooltip="Used to separate selected data into relevant groups. The column specified is the one which contains the groups by which you wish to separate your data.">
1208+
<InlineFormLabel className="gf-form-label query-keyword width-15" tooltip="Used to separate selected data into relevant groups. The column specified is the one which contains the groups by which you wish to separate your data.">
11151209
<span>
11161210
<input type="checkbox" className="width-2" checked={this.state.useGrouping} onChange={(e) => this.useGrouping(e.currentTarget.checked)}/>
11171211
</span>Use Grouping</InlineFormLabel>
@@ -1134,7 +1228,7 @@ export class QueryEditor extends PureComponent<Props, State> {
11341228
)}
11351229
<div className="gf-form-inline">
11361230
<div className="gf-form" style={{wordBreak: 'break-word', textAlign: 'right'}}>
1137-
<InlineFormLabel className="gf-form-label query-keyword width-13" tooltip="Used to enable a date/time column, acting as a key for each record.">
1231+
<InlineFormLabel className="gf-form-label query-keyword width-15" tooltip="Used to enable a date/time column, acting as a key for each record.">
11381232
<span>
11391233
<input type="checkbox" className="width-2" checked={this.state.useTemporalField} onChange={(e) => this.useTemporalField(e.currentTarget.checked)}/>
11401234
</span>Use Temporal Field</InlineFormLabel>
@@ -1155,7 +1249,7 @@ export class QueryEditor extends PureComponent<Props, State> {
11551249
{this.state.useTemporalField && (
11561250
<div className="gf-form-inline">
11571251
<div className="gf-form">
1158-
<InlineFormLabel className="gf-form-label query-keyword width-13" tooltip="The time series data is divided into 'buckets' of time, then reduced to a single point for each interval bucket.">
1252+
<InlineFormLabel className="gf-form-label query-keyword width-15" tooltip="The time series data is divided into 'buckets' of time, then reduced to a single point for each interval bucket.">
11591253
<span>
11601254
<input type="checkbox" className="width-2" checked={this.state.useConflation} onChange={(e) => this.useConflation(e.currentTarget.checked)}/>
11611255
</span>Use Conflation</InlineFormLabel>
@@ -1305,7 +1399,7 @@ export class QueryEditor extends PureComponent<Props, State> {
13051399
// <div className="gf-form">
13061400
// <pre className="gf-form-pre alert alert-error">{error.message}</pre>
13071401
// </div>
1308-
)}
1402+
)}
13091403
</div>
13101404
);
13111405
}

src/datasource.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ private buildKdbRequest(target) {
367367
queryParam.column = this.buildColumnParams(target);
368368
queryParam.temporal_field = target.useTemporalField ? this.buildTemporalField(target) : [];
369369
queryParam.temporal_range = this.buildTemporalRange(target.range);
370-
queryParam.maxRowCount = target.rowCountLimit
370+
queryParam.maxRowCount = target.rowCountLimit;
371+
if(target.postbackFunction)
372+
queryParam.postbackFunction = target.postbackFunction;
371373

372374
if (target.queryType == 'selectQuery') queryParam.where = this.buildWhereParams( (target.where) ? target.where : []);
373375
//conflation
@@ -400,6 +402,12 @@ private buildKdbRequest(target) {
400402
kdbRequest.format = target.format;
401403
kdbRequest.queryId = target.queryId;
402404
kdbRequest.version = target.version;
405+
if(target.useAsyncFunction)
406+
kdbRequest.useAsyncFunction = target.useAsyncFunction;
407+
if(target.useCustomPostback)
408+
kdbRequest.useCustomPostback = target.useCustomPostback;
409+
if(target.asyncProcTypes)
410+
kdbRequest.asyncProcTypes = target.asyncProcTypes;
403411

404412
return [
405413
((target.format == 'time series') ? graphFunction : tabFunction),

src/model/kdb-request.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ export class KdbRequest {
88
query: string;
99
queryParam: QueryParam;
1010
format: string;
11-
version: string;
11+
version: string;
12+
useAsyncFunction: boolean;
13+
useCustomPostback: boolean;
14+
asyncProcTypes: string;
1215
}

src/model/query-param.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export class QueryParam {
1919
conflation: any;
2020
query: QueryDictionary;
2121
maxRowCount: number | string;
22+
postbackFunction: string;
2223
}

src/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export interface MyQuery extends DataQuery {
3232
rowCountLimit: number
3333
version: any
3434
error: string
35+
useAsyncFunction: boolean
36+
useCustomPostback: boolean
37+
asyncProcTypes: string
38+
postbackFunction: string
3539
}
3640

3741
export const defaultQuery: Partial<MyQuery> = {
@@ -57,7 +61,11 @@ export const defaultQuery: Partial<MyQuery> = {
5761
where: [] = [],
5862
select: [] = [],
5963
error: '',
60-
lastQueryError: ''
64+
lastQueryError: '',
65+
useAsyncFunction: false,
66+
useCustomPostback: false,
67+
asyncProcTypes: '',
68+
postbackFunction: ''
6169
};
6270

6371
type Select = {

0 commit comments

Comments
 (0)