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

feat: add query panel tab #1231

Merged
merged 11 commits into from
Jun 25, 2024
Merged

feat: add query panel tab #1231

merged 11 commits into from
Jun 25, 2024

Conversation

gaurpulkit
Copy link
Collaborator

Overview

Problem

#683 (comment)

Solution

Showing query panel in tabs

Screenshot/Demo

A picture is worth a thousand words. Please highlight the changes if applicable.
Screenshot 2024-06-19 at 6 18 31 PM

How to test

  • Steps to be followed to verify the solution or code changes
  • Mention if there is any settings configuration added/changed/deleted

Checklist

  • I have run this code and it appears to resolve the stated issue
  • README.md updated and added information about my change

Copy link
Contributor

@mdesmet mdesmet left a comment

Choose a reason for hiding this comment

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

What happens if vscode is restarted?
I don't think we should allow to clear the results of result document.

Copy link
Contributor

@mdesmet mdesmet left a comment

Choose a reason for hiding this comment

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

usersService,
);

const t = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

@@ -30,8 +31,9 @@ const QueryPanel = (): JSX.Element => {
/>
</Stack>
<Stack>
<ShowOldUxButton />
{!isTab && <ShowOldUxButton />}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{!isTab && <ShowOldUxButton />}
{isPanel && <ShowOldUxButton />}

@@ -29,6 +29,7 @@ import { UsersService } from "../services/usersService";
import { ConversationProvider } from "../comment_provider/conversationProvider";
import { DbtDocsView } from "./DbtDocsView";
import { ConversationService } from "../services/conversationService";
import { QueryResultTab } from "./QueryResultTab";
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be part of queryResultPanel.ts. I have added DbtDocsView, because it was related to doc editor

@@ -30,8 +31,9 @@ const QueryPanel = (): JSX.Element => {
/>
</Stack>
<Stack>
<ShowOldUxButton />
{!isTab && <ShowOldUxButton />}
<ClearResultsButton />
Copy link
Collaborator

Choose a reason for hiding this comment

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

clear results is also not needed in tab

void executeRequestInSync("getQueryTabData", {}).then((data) => {
if (data) {
const typedData = data as QueryPanelStateProps;
setTabData(data as Record<string, unknown>);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this typecasted to unknown? can you use QueryPanelStateProps?

@@ -154,7 +158,24 @@ const useQueryPanelListeners = (): { loading: boolean } => {
};
}, [onMesssage]);

return { loading };
useEffect(() => {
if (!tabData) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like you can avoid storing all the data in tabData. This is only needed to store whether this is a tab or not. You can just store this state value as boolean. This will avoid storing duplicate data in memory

import { UsersService } from "../services/usersService";

@provideSingleton(QueryResultTab)
export class QueryResultTab extends AltimateWebviewProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this new class can be avoided and can be combined with existing queryResultsPanel.

@anandgupta42
Copy link
Contributor

@gaurpulkit make sure we add some tests for this as well. Also, please make sure to test it out manually in both native desktop environment and also in codespaces

@gaurpulkit
Copy link
Collaborator Author

What happens if vscode is restarted? I don't think we should allow to clear the results of result document.

It clears the tabs for now


protected _panel: WebviewView | undefined;
protected _tabPanel: WebviewPanel | undefined = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be private

return;
}

this._webview.onDidReceiveMessage(this.handleCommand, this, []);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use setupWebviewHooks

import Tooltip from "../tooltip/Tooltip";
import classes from "./styles.module.scss";

export const GradientButton = (props: ButtonProps): JSX.Element => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a sample in webview_panels\src\uiCore\uiToolkitStories\Components.stories.tsx

Comment on lines 34 to 37
{isPanel && <ShowOldUxButton />}
{isPanel && <ClearResultsButton />}
{isPanel && <ShowInTabButton />}
<HelpButton />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{isPanel && <ShowOldUxButton />}
{isPanel && <ClearResultsButton />}
{isPanel && <ShowInTabButton />}
<HelpButton />
{isPanel && (
<>
<ShowOldUxButton />
<ClearResultsButton />
<ShowInTabButton />
</>
)}
<HelpButton />

@@ -312,6 +354,32 @@ export class QueryResultPanel extends AltimateWebviewProvider {
this._panel!.onDidChangeVisibility(sendQueryPanelViewEvent);
}

private setupTabWebviewHooks() {
this._tabPanel!.webview.onDidReceiveMessage(
Copy link
Collaborator

Choose a reason for hiding this comment

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

it will be better to reuse the existing onDidReceiveMessage handler, otherwise this tab will lose the other command handling. You should be using existing setupWebviewHooks so that all the commands will go through same flow. Otherwise it will be difficult to maintain multiple versions of the query results panel

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I already tried to do that but the webview of tab isn't available when only panel opens. So, we need to set it when it opens.


this.setupTabWebviewHooks();

this._webview.html = this.getHtml(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is better to use renderWebviewView, which has few conditions to render different type of views based on configuration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again, the setup time of tab and panel will be different

this,
this._disposables,
);
const sendQueryTabViewEvent = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

extract this as separate private function to avoid multiple bindings

@mdesmet mdesmet merged commit 8cc6e7b into master Jun 25, 2024
7 checks passed
@mdesmet mdesmet deleted the add-query-panel-tab branch June 25, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants