Skip to content

data explorer: create "Copy as Code" modal #8537

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

Merged
merged 66 commits into from
Jul 23, 2025
Merged

Conversation

isabelizimm
Copy link
Contributor

@isabelizimm isabelizimm commented Jul 15, 2025

This PR implements the actions and modal dialog for the Copy as Code data explorer button.

A modal dialog was chosen over a modal popup since we cannot use a modal popup in the editor action bar at this point in time. Notes from @dhruvisompura:

The data explorer UI doesn't have the action bar component we created because we normally have it live in its own row below the VS Code editor action bar (the one that every editor tab has). We don't want the data explorer to have two action bars as that is confusing/annoying/bad ux for the user! We are relying on the VS Code editor action bar for the Data Explorer.
We have to contribute all of our buttons via a command for them to show up in that editor action bar.
There currently is no mechanism to show a popup that is anchored to the copy button via an action because commands have no way of knowing what DOM element to anchor a piece of UI to. Commands are pretty primitive and don't have UI context generally.

Note that this is just the first implementation! Things like the "Copy to Clipboard" functionality, real code editor block, etc will come in a follow up PR.

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

Intended behavior is that the modal has a dropdown that is populated with the name of a syntax, eg, pandas, + generated code. At this point, the code generation piece is not implemented, so we won't have to check the code is correct (yet).

On the Python side, a pandas dataframe will fill the dropdown with pandas. A polars dataframe will fill the dropdown with polars. For the R side, unless you have a locally built Ark, the button should be greyed out since there are no syntaxes available.

Copy link

github-actions bot commented Jul 15, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@@ -19,6 +19,8 @@ import { DataExplorerClientInstance } from '../../languageRuntime/common/languag
import { DataExplorerSummaryCollapseEnabled, DefaultDataExplorerSummaryLayout } from './positronDataExplorerSummary.js';
import { CodeSyntaxName } from '../../languageRuntime/common/positronDataExplorerComm.js';
import { ClipboardCell, ClipboardCellRange, ClipboardColumnIndexes, ClipboardColumnRange, ClipboardRowIndexes, ClipboardRowRange } from '../../../browser/positronDataGrid/classes/dataGridInstance.js';
import { POSITRON_DATA_EXPLORER_IS_CONVERT_TO_CODE_ENABLED } from '../../../contrib/positronDataExplorerEditor/browser/positronDataExplorerContextKeys.js';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

locally i saw this message on commit:

[16:51:21] /Users/isabelizimm/code/positron/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts: line 22, col 67, Warning - Imports violates 'vs/base/{common,browser}/** or vs/base/parts/*/{common,browser}/** or vs/platform/*/{common,browser}/** or vs/editor/{common,browser}/** or vs/editor/contrib/*/{common,browser}/** or vs/workbench/{common,browser}/** or vs/workbench/services/*/{common,browser}/** or tas-client-umd or vscode-textmate or @vscode/vscode-languagedetection or @vscode/tree-sitter-wasm or @xterm/xterm or vs/nls.js or vs/amdX.js' restrictions. See https://github.com/microsoft/vscode/wiki/Source-Code-Organization (local/code-import-patterns)

I don't know if it is a Very Bad Thing or something that is okay to ignore? There are no other errors for build, lint, etc, but want to call it out just in case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for calling this out! I do think we want to address this eslint import error. I just messaged you about this via slack.

@@ -19,6 +19,8 @@ import { DataExplorerClientInstance } from '../../languageRuntime/common/languag
import { DataExplorerSummaryCollapseEnabled, DefaultDataExplorerSummaryLayout } from './positronDataExplorerSummary.js';
import { CodeSyntaxName } from '../../languageRuntime/common/positronDataExplorerComm.js';
import { ClipboardCell, ClipboardCellRange, ClipboardColumnIndexes, ClipboardColumnRange, ClipboardRowIndexes, ClipboardRowRange } from '../../../browser/positronDataGrid/classes/dataGridInstance.js';
import { POSITRON_DATA_EXPLORER_IS_CONVERT_TO_CODE_ENABLED } from '../../../contrib/positronDataExplorerEditor/browser/positronDataExplorerContextKeys.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for calling this out! I do think we want to address this eslint import error. I just messaged you about this via slack.

