An open source design system that's fully customizable and agent ready
TypeScript
fix(templates): improve PowerSearch block grading scores (#1625)
Cindy Zhangd373d66226a4
diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.doc.mjs b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.doc.mjsindex 258e1d7e05..c126956b67 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.doc.mjs+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.doc.mjs@@ -3,7 +3,7 @@ export const doc = {type: 'block',name: 'PowerSearch — Full Featured',description:- 'Power search with all field types: enum, multi-select, entity, integer, date, and text filters.',+ 'Power search with multiple field types: enum, multi-select, entity, and text filters.',isReady: true,aspectRatio: 4 / 3,componentsUsed: ['PowerSearch'],diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsxindex 81dfd03d67..8982b87155 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx@@ -11,32 +11,21 @@ const statusValues = [{value: 'review', label: 'In Review'},{value: 'closed', label: 'Closed'},];-const priorityValues = [{value: 'p0', label: 'P0 — Critical'},{value: 'p1', label: 'P1 — High'},{value: 'p2', label: 'P2 — Medium'},{value: 'p3', label: 'P3 — Low'},];--const tagValues = [- {value: 'bug', label: 'Bug'},- {value: 'feature', label: 'Feature'},- {value: 'docs', label: 'Documentation'},- {value: 'perf', label: 'Performance'},- {value: 'security', label: 'Security'},-];-const users: XDSSearchableItem[] = [{id: 'user-1', label: 'Alice Johnson'},{id: 'user-2', label: 'Bob Smith'},{id: 'user-3', label: 'Charlie Brown'},{id: 'user-4', label: 'Diana Prince'},];-const userSource: XDSSearchSource = {- search: (query: string) =>- users.filter(u => u.label.toLowerCase().includes(query.toLowerCase())),+ search: (q: string) =>+ users.filter(u => u.label.toLowerCase().includes(q.toLowerCase())),bootstrap: () => users,};@@ -78,11 +67,7 @@ const config: PowerSearchConfig = {label: 'Priority',defaultOperator: 'is',operators: [- {- key: 'is',- label: 'is',- value: {type: 'enum', values: priorityValues},- },+ {key: 'is', label: 'is', value: {type: 'enum', values: priorityValues}},],},{@@ -97,52 +82,6 @@ const config: PowerSearchConfig = {},],},- {- key: 'tags',- label: 'Tags',- defaultOperator: 'include',- operators: [- {- key: 'include',- label: 'include',- value: {type: 'enum_list', values: tagValues},- },- {- key: 'exclude',- label: 'exclude',- value: {type: 'enum_list', values: tagValues},- },- ],- },- {- key: 'line_count',- label: 'Line count',- defaultOperator: 'gt',- operators: [- {- key: 'gt',- label: 'is greater than',- value: {type: 'integer', minValue: 0, maxValue: 10000, units: 'lines'},- },- {- key: 'lt',- label: 'is less than',- value: {type: 'integer', minValue: 0, maxValue: 10000, units: 'lines'},- },- ],- },- {- key: 'created',- label: 'Created',- defaultOperator: 'after',- operators: [- {- key: 'after',- label: 'is after',- value: {type: 'date_absolute', isDateOnly: true},- },- ],- },],};@@ -150,13 +89,11 @@ export default function PowerSearchFullFeatured() {const [filters, setFilters] = useState<PowerSearchFilter[]>([]);return (- <div style={{width: 700}}>- <XDSPowerSearch- config={config}- filters={filters}- onChange={newFilters => setFilters([...newFilters])}- placeholder="Search..."- />- </div>+ <XDSPowerSearch+ config={config}+ filters={filters}+ onChange={newFilters => setFilters([...newFilters])}+ placeholder="Search..."+ />);}diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.doc.mjs b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.doc.mjsindex a33ef81fc3..ad8e14804b 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.doc.mjs+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.doc.mjs@@ -6,5 +6,5 @@ export const doc = {'Composition of PowerSearch with Table using usePowerSearchConfig to auto-generate config and filter data.',isReady: true,aspectRatio: 4 / 3,- componentsUsed: ['PowerSearch', 'Table'],+ componentsUsed: ['PowerSearch', 'Table', 'Layout'],};diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsxindex cbdb252c68..a73ea491d7 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx@@ -5,14 +5,14 @@ import {XDSPowerSearch, usePowerSearchConfig} from '@xds/core/PowerSearch';import type {PowerSearchFilter} from '@xds/core/PowerSearch';import {XDSTable, pixel, proportional} from '@xds/core/Table';import type {XDSTableColumn} from '@xds/core/Table';+import {XDSVStack} from '@xds/core/Layout';const genreValues = [- {value: 'fiction', label: 'Fiction'},- {value: 'non-fiction', label: 'Non-Fiction'},{value: 'sci-fi', label: 'Science Fiction'},{value: 'fantasy', label: 'Fantasy'},- {value: 'mystery', label: 'Mystery'},+ {value: 'non-fiction', label: 'Non-Fiction'},{value: 'romance', label: 'Romance'},+ {value: 'mystery', label: 'Mystery'},];const fieldDefs = [@@ -31,14 +31,41 @@ interface Book extends Record<string, unknown> {}const books: Book[] = [- {id: '1', title: 'Dune', author: 'Frank Herbert', year: 1965, genre: 'sci-fi'},- {id: '2', title: 'Pride and Prejudice', author: 'Jane Austen', year: 1813, genre: 'romance'},- {id: '3', title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', year: 1925, genre: 'fiction'},- {id: '4', title: '1984', author: 'George Orwell', year: 1949, genre: 'sci-fi'},- {id: '5', title: 'To Kill a Mockingbird', author: 'Harper Lee', year: 1960, genre: 'fiction'},- {id: '6', title: 'The Hobbit', author: 'J.R.R. Tolkien', year: 1937, genre: 'fantasy'},- {id: '7', title: 'Sapiens', author: 'Yuval Noah Harari', year: 2011, genre: 'non-fiction'},- {id: '8', title: 'Gone Girl', author: 'Gillian Flynn', year: 2012, genre: 'mystery'},+ {+ id: '1',+ title: 'Dune',+ author: 'Frank Herbert',+ year: 1965,+ genre: 'sci-fi',+ },+ {+ id: '2',+ title: 'Pride and Prejudice',+ author: 'Jane Austen',+ year: 1813,+ genre: 'romance',+ },+ {+ id: '3',+ title: '1984',+ author: 'George Orwell',+ year: 1949,+ genre: 'sci-fi',+ },+ {+ id: '4',+ title: 'The Hobbit',+ author: 'J.R.R. Tolkien',+ year: 1937,+ genre: 'fantasy',+ },+ {+ id: '5',+ title: 'Sapiens',+ author: 'Yuval Noah Harari',+ year: 2011,+ genre: 'non-fiction',+ },];const columns: XDSTableColumn<Book>[] = [@@ -60,7 +87,7 @@ export default function PowerSearchSearchWithTable() {const filteredBooks = applyFilters(filters, books);return (- <div style={{display: 'flex', flexDirection: 'column', gap: 16}}>+ <XDSVStack gap={4}><XDSPowerSearchconfig={config}filters={filters}@@ -69,6 +96,6 @@ export default function PowerSearchSearchWithTable() {resultCount={filteredBooks.length}/><XDSTable data={filteredBooks} columns={columns} idKey="id" hasHover />- </div>+ </XDSVStack>);}diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.doc.mjs b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.doc.mjsindex d3fb55d424..af67f9828c 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.doc.mjs+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.doc.mjs@@ -2,7 +2,10 @@export const doc = {type: 'block',name: 'PowerSearch',+ description:+ 'Token-based filter bar with enum and text fields, pre-populated with sample filters.',isReady: true,aspectRatio: 1,isShowcase: true,+ componentsUsed: ['PowerSearch'],};diff --git a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsxindex 5c5de28586..c4586d1cb9 100644--- a/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx+++ b/packages/cli/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx@@ -1,5 +1,8 @@+'use client';++import {useState} from 'react';import {XDSPowerSearch} from '@xds/core/PowerSearch';-import type {PowerSearchConfig} from '@xds/core/PowerSearch';+import type {PowerSearchConfig, PowerSearchFilter} from '@xds/core/PowerSearch';const config: PowerSearchConfig = {name: 'BasicSearch',@@ -34,12 +37,23 @@ const config: PowerSearchConfig = {],};+const initialFilters: PowerSearchFilter[] = [+ {field: 'status', operator: 'is', value: {type: 'enum', value: 'open'}},+ {+ field: 'title',+ operator: 'contains',+ value: {type: 'string', value: 'dashboard'},+ },+];+export default function PowerSearchShowcase() {+ const [filters, setFilters] = useState<PowerSearchFilter[]>(initialFilters);+return (<XDSPowerSearchconfig={config}- filters={[]}- onChange={() => {}}+ filters={filters}+ onChange={newFilters => setFilters([...newFilters])}placeholder="Search by status, title..."/>);