Skip to content

Display different message when queries are loading vs no queries found#2523

Merged
robertbrignull merged 9 commits intomainfrom
robertbrignull/queries-loading
Jul 3, 2023
Merged

Display different message when queries are loading vs no queries found#2523
robertbrignull merged 9 commits intomainfrom
robertbrignull/queries-loading

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

@robertbrignull robertbrignull commented Jun 19, 2023

Displays a "loading" message while query discovery has not yet finished, and a separate message when no queries have been found. This should help avoid confusing users by saying there are no queries when really the discovery is just in progress.

The approach I've taken is to make the welcome message the "loading" message, and display a custom text node for the "no queries" case. This helps avoid the effect seen in #2523 (comment) where it flips between the two options before the extension has started initialising.

For the datatypes I opt to create subclasses for QueryTreeQueryItem and QueryTreeTextItem, where QueryTreeQueryItem is identical to the old QueryTreeViewItem. We could maybe split this up further into "node" and "leaf" classes, but I haven't done this here.

I also fix a bug where it wouldn't update the tree view in the case that the initial refresh found no queries. This bug just wasn't visible before because it would display the welcome message anyway.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@robertbrignull
Copy link
Copy Markdown
Contributor Author

Screen recording:

Screen.Recording.2023-06-19.at.12.30.47.mov

Unfortunately it still displays the welcome message for a bit while the extension is starting, before it calls out tree data provider which can provider the loading message.

I'm considering flipping the behaviours so that we use the welcome message to say that things are in progress, and then a custom message when there were no queries found.

@robertbrignull robertbrignull force-pushed the robertbrignull/queries-loading branch from 383a37e to 89749ff Compare June 27, 2023 15:53
@robertbrignull robertbrignull force-pushed the robertbrignull/queries-loading branch from 89749ff to d290b56 Compare June 27, 2023 16:04
@robertbrignull robertbrignull changed the title Robertbrignull/queries loading Display different message when queries are loading vs no queries found Jun 27, 2023
@robertbrignull robertbrignull marked this pull request as ready for review June 27, 2023 16:08
@robertbrignull robertbrignull requested review from a team as code owners June 27, 2023 16:08
@robertbrignull robertbrignull requested review from a team and removed request for a team June 27, 2023 16:08
@robertbrignull
Copy link
Copy Markdown
Contributor Author

robertbrignull commented Jun 27, 2023

I'm considering flipping the behaviours so that we use the welcome message to say that things are in progress, and then a custom message when there were no queries found.

I've updated this PR as described above. I've updated the PR description too.

Should be ready for review and testing now.

Copy link
Copy Markdown
Contributor

@norascheuch norascheuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why we need the added complexity of a QueryTreeQueryItem and QueryTreeTextItem Type.

When making the path optional we should be able to reuse the existing type?

Comment thread extensions/ql-vscode/src/queries-panel/query-tree-view-item.ts Outdated
Comment thread extensions/ql-vscode/src/queries-panel/query-tree-view-item.ts Outdated
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
import { findLanguage } from "../codeql-cli/query-language";
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
import { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you removed the type import specification?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. Earlier in the lifetime of this PR I had to convert the type import because I used QueryTreeViewItem in a instanceof expression, and that requires importing the type at runtime instead of just at compiletime. But that has been removed now so this can stay as a type import.

public getLanguageForQueryFile(queryPath: string): QueryLanguage | undefined {
// Find all packs in a higher directory than the query
const packs = this.getPathData().filter((queryPack) =>
const packs = (this.getPathData() || []).filter((queryPack) =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing for me to run a filter over an empty array, but checking getPathData first and having another if condition is not really better I suppose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check it beforehand. It makes it longer and more verbose, but that's not necessarily a bad thing. I'll make it a separate check instead of using || [] inside this expression.

}
}

export function createQueryTreeNodeItem(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would personally prefer using the domain names here, namely QueryTreeFolderItem and QueryTreeFileItem. Right now I have to translate 'node' and 'leaf' in my head to folder and file to have the correct image in my head. However, I don't have a CS background and could imagine it doesn't make sense to call it something other than node and leaf? For me folder and file is just more descriptive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference between the names. I was just picking one and my mind goes towards nodes and leaves because we're making TreeView/QueryTree.

I do now see we're using "queryFolder" and "queryFile" for the context values. I'll change the function names to match those.

Comment thread extensions/ql-vscode/src/queries-panel/query-tree-view-item.ts Outdated
Copy link
Copy Markdown
Contributor

@norascheuch norascheuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments otherwise looks good. Thanks for introducing these types!

@robertbrignull robertbrignull enabled auto-merge July 3, 2023 09:09
@robertbrignull robertbrignull merged commit 0a0b9e5 into main Jul 3, 2023
@robertbrignull robertbrignull deleted the robertbrignull/queries-loading branch July 3, 2023 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants