Skip to content

Show snippet run location in list and card views - #589

Open
faisalahammad wants to merge 1 commit into
codesnippetspro:core-betafrom
faisalahammad:feat/517-run-location-indicator/core
Open

faisalahammad wants to merge 1 commit into
codesnippetspro:core-betafrom
faisalahammad:feat/517-run-location-indicator/core

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Adds the run location to the All Snippets list so users can see where each snippet executes without opening the editor. A new Location column shows the scope icon and label in table view, and cards show the same location line in their meta row. Labels and icons reuse the editor's existing Location options, so wording matches everywhere.

Closes #517

Changes

Location column (TableColumns.tsx)

Before: table showed activate, ID, name, type, description, tags, date columns only.
After: new LocationColumn component renders an aria-hidden dashicon plus the visible scope label (Run everywhere, Only run in administration area, etc). Conditional snippets have no single run location and show an em dash, matching the editor where they have no Location field. The column is sortable and registered in Screen Options so it can be toggled and its state persists.
Why: the issue asks for an always-visible, text-backed run location in the list, not color- or tooltip-only.

Card view (ManageSnippetCard.tsx)

Before: card meta row only rendered when the snippet had tags or a modified date.
After: the meta row also renders when the snippet has a location, with the location as the first item.
Why: otherwise a plain global snippet with no tags and no edits would show nothing in card view.

Shared helper (snippets.ts)

Before: scope labels only accessible as the editor's select options.
After: new getSnippetLocation() returns the visible label for a snippet or undefined for conditional snippets. Reused by both the column and the card.

Screen Options (Manage_Menu_Screen_Options.php)

Before: location key missing from the server-side column list.
After: location registered after type so the column participates in the Screen Options toggle and persistence.

Styles (_snippets-table.scss)

After: .snippet-location uses logical properties, muted text color, and 16px dashicon sizing shared with the name and type columns. Card location takes the full meta-row width.

Tests

  • E2E: new Snippet run location describe creates snippets covering global, admin, front-end, single-use, content, site-css, and site-head-js scopes, asserts table and card labels, asserts the condition snippet shows an em dash in table and nothing in card, and asserts the Screen Options toggle hides and shows the column in real time. SnippetsTestHelper accepts an explicit scope for CLI-created snippets.
  • PHPUnit: new assertion that get_columns() returns Location for the location key.

Testing

Test 1: Table view labels

  1. Open All Snippets in table view.
  2. Check the Location column for snippets of each scope.
    Result: each row shows the icon and label matching the editor's Location options; global snippets show Run everywhere.

Test 2: Conditional snippets

  1. Find a conditional snippet in table and card view.
    Result: table shows an em dash in the Location column; card shows no location line.

Test 3: Screen Options toggle

  1. Open Screen Options and toggle the Location column.
    Result: the column hides and shows in real time and the state persists across page loads.

Test 4: Card view

  1. Switch to card view.
    Result: each card shows its location in the meta row with the same wording as table view.

Test 5: Responsive

  1. Narrow the viewport below 782px so the table switches to the stacked layout.
    Result: the location stays visible with the other per-row fields.

Automated: PHPCS/WPCS, ESLint, and Stylelint pass. PHPUnit 355 tests, 810 assertions pass (25 pre-existing environment skips). CodeRabbit review reported no findings. npm run build and npm run bundle succeed.

Screenshots

Not attached; the wp-env site was verified locally.

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.

Show snippet run location in list and card views

1 participant