Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented May 8, 2025

Describe your changes

Add some column information to the column menu. This includes an icon for the column type, the name, and an easy way to copy the name to the clipboard.

image

In a potential follow-up, we might allow changing the column type by clicking on the icon.

Testing Plan

  • Added unit test.
  • Update snapshots.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11303/streamlit-1.46.1-py3-none-any.whl
🕹️ Preview app pr-11303.streamlit.app (☁️ Deploy here if not accessible)

@snyk-io
Copy link
Contributor

snyk-io bot commented May 8, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@lukasmasuch lukasmasuch changed the title [WIP] Add column info to dataframe column menu [Prototype] Add column info to dataframe column menu May 8, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR labels Jul 8, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot July 8, 2025 23:01

This comment was marked as outdated.

@lukasmasuch lukasmasuch changed the title [Prototype] Add column info to dataframe column menu Add column info to dataframe column menu Jul 8, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review July 8, 2025 23:40
@lukasmasuch lukasmasuch requested a review from Copilot July 8, 2025 23:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the DataFrame column menu by showing column metadata (type icon, name) and adding a copy-to-clipboard action.

  • Introduces styled components to render a header row with type icon, column name, and copy button
  • Updates ColumnMenu to accept columnName, compute and display the icon, and handle copying
  • Adds a COLUMN_TYPE_ICONS map, a new unit test for name rendering, and updated snapshots

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
frontend/lib/src/components/widgets/DataFrame/menus/styled-components.ts Adds StyledColumnHeaderRow, StyledTypeIconContainer, StyledColumnNameWithIcon, StyledColumnNameText, and StyledIconButton
frontend/lib/src/components/widgets/DataFrame/menus/ColumnMenu.tsx Accepts columnName, uses useMemo for icon lookup, and renders the header row with copy functionality
frontend/lib/src/components/widgets/DataFrame/menus/ColumnMenu.test.tsx Includes columnName in defaultProps and tests rendering of the name
frontend/lib/src/components/widgets/DataFrame/columns/index.ts Defines COLUMN_TYPE_ICONS mapping for column kinds
frontend/lib/src/components/widgets/DataFrame/DataFrame.tsx Passes columnName from originalColumns into ColumnMenu
Comments suppressed due to low confidence (2)

frontend/lib/src/components/widgets/DataFrame/menus/ColumnMenu.test.tsx:58

  • Add a test to verify that clicking the copy button calls navigator.clipboard.writeText with the correct column name to ensure the copy-to-clipboard feature is covered.
  test("renders the column menu with the correct column name", () => {

frontend/lib/src/components/widgets/DataFrame/menus/ColumnMenu.test.tsx:61

  • Consider adding a test that checks the type icon is rendered with the expected title attribute (column kind) to cover icon rendering behavior.
    const columnName = screen.getByText("testColumn")

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

/**
* Mapping of column types to icons.
*/
export const COLUMN_TYPE_ICONS: Record<string, string> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Is there a better type we can use instead of string as the key type? If a new column type were to be added, this would fail type checking until all of the column types are handled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I made the typeIcon a required column property -> thereby, its enforced to be defined whenever we implement a new column type

Comment on lines 119 to 125
if (navigator.clipboard) {
navigator.clipboard.writeText(columnName).catch(error => {
LOG.error("Failed to copy column name to clipboard:", error)
})
} else {
LOG.error("Clipboard API not supported.")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Utilize the existing clipboard dependency so that it works across browsers.

Out of scope for this PR, but it would be better if we instead had a shared copyToClipboard function that abstracts this implementation and dependency away so every callsite doesn't need to handle this.

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 looked into this a bit, and I think it might be better to treat this as a follow-up. Here are a couple of findings:
How we use clipboard is a bit mixed: the json and code component are using the clipboard dependency while ExceptionElement and ThemeCreatorEditor are using navigator.clipboard.writeText directly. It looks like clipboard is a bit outdated since it hasn't been updated for 3 years and is not using the browser clipboard API. It's relying on the deprecated document.execCommand instead; maybe there is a better dependency for this. I think what we might want to have is a mix between using the clipboard API if possible, and falling back to the older behaviour (e.g., if permissions do not allow the clipboard API). I added a tech debt item here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good find! Agree that we can align all of this in a follow-up!

@lukasmasuch lukasmasuch merged commit 9dec9ec into develop Jul 17, 2025
39 of 40 checks passed
@lukasmasuch lukasmasuch deleted the feature/add-column-info-to-df-menu branch July 17, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants