Skip to content

Commit ec42740

Browse files
committed
fix: no selection made msg when clicking search btn in trees
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
1 parent b370c14 commit ec42740

4 files changed

Lines changed: 127 additions & 76 deletions

File tree

packages/zowe-explorer/__tests__/__unit__/trees/job/JobTree.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,3 +2337,20 @@ describe("openWithEncoding", () => {
23372337
expect(promptMock).toHaveBeenCalledTimes(1);
23382338
});
23392339
});
2340+
2341+
describe("ZosJobsProvider unit tests - Function searchPrompt", () => {
2342+
it("should return early and not open a prompt if inFilterPrompt is already true", async () => {
2343+
const globalMocks = await createGlobalMocks();
2344+
const node = globalMocks.testSessionNode;
2345+
2346+
node.inFilterPrompt = true;
2347+
2348+
vi.spyOn(globalMocks.testJobsProvider, "checkCurrentProfile").mockResolvedValue(undefined);
2349+
const getUserJobsMenuChoiceSpy = vi.spyOn(globalMocks.testJobsProvider, "getUserJobsMenuChoice").mockClear();
2350+
2351+
await globalMocks.testJobsProvider.searchPrompt(node);
2352+
2353+
expect(getUserJobsMenuChoiceSpy).not.toHaveBeenCalled();
2354+
expect(node.inFilterPrompt).toBe(true); // Should remain true
2355+
});
2356+
});

packages/zowe-explorer/__tests__/__unit__/trees/uss/USSTree.unit.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,22 @@ describe("USSTree Unit Tests - Function filterPrompt", () => {
11031103
});
11041104
expect(updateTreeViewSpy).not.toHaveBeenCalled();
11051105
});
1106+
1107+
it("should return early and not open a prompt if inFilterPrompt is already true", async () => {
1108+
const globalMocks = createGlobalMocks();
1109+
const node = globalMocks.testTree.mSessionNodes[1];
1110+
1111+
node.inFilterPrompt = true;
1112+
1113+
const createQuickPickSpy = vi.spyOn(Gui, "createQuickPick").mockClear();
1114+
const showInputBoxSpy = vi.spyOn(Gui, "showInputBox").mockClear();
1115+
1116+
await globalMocks.testTree.filterPrompt(node);
1117+
1118+
expect(createQuickPickSpy).not.toHaveBeenCalled();
1119+
expect(showInputBoxSpy).not.toHaveBeenCalled();
1120+
expect(node.inFilterPrompt).toBe(true); // Should remain true
1121+
});
11061122
});
11071123

11081124
describe("USSTree Unit Tests - Function filterBy", () => {

packages/zowe-explorer/src/trees/job/JobTree.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -832,47 +832,56 @@ Would you like to do this now?`,
832832
}
833833

834834
if (isSessionNotFav) {
835-
searchCriteria = await this.applyRegularSessionSearchLabel(node);
836-
837-
if (searchCriteria != null) {
838-
node.filtered = true;
839-
node.label = node.getProfileName();
840-
node.description = searchCriteria;
841-
node.dirty = true;
842-
const toolTipList = (node.tooltip as string).split("\n");
843-
switch (true) {
844-
case searchCriteria.includes(vscode.l10n.t("Owner: ")): {
845-
const jobIdIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("JobId: ")));
846-
if (jobIdIndex !== -1) {
847-
toolTipList.splice(jobIdIndex, 1);
848-
}
835+
if (node.inFilterPrompt) {
836+
ZoweLogger.debug("[JobTree.searchPrompt] Cancelled because filter prompt is already open for this node");
837+
return;
838+
}
839+
node.inFilterPrompt = true;
840+
try {
841+
searchCriteria = await this.applyRegularSessionSearchLabel(node);
842+
843+
if (searchCriteria != null) {
844+
node.filtered = true;
845+
node.label = node.getProfileName();
846+
node.description = searchCriteria;
847+
node.dirty = true;
848+
const toolTipList = (node.tooltip as string).split("\n");
849+
switch (true) {
850+
case searchCriteria.includes(vscode.l10n.t("Owner: ")): {
851+
const jobIdIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("JobId: ")));
852+
if (jobIdIndex !== -1) {
853+
toolTipList.splice(jobIdIndex, 1);
854+
}
849855

850-
const searchCriteriaIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("Owner: ")));
851-
if (searchCriteriaIndex === -1) {
852-
toolTipList.push(searchCriteria);
853-
} else {
854-
toolTipList[searchCriteriaIndex] = searchCriteria;
855-
}
856-
break;
857-
}
858-
case searchCriteria.includes(vscode.l10n.t("JobId: ")): {
859-
const searchFilterIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("Owner: ")));
860-
if (searchFilterIndex !== -1) {
861-
toolTipList.splice(searchFilterIndex, 1);
856+
const searchCriteriaIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("Owner: ")));
857+
if (searchCriteriaIndex === -1) {
858+
toolTipList.push(searchCriteria);
859+
} else {
860+
toolTipList[searchCriteriaIndex] = searchCriteria;
861+
}
862+
break;
862863
}
864+
case searchCriteria.includes(vscode.l10n.t("JobId: ")): {
865+
const searchFilterIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("Owner: ")));
866+
if (searchFilterIndex !== -1) {
867+
toolTipList.splice(searchFilterIndex, 1);
868+
}
863869

864-
const jobIdIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("JobId: ")));
865-
if (jobIdIndex === -1) {
866-
toolTipList.push(searchCriteria);
867-
} else {
868-
toolTipList[jobIdIndex] = searchCriteria;
870+
const jobIdIndex = toolTipList.findIndex((key) => key.startsWith(vscode.l10n.t("JobId: ")));
871+
if (jobIdIndex === -1) {
872+
toolTipList.push(searchCriteria);
873+
} else {
874+
toolTipList[jobIdIndex] = searchCriteria;
875+
}
876+
break;
869877
}
870-
break;
871878
}
879+
node.tooltip = toolTipList.join("\n");
880+
this.addSearchHistory(searchCriteria);
881+
await TreeViewUtils.expandNode(node, this);
872882
}
873-
node.tooltip = toolTipList.join("\n");
874-
this.addSearchHistory(searchCriteria);
875-
await TreeViewUtils.expandNode(node, this);
883+
} finally {
884+
node.inFilterPrompt = false;
876885
}
877886
} else {
878887
if (isExpanded) {

packages/zowe-explorer/src/trees/uss/USSTree.ts

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -879,40 +879,58 @@ export class USSTree extends ZoweTreeProvider<IZoweUSSTreeNode> implements Types
879879
if (Profiles.getInstance().validProfile !== Validation.ValidationType.INVALID) {
880880
let remotepath: string;
881881
if (SharedContext.isSessionNotFav(node)) {
882-
ZoweLogger.debug(vscode.l10n.t("Prompting the user for a USS path"));
883-
if (this.mPersistence.getSearchHistory().length > 0) {
884-
const items: vscode.QuickPickItem[] = this.mPersistence.getSearchHistory().map((element) => new FilterItem({ text: element }));
885-
const quickpick = Gui.createQuickPick();
886-
quickpick.placeholder = vscode.l10n.t("Select a filter or type to create a new one");
887-
quickpick.ignoreFocusOut = true;
888-
889-
// Callback updates the "Create a new filter" option as user types
890-
quickpick.onDidChangeValue((value) => {
891-
const trimmedValue = value.trim();
892-
const createPick = trimmedValue
893-
? new FilterDescriptor(`$(plus) ${vscode.l10n.t("Create a new filter")}: "${value.trim()}"`)
894-
: new FilterDescriptor(USSTree.defaultDialogText);
882+
if (node.inFilterPrompt) {
883+
ZoweLogger.debug("[USSTree.filterPrompt] Cancelled because filter prompt is already open for this node");
884+
return;
885+
}
886+
node.inFilterPrompt = true;
887+
try {
888+
ZoweLogger.debug(vscode.l10n.t("Prompting the user for a USS path"));
889+
if (this.mPersistence.getSearchHistory().length > 0) {
890+
const items: vscode.QuickPickItem[] = this.mPersistence.getSearchHistory().map((element) => new FilterItem({ text: element }));
891+
const quickpick = Gui.createQuickPick();
892+
quickpick.placeholder = vscode.l10n.t("Select a filter or type to create a new one");
893+
quickpick.ignoreFocusOut = true;
894+
895+
// Callback updates the "Create a new filter" option as user types
896+
quickpick.onDidChangeValue((value) => {
897+
const trimmedValue = value.trim();
898+
const createPick = trimmedValue
899+
? new FilterDescriptor(`$(plus) ${vscode.l10n.t("Create a new filter")}: "${value.trim()}"`)
900+
: new FilterDescriptor(USSTree.defaultDialogText);
901+
quickpick.items = [createPick, Constants.SEPARATORS.RECENT_FILTERS, ...items];
902+
});
903+
904+
const createPick = new FilterDescriptor(USSTree.defaultDialogText);
895905
quickpick.items = [createPick, Constants.SEPARATORS.RECENT_FILTERS, ...items];
896-
});
897-
898-
const createPick = new FilterDescriptor(USSTree.defaultDialogText);
899-
quickpick.items = [createPick, Constants.SEPARATORS.RECENT_FILTERS, ...items];
900906

901-
quickpick.show();
902-
const choice = await Gui.resolveQuickPick(quickpick);
903-
quickpick.hide();
904-
if (!choice) {
905-
Gui.showMessage(vscode.l10n.t("No selection made. Operation cancelled."));
906-
return;
907-
}
908-
if (choice instanceof FilterDescriptor) {
909-
// If user typed something and selected "Create a new filter", use that input
910-
if (quickpick.value && quickpick.value.trim()) {
911-
remotepath = quickpick.value.trim();
907+
quickpick.show();
908+
const choice = await Gui.resolveQuickPick(quickpick);
909+
quickpick.hide();
910+
if (!choice) {
911+
Gui.showMessage(vscode.l10n.t("No selection made. Operation cancelled."));
912+
return;
913+
}
914+
if (choice instanceof FilterDescriptor) {
915+
// If user typed something and selected "Create a new filter", use that input
916+
if (quickpick.value && quickpick.value.trim()) {
917+
remotepath = quickpick.value.trim();
918+
} else {
919+
// Fall back to input box if no text was entered
920+
const options: vscode.InputBoxOptions = {
921+
placeHolder: vscode.l10n.t("New filter"),
922+
validateInput: (input: string) => (input.length > 0 ? null : vscode.l10n.t("Please enter a valid USS path.")),
923+
};
924+
remotepath = await Gui.showInputBox(options);
925+
if (remotepath == null) {
926+
return;
927+
}
928+
}
912929
} else {
913-
// Fall back to input box if no text was entered
930+
// User selected an existing filter - show input box with the filter pre-filled for editing
914931
const options: vscode.InputBoxOptions = {
915932
placeHolder: vscode.l10n.t("New filter"),
933+
value: choice.label, // Pre-fill with the selected filter
916934
validateInput: (input: string) => (input.length > 0 ? null : vscode.l10n.t("Please enter a valid USS path.")),
917935
};
918936
remotepath = await Gui.showInputBox(options);
@@ -921,27 +939,18 @@ export class USSTree extends ZoweTreeProvider<IZoweUSSTreeNode> implements Types
921939
}
922940
}
923941
} else {
924-
// User selected an existing filter - show input box with the filter pre-filled for editing
942+
// No search history, use input box directly
925943
const options: vscode.InputBoxOptions = {
926944
placeHolder: vscode.l10n.t("New filter"),
927-
value: choice.label, // Pre-fill with the selected filter
928945
validateInput: (input: string) => (input.length > 0 ? null : vscode.l10n.t("Please enter a valid USS path.")),
929946
};
930947
remotepath = await Gui.showInputBox(options);
931948
if (remotepath == null) {
932949
return;
933950
}
934951
}
935-
} else {
936-
// No search history, use input box directly
937-
const options: vscode.InputBoxOptions = {
938-
placeHolder: vscode.l10n.t("New filter"),
939-
validateInput: (input: string) => (input.length > 0 ? null : vscode.l10n.t("Please enter a valid USS path.")),
940-
};
941-
remotepath = await Gui.showInputBox(options);
942-
if (remotepath == null) {
943-
return;
944-
}
952+
} finally {
953+
node.inFilterPrompt = false;
945954
}
946955
} else {
947956
// executing search from saved search in favorites

0 commit comments

Comments
 (0)