isabelizimm and others added 3 commits July 21, 2025 09:40
…alDialog.tsx

Co-authored-by: Dhruvi Sompura <dhruvi.sompura@posit.co>
Signed-off-by: Isabel Zimmerman <54685329+isabelizimm@users.noreply.github.com>
@isabelizimm isabelizimm marked this pull request as ready for review July 21, 2025 14:53
isabelizimm added a commit that referenced this pull request Jul 21, 2025
related issue: #8531
related pr for Ark: posit-dev/ark#873 

I'm not exactly sure of the flow of these PRs with Ark, but I believe
we'll want to merge that PR, release Ark, and then pick up the new
release in this PR before this PR is merged.

This PR implements makes 3 major changes to the comms:
- **add `convert_to_code` as a supported feature:** there are other
supported features, such as row filters and column filters. This
structure includes if it is supported as well as supported syntaxes, as
an array of values.
- **`suggest_code_syntax` message:** for a particular data explorer
instance, decide what options a user has for generating code. I would
expect the return value of this to be `base-r` or something to that
effect.
- **`convert_to_code` message:** for a particular data explorer
instance, this message sends over the filters and sorts applied to the
data and the desired syntax. The expectation is that this will return a
code snippet string. The front end will (eventually) apply code
highlighting and formatting.

Below is a diagram of the general flow through comms. Note that these
comm messages will not call each other; they will be triggered by a
modal in Positron core.

```mermaid
flowchart TD
    A["Data explorer instance is created"] --> B["Get all potential syntaxes from language pack via the **supported_features**." ]
    B -->  C["Also set suggested syntax with **suggest_code_syntax**"]
    C --> D[Open modal]
    D --> E["Use **dataExplorerInstance.suggestedSyntax**"]
    E --> F["Translate data view (filters, sorts) to code with **_translate_to_code_**"]
    F --> G[Display code for user to copy]
    G -->|user chooses another syntax from modal dropdown| F
```

There is an open PR that builds off this branch to use these comms, so
you can actually fire them off/interact with them #8537

### Release Notes

<!--
Optionally, replace `N/A` with text to be included in the next release
notes.
The `N/A` bullets are ignored. If you refer to one or more Positron
issues,
these issues are used to collect information about the feature or
bugfix, such
as the relevant language pack as determined by Github labels of type
`lang: `.
  The note will automatically be tagged with the language.

These notes are typically filled by the Positron team. If you are an
external
  contributor, you may ignore this section.
-->

#### New Features

- N/A

#### Bug Fixes

- N/A


### QA Notes

It doesn't look like we have much testing for comms, but open to ideas!
Currently I plan on adding unit tests on each language runtime and then
e2e tests for the UI pieces.

---------

Signed-off-by: Isabel Zimmerman <54685329+isabelizimm@users.noreply.github.com>
Co-authored-by: Jennifer (Jenny) Bryan <jenny.f.bryan@gmail.com>
Base automatically changed from copy-as-code-comms to main July 21, 2025 20:39
Signed-off-by: Isabel Zimmerman <54685329+isabelizimm@users.noreply.github.com>
@isabelizimm
Copy link
Contributor Author

failing test is unrelated!

@isabelizimm isabelizimm requested a review from softwarenerd July 23, 2025 15:35
softwarenerd
softwarenerd previously approved these changes Jul 23, 2025
Copy link
Contributor

@softwarenerd softwarenerd left a comment

Choose a reason for hiding this comment

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

There are just two comments left.

<div className='dropdown-entry-title'>
{props.title}
</div>
{props.group ? <div className='dropdown-entry-group'>{props.group}</div> : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified as:

{props.group && <div className='dropdown-entry-group'>{props.group}</div>}

"Convert to Code"
))()}
width={400}
onAccept={async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

async doesn't seem to be needed.

onAccept={() => renderer.dispose()}

@isabelizimm isabelizimm merged commit eec9df6 into main Jul 23, 2025
10 checks passed
@isabelizimm isabelizimm deleted the copy-as-code-modal branch July 23, 2025 21:25
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants