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

AXON-193: make customJqlTreeView only visible when user has custom JQLs + fix bug + add util tests #194

Merged
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
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module.exports = {
projects: ['<rootDir>/jest.react.config.js', '<rootDir>/jest.unit.config.js'],
verbose: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'],
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.{spec,test}.{ts,tsx,js,jsx}', // Exclude test files
],
coverageDirectory: 'coverage',
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
};
31 changes: 19 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@
"category": "Atlassian"
},
{
"command": "atlascode.jira.removeFromSidebar",
"title": "Remove from sidebar",
"category": "Atlassian"
"command": "atlascode.jira.addJiraSite",
"title": "Add Jira Site",
"category": "Atlassian",
"shortTitle": "Add another Jira site"
},
{
"command": "atlascode.jira.refreshAssignedWorkItemsExplorer",
Expand All @@ -254,7 +255,9 @@
"dark": "resources/dark/settings.svg",
"light": "resources/light/settings.svg"
},
"category": "Atlassian"
"category": "Atlassian",
"shortTitle": "View settings"

},
{
"command": "atlascode.jira.showIssueForKey",
Expand Down Expand Up @@ -489,12 +492,12 @@
{
"id": "atlascode.views.jira.assignedWorkItemsTreeView",
"name": "Assigned Jira Work Items",
"when": "config.atlascode.jira.enabled && atlascode:customJQLExplorerEnabled"
"when": "atlascode:assignedIssueExplorerEnabled && config.atlascode.jira.enabled"
},
{
"id": "atlascode.views.jira.customJqlTreeView",
"name": "Custom Jql Filters",
"when": "config.atlascode.jira.enabled && atlascode:customJQLExplorerEnabled"
"when": "atlascode:assignedIssueExplorerEnabled && config.atlascode.jira.enabled && atlascode:customJQLExplorerEnabled"
},
{
"id": "atlascode.views.bb.pullrequestsTreeView",
Expand Down Expand Up @@ -583,7 +586,7 @@
"view/title": [
{
"command": "atlascode.jira.createIssue",
"when": "view =~ /(atlascode.views.jira.customJql)/ && atlascode:isJiraAuthenticated",
"when": "view =~ /(atlascode.views.jira.customJql|atlascode.views.jira.assignedWorkItemsTreeView)/ && atlascode:isJiraAuthenticated",
"group": "navigation@1"
},
{
Expand All @@ -593,7 +596,7 @@
},
{
"command": "atlascode.jira.searchIssues",
"when": "view == atlascode.views.jira.customJqlTreeView && atlascode:isJiraAuthenticated",
"when": "view =~ /(atlascode.views.jira.customJqlTreeView|atlascode.views.jira.assignedWorkItemsTreeView)/ && atlascode:isJiraAuthenticated",
"group": "navigation@3"
},
{
Expand All @@ -606,10 +609,6 @@
"when": "view == atlascode.views.jira.customJqlTreeView && atlascode:isJiraAuthenticated",
"group": "navigation@2"
},
{
"command": "atlascode.jira.removeFromSidebar",
"when": "view =~ /(atlascode.views.jira.customJqlTreeView)/ && atlascode:isJiraAuthenticated"
},
{
"command": "atlascode.jira.createNewJql",
"when": "view =~ /(atlascode.views.jira.customJqlTreeView)/ && atlascode:isJiraAuthenticated"
Expand All @@ -619,6 +618,14 @@
"when": "view == atlascode.views.jira.customJql",
"group": "navigation@4"
},
{
"command": "atlascode.jira.addJiraSite",
"when": "view == atlascode.views.jira.assignedWorkItemsTreeView && atlascode:isJiraAuthenticated"
},
{
"command": "atlascode.jira.showJiraIssueSettings",
"when": "view =~ /(atlascode.views.jira.assignedWorkItemsTreeView|atlascode.views.jira.customJqlTreeView)/"
},
{
"command": "atlascode.bb.createPullRequest",
"when": "atlascode:isBBAuthenticated && atlascode:bitbucketExplorerEnabled && view == atlascode.views.bb.pullrequestsTreeView",
Expand Down
1 change: 1 addition & 0 deletions src/commandContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { commands } from 'vscode';
export enum CommandContext {
JiraExplorer = 'atlascode:jiraExplorerEnabled',
CustomJQLExplorer = 'atlascode:customJQLExplorerEnabled',
AssignedIssueExplorer = 'atlascode:assignedIssueExplorerEnabled',
BitbucketExplorer = 'atlascode:bitbucketExplorerEnabled',
PipelineExplorer = 'atlascode:pipelineExplorerEnabled',
BitbucketIssuesExplorer = 'atlascode:bitbucketIssuesExplorerEnabled',
Expand Down
10 changes: 6 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ConfigSection, ConfigSubSection } from './lib/ipc/models/config';
import { AbstractBaseNode } from './views/nodes/abstractBaseNode';
import { IssueNode } from './views/nodes/issueNode';
import { PipelineNode } from './views/pipelines/PipelinesTree';
import { CommandContext, setCommandContext } from './commandContext';

export enum Commands {
BitbucketSelectContainer = 'atlascode.bb.selectContainer',
Expand Down Expand Up @@ -57,6 +56,7 @@ export enum Commands {
RefreshJiraExplorer = 'atlascode.jira.refreshExplorer',
RefreshAssignedWorkItemsExplorer = 'atlascode.jira.refreshAssignedWorkItemsExplorer',
RefreshCustomJqlExplorer = 'atlascode.jira.refreshCustomJqlExplorer',
AddJiraSite = 'atlascode.jira.addJiraSite',
ShowJiraIssueSettings = 'atlascode.jira.showJiraIssueSettings',
ShowPullRequestSettings = 'atlascode.bb.showPullRequestSettings',
ShowPipelineSettings = 'atlascode.bb.showPipelineSettings',
Expand Down Expand Up @@ -96,16 +96,18 @@ export enum Commands {
CloneRepository = 'atlascode.cloneRepository',
DisableHelpExplorer = 'atlascode.disableHelpExplorer',
CreateNewJql = 'atlascode.jira.createNewJql',
RemoveFromSidebar = 'atlascode.jira.removeFromSidebar',
ToDoIssue = 'atlascode.jira.todoIssue',
InProgressIssue = 'atlascode.jira.inProgressIssue',
DoneIssue = 'atlascode.jira.doneIssue',
}

export function registerCommands(vscodeContext: ExtensionContext) {
vscodeContext.subscriptions.push(
commands.registerCommand(Commands.RemoveFromSidebar, () =>
setCommandContext(CommandContext.CustomJQLExplorer, false),
commands.registerCommand(Commands.AddJiraSite, () =>
Container.settingsWebviewFactory.createOrShow({
section: ConfigSection.Jira,
subSection: ConfigSubSection.Auth,
}),
),
commands.registerCommand(Commands.CreateNewJql, () =>
Container.settingsWebviewFactory.createOrShow({
Expand Down
11 changes: 0 additions & 11 deletions src/views/jira/treeViews/customJqlViewProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ jest.mock('../../../container', () => ({
},
}));

const mockExecuteQuery = jest.fn().mockReturnValue(Promise.resolve([]));
jest.mock('../customJqlTree', () => {
return {
CustomJQLTree: jest.fn().mockImplementation(() => ({
dispose: jest.fn(),
executeQuery: mockExecuteQuery,
setNumIssues: jest.fn(),
})),
};
});

jest.mock('../searchJiraHelper');

function forceCastTo<T>(obj: any): T {
Expand Down
29 changes: 19 additions & 10 deletions src/views/jira/treeViews/customJqlViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@ import {
commands,
window,
} from 'vscode';
import { JiraIssueNode, executeJqlQuery, createLabelItem } from './utils';
import { JiraIssueNode, executeJqlQuery, createLabelItem, loginToJiraMessageNode } from './utils';
import { SearchJiraHelper } from '../searchJiraHelper';

const enum ViewStrings {
LoginToJiraMessage = 'Please login to Jira',
ConfigureJqlMessage = 'Configure JQL entries in settings to view Jira issues',
NoIssuesMessage = 'No issues match this query',
}

const CustomJQLViewProviderId = 'atlascode.views.jira.customJqlTreeView';

export class CustomJQLViewProvider implements TreeDataProvider<TreeItem>, Disposable {
private static readonly _treeItemLoginToJiraMessage = createLabelItem(ViewStrings.LoginToJiraMessage, {
command: Commands.ShowConfigPage,
title: 'Login to Jira',
arguments: [ProductJira],
});
private static readonly _treeItemLoginToJiraMessage = loginToJiraMessageNode;
private static readonly _treeItemConfigureJqlMessage = createLabelItem(ViewStrings.ConfigureJqlMessage, {
command: Commands.ShowJiraIssueSettings,
title: 'Configure Filters',
Expand All @@ -54,15 +49,25 @@ export class CustomJQLViewProvider implements TreeDataProvider<TreeItem>, Dispos

window.createTreeView(CustomJQLViewProviderId, { treeDataProvider: this });

setCommandContext(CommandContext.CustomJQLExplorer, true);
const jqlEntries = Container.jqlManager.getCustomJQLEntries();

if (jqlEntries.length > 0) {
setCommandContext(CommandContext.CustomJQLExplorer, Container.config.jira.explorer.enabled);
}

Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this));

this.refresh();
}

onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (configuration.changed(e, 'jira.jqlList') || configuration.changed(e, 'jira.explorer')) {
const jqlEntries = Container.jqlManager.getCustomJQLEntries();
if (jqlEntries.length > 0) {
setCommandContext(CommandContext.CustomJQLExplorer, Container.config.jira.explorer.enabled);
} else {
setCommandContext(CommandContext.CustomJQLExplorer, false);
}
this.refresh();
}
}
Expand Down Expand Up @@ -91,6 +96,7 @@ export class CustomJQLViewProvider implements TreeDataProvider<TreeItem>, Dispos
}

private refresh() {
SearchJiraHelper.clearIssues(CustomJQLViewProviderId);
this._onDidChangeTreeData.fire();
}
}
Expand All @@ -110,9 +116,12 @@ class JiraIssueQueryNode extends TreeItem {
return [JiraIssueQueryNode._treeItemNoIssuesMessage];
}

issues = Container.config.jira.explorer.nestSubtasks ? await this.constructIssueTree(issues) : issues;
// index only issues that are directly retrieved with the JQL queries, and not
// the extra parent items retrieved to rebuild the issues hierarchy
SearchJiraHelper.appendIssues(issues, CustomJQLViewProviderId);

issues = Container.config.jira.explorer.nestSubtasks ? await this.constructIssueTree(issues) : issues;

return issues.map((issue) => new JiraIssueNode(JiraIssueNode.NodeType.CustomJqlQueriesNode, issue));
})();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AssignedWorkItemsViewProvider } from './jiraAssignedWorkItemsViewProvider';
import { Container } from '../../../container';
import { JQLManager } from 'src/jira/jqlManager';
import { SiteManager } from 'src/siteManager';
import { JQLManager } from '../../../jira/jqlManager';
import { SiteManager } from '../../../siteManager';
import { Disposable } from 'vscode';
import { JQLEntry } from '../../../config/model';
import { MinimalIssue } from '@atlassianlabs/jira-pi-common-models';
import { DetailedSiteInfo } from 'src/atlclients/authInfo';
import { DetailedSiteInfo } from '../../../atlclients/authInfo';

function forceCastTo<T>(obj: any): T {
return obj as unknown as T;
Expand Down Expand Up @@ -55,6 +55,18 @@ jest.mock('../../../container', () => ({
siteManager: {
onDidSitesAvailableChange: () => new Disposable(() => {}),
} as Partial<SiteManager>,
context: {
subscriptions: {
push: jest.fn(),
},
},
config: {
jira: {
explorer: {
enabled: true,
},
},
},
},
}));

Expand Down
39 changes: 27 additions & 12 deletions src/views/jira/treeViews/jiraAssignedWorkItemsViewProvider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { MinimalIssue } from '@atlassianlabs/jira-pi-common-models';
import { DetailedSiteInfo, ProductJira } from '../../../atlclients/authInfo';
import { DetailedSiteInfo } from '../../../atlclients/authInfo';
import { Container } from '../../../container';
import { Commands } from '../../../commands';
import { SearchJiraHelper } from '../searchJiraHelper';
import { PromiseRacer } from '../../../util/promises';
import { Disposable, TreeDataProvider, TreeItem, EventEmitter, commands, window } from 'vscode';
import { JiraIssueNode, executeJqlQuery, createLabelItem } from './utils';

const enum ViewStrings {
ConfigureJiraMessage = 'Please login to Jira',
}
import {
Disposable,
TreeDataProvider,
TreeItem,
EventEmitter,
commands,
window,
ConfigurationChangeEvent,
} from 'vscode';
import { JiraIssueNode, executeJqlQuery, loginToJiraMessageNode } from './utils';
import { configuration } from '../../../config/configuration';
import { CommandContext, setCommandContext } from '../../../commandContext';

const AssignedWorkItemsViewProviderId = 'atlascode.views.jira.assignedWorkItemsTreeView';

export class AssignedWorkItemsViewProvider implements TreeDataProvider<TreeItem>, Disposable {
private static readonly _treeItemConfigureJiraMessage = createLabelItem(ViewStrings.ConfigureJiraMessage, {
command: Commands.ShowConfigPage,
title: 'Login to Jira',
arguments: [ProductJira],
});
private static readonly _treeItemConfigureJiraMessage = loginToJiraMessageNode;

private _onDidChangeTreeData = new EventEmitter<TreeItem | undefined | void>();
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
Expand All @@ -36,14 +38,27 @@ export class AssignedWorkItemsViewProvider implements TreeDataProvider<TreeItem>

window.createTreeView(AssignedWorkItemsViewProviderId, { treeDataProvider: this });

setCommandContext(CommandContext.AssignedIssueExplorer, Container.config.jira.explorer.enabled);

const jqlEntries = Container.jqlManager.getAllDefaultJQLEntries();

if (jqlEntries.length) {
this._initPromises = new PromiseRacer(jqlEntries.map(executeJqlQuery));
}

Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this));
this._onDidChangeTreeData.fire();
}

private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (configuration.changed(e, 'jira.explorer.enabled')) {
setCommandContext(CommandContext.AssignedIssueExplorer, Container.config.jira.explorer.enabled);
this.refresh();
} else if (configuration.changed(e, 'jira.explorer')) {
this.refresh();
}
}

dispose() {
this._disposable.dispose();
}
Expand Down
Loading