Skip to content

Commit 113fc7d

Browse files
committed
feat(PowerSearch): an operator opts into value-only matches in the typeahead
An operator's new isValueOnlyMatchAllowed suggests its complete filters for a typed value with no field label before it (component:PowerSearch FR27-FR29, AR7, DEC-8). Typing "fiction" offers "Genre is Fiction" after the field and field-and-operator rows. - Free-text rows for string and string_list operators without a source, enum and enum_list values by word start under the shared fold, and the items of an operator's search source. - At most three rows per field from two characters (or the field's typeaheadMinQueryLength), then a "More {field} matching '{text}'" row that opens the value editor on the text through the opening query. None counts toward maxSearchResults. - Each distinct source is asked once per query after the text rests 150 ms; its field's rows append in config order once it settles, and a superseded query cancels the hold and any working source. - A field's isValueMatchAllowed: false turns these rows off, and an opt-in under it warns once in development. - The value-only code loads on first intent (the field's focus or a typed query) on a field whose config opts an operator in, so a page that opts none in pays for its wiring alone; a query typed while it loads lists its other rows at once. - The sheet presentation's content search keeps its suggestions. The FR27-FR29 status cells move from the implementation gap to their evidence.
1 parent 617f8cc commit 113fc7d

16 files changed

Lines changed: 1933 additions & 42 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] `PowerSearch`: an operator's new `isValueOnlyMatchAllowed: true` suggests its complete filters for a typed value alone, with no field label before it (`component:PowerSearch` FR27–FR29, DEC-8). Typing "fiction" offers `Genre is Fiction` after the field and field-and-operator rows: a `string` or `string_list` operator without a `searchSource` offers the typed text, an `enum` or `enum_list` operator the values with a word that starts with it (ignoring case and accents, whole-label matches first), and an operator with a `searchSource` the items that source returns. Each distinct source is asked once per query, once the text has rested 150 ms, and its rows append below the others. A field shows at most three of these rows from two characters (or its `typeaheadMinQueryLength`), then a "More {field} matching '{text}'" row that opens that field's value editor, carrying the typed text into an editor that searches (an `enum` field's editor opens on its full list). They do not count toward `maxSearchResults`. The option is off by default, so a config that opts no operator in keeps every list as it is; a field's `isValueMatchAllowed: false` turns these rows off too, and an opt-in under it warns once in development. The sheet presentation's content search does not list them.
6+
7+
@imdreamrunner

‎apps/storybook/stories/PowerSearch.stories.tsx‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,115 @@ export const WithContentSearchFieldKey: Story = {
16701670
name: 'Content Search Field Key',
16711671
};
16721672

1673+
// Operators that set isValueOnlyMatchAllowed answer a typed value with no
1674+
// field label: "in" suggests `Status is In Progress`, `Status is In Review`
1675+
// and `Tags has any of Infrastructure`, and "al" suggests `Assignee is any of
1676+
// Alice Johnson` once the slow people source answers. A field shows at most
1677+
// three rows, then a "More" row that opens the field's editor; an editor
1678+
// that searches opens on the typed text.
1679+
const valueOnlySlowUserSource: SearchSource = {
1680+
search: async (query: string) => {
1681+
await new Promise(resolve => setTimeout(resolve, 400));
1682+
return users.filter(u =>
1683+
u.label.toLowerCase().includes(query.toLowerCase()),
1684+
);
1685+
},
1686+
bootstrap: () => users,
1687+
};
1688+
1689+
const valueOnlyConfig: PowerSearchConfig = {
1690+
name: 'ValueOnlyMatches',
1691+
contentSearchFieldKey: 'title',
1692+
fields: [
1693+
{
1694+
key: 'title',
1695+
label: 'Title',
1696+
defaultOperator: 'contains',
1697+
operators: [
1698+
{key: 'contains', label: 'contains', value: {type: 'string'}},
1699+
],
1700+
},
1701+
{
1702+
key: 'status',
1703+
label: 'Status',
1704+
defaultOperator: 'is',
1705+
operators: [
1706+
{
1707+
key: 'is',
1708+
label: 'is',
1709+
value: {type: 'enum', values: statusValues},
1710+
isValueOnlyMatchAllowed: true,
1711+
},
1712+
{
1713+
key: 'is_not',
1714+
label: 'is not',
1715+
value: {type: 'enum', values: statusValues},
1716+
},
1717+
],
1718+
},
1719+
{
1720+
key: 'tags',
1721+
label: 'Tags',
1722+
defaultOperator: 'has_any',
1723+
operators: [
1724+
{
1725+
key: 'has_any',
1726+
label: 'has any of',
1727+
value: {type: 'enum_list', values: tagValues},
1728+
isValueOnlyMatchAllowed: true,
1729+
},
1730+
],
1731+
},
1732+
{
1733+
key: 'assignee',
1734+
label: 'Assignee',
1735+
defaultOperator: 'is_any_of',
1736+
operators: [
1737+
{
1738+
key: 'is_any_of',
1739+
label: 'is any of',
1740+
value: {type: 'entity_list', searchSource: valueOnlySlowUserSource},
1741+
isValueOnlyMatchAllowed: true,
1742+
},
1743+
],
1744+
},
1745+
],
1746+
};
1747+
1748+
export const ValueOnlyMatches: Story = {
1749+
render: args => {
1750+
const [filters, setFilters] = useState<PowerSearchFilter[]>([]);
1751+
return (
1752+
<div>
1753+
<PowerSearch
1754+
{...args}
1755+
config={valueOnlyConfig}
1756+
filters={filters}
1757+
onChange={newFilters => setFilters([...newFilters])}
1758+
/>
1759+
{filters.length > 0 && (
1760+
<pre
1761+
style={{
1762+
marginTop: 16,
1763+
padding: 12,
1764+
backgroundColor: '#f5f5f5',
1765+
borderRadius: 8,
1766+
fontSize: 12,
1767+
overflow: 'auto',
1768+
}}>
1769+
{JSON.stringify(filters, null, 2)}
1770+
</pre>
1771+
)}
1772+
</div>
1773+
);
1774+
},
1775+
args: {
1776+
placeholder: 'Type a value, like "in" or "al"...',
1777+
presentation: 'popover',
1778+
},
1779+
name: 'Value-only matches',
1780+
};
1781+
16731782
export const SizeVariants: Story = {
16741783
render: () => {
16751784
const [smFilters, setSmFilters] = useState<PowerSearchFilter[]>([

‎docs/specs/components/PowerSearch/PowerSearch.spec.md‎

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

‎internal/eslint-plugin-astryx/no-comment-provenance.baseline.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@
751751
"packages/core/src/PowerSearch/PowerSearchValueEditor.tsx": [
752752
"#1103",
753753
"#1106",
754-
"#1106",
755754
"#1107"
756755
],
757756
"packages/core/src/ProgressBar/ProgressBar.tsx": [

‎packages/core/locales/en.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,18 @@
14231423
"defaultMessage": "Editable filters removed",
14241424
"description": "Screen-reader announcement after a PowerSearch field's Clear all removes the filters the user can edit and keeps its read-only filters. Used instead of @astryx.powersearch.allFiltersRemoved while a read-only filter remains."
14251425
},
1426+
"@astryx.powersearch.valueOnlyMatch.text": {
1427+
"defaultMessage": "{field} {operator} \"{value}\"",
1428+
"description": "A typeahead suggestion for text typed with no field name before it: the complete filter that searches a text field for the typed text (for example 'Title contains \"partner\"'). field is the field label, operator the operator label, value the typed text, shown in quotation marks. Translators may reorder the parts."
1429+
},
1430+
"@astryx.powersearch.valueOnlyMatch.value": {
1431+
"defaultMessage": "{field} {operator} {value}",
1432+
"description": "A typeahead suggestion for text typed with no field name before it: a complete filter for one value that matches the text (for example \"Genre is Fiction\" or \"Owner is Jane Doe\"). field is the field label, operator the operator label, value the matching value's label. Translators may reorder the parts."
1433+
},
1434+
"@astryx.powersearch.valueOnlyMatch.more": {
1435+
"defaultMessage": "More {field} matching ''{text}''",
1436+
"description": "The last typeahead suggestion of a field that has more matches for the typed text than the list shows; choosing it opens that field's value editor on the text (for example \"More Owner matching 'jane'\"). field is the field label, text the typed text. In ICU syntax two apostrophes write one apostrophe."
1437+
},
14261438
"@astryx.resizable.collapsed": {
14271439
"defaultMessage": "Collapsed",
14281440
"description": "aria-valuetext for the Resizable drag handle (role=separator) while its panel is collapsed to zero size. Replaces the numeric value announcement, since the numeric value is clamped to the minimum while collapsed. Adjective describing the panel state, not a verb/command."

‎packages/core/src/PowerSearch/PowerSearch.doc.mjs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,44 @@ export const docs = {
210210
},
211211
],
212212
examples: [
213+
{
214+
label: 'Suggest complete filters from a typed value',
215+
code: `// isValueOnlyMatchAllowed: typing "fiction" with no field label offers
216+
// "Genre is Fiction", and typing "jane" asks the owner source and offers
217+
// "Owner is any of Jane Doe". A field shows at most three such rows, then a
218+
// "More Genre matching 'fiction'" row that opens Genre's editor. An editor
219+
// that searches, such as the owner's, opens on the typed text.
220+
const config = {
221+
name: 'Books',
222+
fields: [
223+
{
224+
key: 'genre',
225+
label: 'Genre',
226+
operators: [
227+
{
228+
key: 'is',
229+
label: 'is',
230+
value: {type: 'enum', values: genres},
231+
isValueOnlyMatchAllowed: true,
232+
},
233+
],
234+
},
235+
{
236+
key: 'owner',
237+
label: 'Owner',
238+
operators: [
239+
{
240+
key: 'is_any_of',
241+
label: 'is any of',
242+
value: {type: 'entity_list', searchSource: peopleSource},
243+
isValueOnlyMatchAllowed: true,
244+
},
245+
],
246+
},
247+
],
248+
};
249+
<PowerSearch config={config} filters={filters} onChange={setFilters} />`,
250+
},
213251
{
214252
label: 'Keep the popover on every device',
215253
code: `const [filters, setFilters] = useState([]);

0 commit comments

Comments
 (0)