Skip to content

Commit a51c8ff

Browse files
Merge pull request #533 from KxSystems/KXI-58282
Kxi 58282 - Run UDAs with optional parameters not defined in getMeta
2 parents 0acb809 + 99b2e7f commit a51c8ff

File tree

7 files changed

+243
-32
lines changed

7 files changed

+243
-32
lines changed

src/commands/dataSourceCommand.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ export async function runDataSource(
228228
`[DATASOURCE] Results is a string with length: ${res.length}`,
229229
"INFO",
230230
);
231-
} else if (res.errorMsg) {
232-
res = res.errorMsg;
231+
} else if (res.error) {
232+
res = res.errorMsg ? res.errorMsg : res.error;
233233
}
234234

235235
await writeQueryResultsToConsole(
@@ -510,6 +510,8 @@ export function getQuery(
510510
return `GetData - table: ${fileContent.dataSource.api.table}`;
511511
case "QSQL":
512512
return fileContent.dataSource.qsql.query;
513+
case "UDA":
514+
return `Executed UDA: ${fileContent.dataSource.uda?.name}`;
513515
case "SQL":
514516
default:
515517
return fileContent.dataSource.sql.query;

src/models/uda.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface UDAParam {
3838
selectedMultiTypeString?: string;
3939
value?: any;
4040
isVisible?: boolean;
41+
isDistinguised?: boolean;
4142
}
4243

4344
export interface UDAReturn {

src/utils/queryUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export function checkIfIsDatasource(
316316
if (dataSourceType === undefined) {
317317
return false;
318318
}
319-
const validTypes = ["API", "QSQL", "SQL"];
319+
const validTypes = ["API", "QSQL", "SQL", "UDA"];
320320
return validTypes.includes(dataSourceType);
321321
}
322322

src/webview/components/kdbDataSourceView.ts

Lines changed: 137 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,74 @@ import {
3434
import { MetaObjectPayload } from "../../models/meta";
3535
import { DataSourceCommand, DataSourceMessage2 } from "../../models/messages";
3636
import { dataSourceStyles, kdbStyles, shoelaceStyles } from "./styles";
37-
import { UDA, UDAParam } from "../../models/uda";
37+
import { ParamFieldType, UDA, UDAParam } from "../../models/uda";
3838

3939
const MAX_RULES = 32;
40+
const UDA_DISTINGUISED_PARAMS: UDAParam[] = [
41+
{
42+
name: "table",
43+
description: "Table to target.",
44+
isReq: false,
45+
type: [-11],
46+
isVisible: false,
47+
fieldType: ParamFieldType.Text,
48+
isDistinguised: true,
49+
},
50+
{
51+
name: "labels",
52+
description: "A dictionary describing DAP labels to target,",
53+
isReq: false,
54+
type: [99],
55+
isVisible: false,
56+
fieldType: ParamFieldType.JSON,
57+
isDistinguised: true,
58+
},
59+
{
60+
name: "scope",
61+
description: "A dictionary describing what RC and/or DAPs to target.",
62+
isReq: false,
63+
type: [99],
64+
fieldType: ParamFieldType.JSON,
65+
isDistinguised: true,
66+
},
67+
{
68+
name: "startTS",
69+
description: "Inclusive start time of the request.",
70+
isReq: false,
71+
type: [-19],
72+
isVisible: false,
73+
fieldType: ParamFieldType.Timestamp,
74+
isDistinguised: true,
75+
},
76+
{
77+
name: "endTS",
78+
description: "Exclusive end time of the request.",
79+
isReq: false,
80+
type: [-19],
81+
isVisible: false,
82+
fieldType: ParamFieldType.Timestamp,
83+
isDistinguised: true,
84+
},
85+
{
86+
name: "inputTZ",
87+
description: "Timezone of startTS and endTS (default: UTC).",
88+
isReq: false,
89+
type: [-11],
90+
isVisible: false,
91+
fieldType: ParamFieldType.Text,
92+
isDistinguised: true,
93+
},
94+
{
95+
name: "outputTZ",
96+
description:
97+
"Timezone of the final result (.kxi.getData only). No effect on routing.",
98+
isReq: false,
99+
type: [-11],
100+
isVisible: false,
101+
fieldType: ParamFieldType.Text,
102+
isDistinguised: true,
103+
},
104+
];
40105

41106
@customElement("kdb-data-source-view")
42107
export class KdbDataSourceView extends LitElement {
@@ -954,7 +1019,6 @@ export class KdbDataSourceView extends LitElement {
9541019
${this.renderUDAOptions()}
9551020
</sl-select>
9561021
${this.renderUDADetails()} ${this.renderUDAParams()}
957-
${this.userSelectedUDA ? this.renderUDAAddParamButton() : null}
9581022
</div>
9591023
`;
9601024
}
@@ -1015,26 +1079,36 @@ export class KdbDataSourceView extends LitElement {
10151079
const visibleParams = this.renderVisibleUDAParams();
10161080
const noParams = this.renderUDANoParams();
10171081
const invalidParams = this.renderUDAInvalidParams();
1082+
const addParamsBtn = this.renderUDAAddParamButton();
10181083

10191084
if (invalidParams) {
10201085
params.push(invalidParams);
10211086
} else {
1022-
params.push(...(visibleParams.length ? visibleParams : [noParams]));
1087+
params.push(
1088+
...(visibleParams.length ? visibleParams : [noParams]),
1089+
...[addParamsBtn],
1090+
);
10231091
}
10241092

10251093
return params;
10261094
}
10271095

10281096
renderUDAAddParamButton() {
10291097
return html`
1030-
<sl-dropdown
1031-
class="udaDropdown"
1032-
@sl-select="${this.handleUDAAddParamSelect}">
1033-
<sl-button slot="trigger" variant="neutral" class="width-200-px" caret>
1034-
+ Add Parameter
1035-
</sl-button>
1036-
${this.renderUDAAddParamBtnOptions()}
1037-
</sl-dropdown>
1098+
<div class="width-98-pct">
1099+
<sl-dropdown
1100+
class="udaDropdown width-30-pct"
1101+
@sl-select="${this.handleUDAAddParamSelect}">
1102+
<sl-button
1103+
slot="trigger"
1104+
class="width-100-pct"
1105+
variant="neutral"
1106+
caret>
1107+
+ Add Parameter
1108+
</sl-button>
1109+
${this.renderUDAAddParamBtnOptions()}
1110+
</sl-dropdown>
1111+
</div>
10381112
`;
10391113
}
10401114

@@ -1051,7 +1125,7 @@ export class KdbDataSourceView extends LitElement {
10511125

10521126
renderUDAAddParamBtnOptions() {
10531127
return html`
1054-
<sl-menu class="width-200-px">
1128+
<sl-menu class="width-100-pct">
10551129
${this.renderUDAOptionalParamsOpts()}
10561130
</sl-menu>
10571131
`;
@@ -1064,26 +1138,61 @@ export class KdbDataSourceView extends LitElement {
10641138
`;
10651139
}
10661140

1141+
const optParamTxtHtml = html`
1142+
<small class="btn-opt-text"><strong>OPTIONAL PARAMETERS:</strong></small>
1143+
`;
1144+
const distParamTxtHtml = html`
1145+
<small class="btn-opt-text"
1146+
><strong>DISTINGUISHED PARAMETERS:</strong></small
1147+
>
1148+
`;
1149+
10671150
const optionalParams = this.userSelectedUDA.params.filter(
10681151
(param) => !param.isReq,
10691152
);
1153+
const filteredDistinguisedParam = UDA_DISTINGUISED_PARAMS.filter(
1154+
(param) =>
1155+
!optionalParams.some(
1156+
(optionalParam) => param.name === optionalParam.name,
1157+
),
1158+
);
10701159

1071-
if (optionalParams.length === 0) {
1072-
return html`
1073-
<sl-menu-item disabled>No optional parameters available</sl-menu-item>
1074-
`;
1160+
const renderParams = (params: any[]) =>
1161+
params.map(
1162+
(param: {
1163+
isVisible: unknown;
1164+
name: unknown;
1165+
description: unknown;
1166+
}) => html`
1167+
<sl-menu-item
1168+
.type=${param.isVisible ? "checkbox" : "normal"}
1169+
.disabled=${!!param.isVisible}
1170+
.value=${param.name as string}>
1171+
${param.name}<br /><small>${param.description}</small>
1172+
</sl-menu-item>
1173+
`,
1174+
);
1175+
1176+
const optionalParamsHtml = [
1177+
optParamTxtHtml,
1178+
...(optionalParams.length
1179+
? renderParams(optionalParams)
1180+
: [
1181+
html`<sl-menu-item disabled
1182+
>No optional parameters available</sl-menu-item
1183+
>`,
1184+
]),
1185+
];
1186+
1187+
if (filteredDistinguisedParam.length > 0) {
1188+
optionalParamsHtml.push(
1189+
html`<hr class="btn-opt-divider" />`,
1190+
distParamTxtHtml,
1191+
...renderParams(filteredDistinguisedParam),
1192+
);
10751193
}
10761194

1077-
return optionalParams.map(
1078-
(param) => html`
1079-
<sl-menu-item
1080-
.type=${param.isVisible ? "checkbox" : "normal"}
1081-
.disabled=${param.isVisible === true}
1082-
.value=${param.name}>
1083-
${param.name}<br /><small>${param.description}</small>
1084-
</sl-menu-item>
1085-
`,
1086-
);
1195+
return optionalParamsHtml;
10871196
}
10881197

10891198
renderDeleteUDAParamButton(param: UDAParam) {
@@ -1115,7 +1224,7 @@ export class KdbDataSourceView extends LitElement {
11151224
multitype: "multitype",
11161225
text: "text",
11171226
};
1118-
return inputTypes[type || "text"] || "text";
1227+
return inputTypes[type ?? "text"] || "text";
11191228
}
11201229

11211230
renderVisibleUDAParams() {
@@ -1200,7 +1309,7 @@ export class KdbDataSourceView extends LitElement {
12001309
<sl-select
12011310
class="reset-widths-limit width-30-pct"
12021311
label="${param.name}"
1203-
.helpText="Select a type"
1312+
help-text="Select a type"
12041313
.value="${live(value)}"
12051314
@sl-change="${(event: Event) => {
12061315
param.selectedMultiTypeString = (

src/webview/components/styles.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ export const dataSourceStyles = css`
164164
margin-top: 28px;
165165
}
166166
167+
.btn-opt-text {
168+
margin-left: 1rem;
169+
}
170+
171+
.btn-opt-divider {
172+
border: solid var(--sl-panel-border-width) var(--vscode-focusBorder) !important;
173+
}
174+
167175
sl-menu {
168176
border: solid var(--sl-panel-border-width) var(--vscode-focusBorder) !important;
169177
}
@@ -325,6 +333,10 @@ export const kdbStyles = css`
325333
width: 97%;
326334
}
327335
336+
.width-98-pct {
337+
width: 98%;
338+
}
339+
328340
.width-100-pct {
329341
width: 100%;
330342
}

test/suite/services.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,6 @@ describe("queryHistoryProvider", () => {
10171017
TreeItemCollapsibleState.None,
10181018
);
10191019
const result = queryHistoryTreeItem.defineQueryIcon(true);
1020-
console.log(JSON.stringify(queryHistoryTreeItem));
10211020
assert.strictEqual(
10221021
result,
10231022
sucessIcon,

test/suite/webview.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,94 @@ describe("KdbDataSourceView", () => {
825825
assert.ok(!result);
826826
});
827827
});
828+
829+
describe("renderUDAOptionalParamsOpts", () => {
830+
it("should return 'No optional parameters available' if userSelectedUDA is not set", () => {
831+
view.userSelectedUDA = undefined;
832+
const result = view.renderUDAOptionalParamsOpts();
833+
assert.strictEqual(Array.isArray(result) ? result.length : 0, 0);
834+
const resultString = Array.isArray(result)
835+
? result.map((item) => item.strings.join("")).join("")
836+
: result.strings.join("");
837+
assert.ok(resultString.includes("No optional parameters available"));
838+
});
839+
840+
it("should return 'No optional parameters available' if there are no optional parameters", () => {
841+
view.userSelectedUDA = {
842+
name: "test",
843+
description: "test description",
844+
params: [
845+
{
846+
name: "param",
847+
type: 10,
848+
description: "param description",
849+
isReq: true,
850+
},
851+
],
852+
return: {
853+
type: ["99"],
854+
description: "test return description",
855+
},
856+
};
857+
const result = view.renderUDAOptionalParamsOpts();
858+
assert.strictEqual(Array.isArray(result) ? result.length : 0, 11);
859+
const resultString = Array.isArray(result)
860+
? result.map((item) => item.strings.join("")).join("")
861+
: result.strings.join("");
862+
assert.ok(resultString.includes("No optional parameters available"));
863+
});
864+
865+
it("should render optional parameters if they exist", () => {
866+
view.userSelectedUDA = {
867+
name: "test",
868+
description: "test description",
869+
params: [
870+
{
871+
name: "optionalParam",
872+
type: 10,
873+
description: "optional param description",
874+
isReq: false,
875+
},
876+
],
877+
return: {
878+
type: ["99"],
879+
description: "test return description",
880+
},
881+
};
882+
const result = view.renderUDAOptionalParamsOpts();
883+
assert.strictEqual(Array.isArray(result) ? result.length : 0, 11);
884+
const resultString = Array.isArray(result)
885+
? result.map((item) => item.strings.join("")).join("")
886+
: result.strings.join("");
887+
assert.ok(resultString.includes("OPTIONAL PARAMETERS"));
888+
});
889+
890+
it("should render distinguished parameters if they exist", () => {
891+
view.userSelectedUDA = {
892+
name: "test",
893+
description: "test description",
894+
params: [
895+
{
896+
name: "optionalParam",
897+
type: 10,
898+
description: "optional param description",
899+
isReq: false,
900+
},
901+
],
902+
return: {
903+
type: ["99"],
904+
description: "test return description",
905+
},
906+
};
907+
const result = view.renderUDAOptionalParamsOpts();
908+
assert.strictEqual(Array.isArray(result) ? result.length : 0, 11);
909+
const resultString = Array.isArray(result)
910+
? result.map((item) => item.strings.join("")).join("")
911+
: result.strings.join("");
912+
913+
assert.ok(resultString.includes("DISTINGUISHED PARAMETERS:"));
914+
});
915+
});
828916
});
829917

830918
describe("KdbNewConnectionView", () => {

0 commit comments

Comments
 (0)