@wallarm-org/design-system 4.7.0 → 4.8.0-rc-fix-claude-code.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/components/BulkBar/index.d.ts +5 -0
- package/dist/components/Drawer/classes.js +1 -1
- package/dist/components/NotificationCenter/NotificationCenter.d.ts +20 -0
- package/dist/components/NotificationCenter/NotificationCenter.js +65 -0
- package/dist/components/NotificationCenter/NotificationCenterBody.d.ts +18 -0
- package/dist/components/NotificationCenter/NotificationCenterBody.js +202 -0
- package/dist/components/NotificationCenter/NotificationCenterContent.d.ts +5 -0
- package/dist/components/NotificationCenter/NotificationCenterContent.js +42 -0
- package/dist/components/NotificationCenter/NotificationCenterHeader.d.ts +20 -0
- package/dist/components/NotificationCenter/NotificationCenterHeader.js +202 -0
- package/dist/components/NotificationCenter/NotificationCenterItem.d.ts +26 -0
- package/dist/components/NotificationCenter/NotificationCenterItem.js +211 -0
- package/dist/components/NotificationCenter/NotificationCenterItemTime.d.ts +9 -0
- package/dist/components/NotificationCenter/NotificationCenterItemTime.js +148 -0
- package/dist/components/NotificationCenter/NotificationCenterItemTitle.d.ts +14 -0
- package/dist/components/NotificationCenter/NotificationCenterItemTitle.js +115 -0
- package/dist/components/NotificationCenter/NotificationCenterTabs.d.ts +10 -0
- package/dist/components/NotificationCenter/NotificationCenterTabs.js +77 -0
- package/dist/components/NotificationCenter/NotificationCenterTrigger.d.ts +13 -0
- package/dist/components/NotificationCenter/NotificationCenterTrigger.js +138 -0
- package/dist/components/NotificationCenter/index.d.ts +9 -0
- package/dist/components/NotificationCenter/index.js +9 -0
- package/dist/components/Overlay/Overlay.js +1 -1
- package/dist/components/SearchInput/SearchInput.d.ts +7 -5
- package/dist/components/SearchInput/SearchInput.js +119 -101
- package/dist/components/Select/SelectSearchInput.d.ts +1 -1
- package/dist/components/Table/types.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +1 -0
- package/dist/components/Tabs/Tabs.js +30 -28
- package/dist/components/Tabs/TabsList/index.d.ts +1 -1
- package/dist/components/Tabs/index.d.ts +2 -2
- package/dist/components/Tour/TourPositioner.d.ts +3 -0
- package/dist/components/Tour/TourPositioner.js +4 -4
- package/dist/guidelines/foundations/color.md +157 -0
- package/dist/guidelines/foundations/focus.md +122 -0
- package/dist/guidelines/foundations/layering.md +131 -0
- package/dist/guidelines/foundations/radius-elevation.md +111 -0
- package/dist/guidelines/foundations/spacing.md +117 -0
- package/dist/guidelines/foundations/typography.md +114 -0
- package/dist/guidelines/patterns/app-layout.md +1567 -0
- package/dist/guidelines/patterns/auth-page.md +668 -0
- package/dist/guidelines/patterns/confirmation-dialogs.md +605 -0
- package/dist/guidelines/patterns/create-edit-forms.md +768 -0
- package/dist/guidelines/patterns/detail-drawer.md +868 -0
- package/dist/guidelines/patterns/empty-states.md +461 -0
- package/dist/guidelines/patterns/entity-table.md +533 -0
- package/dist/guidelines/patterns/feedback-toasts.md +493 -0
- package/dist/guidelines/patterns/filtering.md +630 -0
- package/dist/guidelines/patterns/resource-list-page.md +558 -0
- package/dist/guidelines/patterns/settings-page.md +752 -0
- package/dist/guidelines/rules.md +25 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/metadata/components.json +12641 -9320
- package/dist/metadata/guidelines.json +1705 -0
- package/dist/theme/typography.css +5 -0
- package/dist/utils/formatDateTime.d.ts +6 -0
- package/dist/utils/formatDateTime.js +13 -1
- package/package.json +6 -1
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Filtering
|
|
3
|
+
description: Use when narrowing a list or table by attributes, or picking values from a long list — filter chips, hierarchical scope, query builder, searchable select, picker dialog.
|
|
4
|
+
components: [FilterDropdown, FilterDropdownTrigger, FilterDropdownContent, FilterDropdownOption, FilterCascade, FilterCascadeTrigger, FilterCascadeContent, FilterCascadeCheckboxItem, FilterInput, SearchInput, PageToolbar, Select, SelectInput, SelectSearchInput, SegmentedTabs, SegmentedControl, NumericBadge, Table, TableEmptyState, EmptyState, Dialog, Field, Button]
|
|
5
|
+
keywords: [filter, filters, filter bar, filter chip, filter pill, facet, facets, toolbar, scope filter, hierarchy, cascade, query builder, search, searchable select, combobox, autocomplete, select search, picker, picker dialog, add users, multi select, view toggle]
|
|
6
|
+
order: 90
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Filtering
|
|
10
|
+
|
|
11
|
+
Pick the control by the shape of the values; every filter applies on pick.
|
|
12
|
+
|
|
13
|
+
## When to use
|
|
14
|
+
|
|
15
|
+
| Need | Use | Not |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| Text match on name or ID | `SearchInput` in `PageToolbar` | `Input` with a search icon |
|
|
18
|
+
| One status with counts | `SegmentedTabs` + `NumericBadge` | `FilterDropdown` |
|
|
19
|
+
| One flat attribute, one value | `FilterDropdown` with `allLabel` | `Select` in a toolbar |
|
|
20
|
+
| One flat attribute, several values | `FilterDropdown multiple` | `Checkbox` rows |
|
|
21
|
+
| A hierarchy (organization › deployment › application) | `FilterCascade` | Nested `DropdownMenu`s |
|
|
22
|
+
| Over four attributes, operators, AND/OR | `FilterInput` | Five `FilterDropdown`s |
|
|
23
|
+
| A value in a form | `Select` + `SelectInput` in `Field` | `FilterDropdown` |
|
|
24
|
+
| Pick rows from a large set | `Dialog width={960}` + selectable `Table` | A huge multi `Select` |
|
|
25
|
+
| Table or schema view | `SegmentedControl` with icons | `Tabs` |
|
|
26
|
+
|
|
27
|
+
There is no `FilterBar`, `PageFilters` or `Combobox` (use `Select` + `useSelectSearch`), and no `onApply` prop.
|
|
28
|
+
|
|
29
|
+
## Rules
|
|
30
|
+
|
|
31
|
+
**Filter bar layout**
|
|
32
|
+
|
|
33
|
+
- `PageToolbar` owns the 24px gutter and 12px gap. **Never** add `gap-*`, `px-*` or `py-*` to it.
|
|
34
|
+
- Wrap `SearchInput` and the filters in one `<div className='flex items-center gap-8'>`.
|
|
35
|
+
- `SearchInput` is `w-[320px]` in a toolbar, `flex-1` in a dialog.
|
|
36
|
+
- A view toggle goes last with `className='ml-auto'`.
|
|
37
|
+
- **Never** set a width on filter triggers; they hug their text up to 180px.
|
|
38
|
+
- **Never** stack two `SegmentedTabs` in one toolbar.
|
|
39
|
+
|
|
40
|
+
**FilterDropdown**
|
|
41
|
+
|
|
42
|
+
- Always give it a `label`; it names the trigger and aria-label.
|
|
43
|
+
- If the attribute is exclusive, use `allLabel` («All …» resets). If values combine, use `multiple` (OR-ed).
|
|
44
|
+
- Build `collection` with `createListCollection({ items, groupBy })`.
|
|
45
|
+
- Render options from `useFilterDropdown().groups` in a child component so they follow the search.
|
|
46
|
+
- `details.value` of `[]` means unset. Pass counts as `hint`.
|
|
47
|
+
- **Never** put `FilterDropdown` in a form or add an Apply button to a filter menu.
|
|
48
|
+
|
|
49
|
+
**FilterCascade**
|
|
50
|
+
|
|
51
|
+
- Import all cascade parts from `@wallarm-org/design-system/FilterCascade`, never the root.
|
|
52
|
+
- Build `collection` with `createFilterCascadeCollection(items, accessors)`; plain `{ value, label, children }` items need no accessors.
|
|
53
|
+
- If a level loads on demand, pass `loadChildren` and mark parents `hasChildren`. If a parent is pickable, pass `parentLabel`.
|
|
54
|
+
- If the menu needs a toggle ("Own only"), use `FilterCascadeCheckboxItem` in `FilterCascadeSection`; you keep its state.
|
|
55
|
+
- **Never** leave a description empty; show "No policies" for zero.
|
|
56
|
+
|
|
57
|
+
**FilterInput**
|
|
58
|
+
|
|
59
|
+
- Pass `fields` (`name`, `label`, `type`, `values`) and `value` / `onChange(ExprNode | null)`. Its menus and chips are built in.
|
|
60
|
+
|
|
61
|
+
**Searchable select**
|
|
62
|
+
|
|
63
|
+
- Put `SelectSearchInput` in `SelectHeader`, wired to `useSelectSearch`. Pass the original collection to `Select`; render `filteredCollection`.
|
|
64
|
+
- If the menu must match the trigger, pass `positioning={{ sameWidth: true }}` and `SelectPositioner className='min-w-full max-w-full'`; otherwise it is 240–320px.
|
|
65
|
+
- Option icons: set `icon` on each item.
|
|
66
|
+
- For several values use `SelectInput multiple`. `SelectButtonTag` is a trigger, not a chip list.
|
|
67
|
+
|
|
68
|
+
**Picker dialog**
|
|
69
|
+
|
|
70
|
+
- Use `Dialog width={960}`; there is no `DIALOG_SIZES`.
|
|
71
|
+
- Dialog parts own the 24px gutter. **Never** pad them. `DialogBody` has no `className`: put `flex flex-col gap-8` on a child div, search and tabs in `flex items-center gap-12`.
|
|
72
|
+
- Pass `getRowId` so selection survives search and paging.
|
|
73
|
+
- Primary is `disabled` "Add users" until rows are picked, then "Add 1 user", "Add 3 users".
|
|
74
|
+
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
A filter bar over a table: search, a multiple and a single filter, a scope chip, and the view toggle last.
|
|
78
|
+
|
|
79
|
+
Every pick applies at once. When the filters match nothing, the table offers "Reset filters",
|
|
80
|
+
which clears the search and every filter.
|
|
81
|
+
|
|
82
|
+
```tsx story=Default
|
|
83
|
+
import { useState } from 'react';
|
|
84
|
+
import { Badge } from '@wallarm-org/design-system/Badge';
|
|
85
|
+
import { Button } from '@wallarm-org/design-system/Button';
|
|
86
|
+
import { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateIllustration, EmptyStateMessage, EmptyStateTitle } from '@wallarm-org/design-system/EmptyState';
|
|
87
|
+
import { createFilterCascadeCollection, FilterCascade, FilterCascadeContent, FilterCascadeTrigger, type FilterCascadeValueChangeDetails } from '@wallarm-org/design-system/FilterCascade';
|
|
88
|
+
import { FilterDropdown, FilterDropdownAllOption, FilterDropdownContent, FilterDropdownFooter, FilterDropdownOption, FilterDropdownTrigger, type FilterDropdownValueChangeDetails, useFilterDropdown } from '@wallarm-org/design-system/FilterDropdown';
|
|
89
|
+
import { FilterX, List, SearchX, Workflow } from '@wallarm-org/design-system/icons';
|
|
90
|
+
import { Page, PageContent, PageDescription, PageHeader, PageHeaderGroup, PageTitle, PageToolbar } from '@wallarm-org/design-system/Page';
|
|
91
|
+
import { SearchInput } from '@wallarm-org/design-system/SearchInput';
|
|
92
|
+
import { SegmentedControl, SegmentedControlItem } from '@wallarm-org/design-system/SegmentedControl';
|
|
93
|
+
import { createListCollection } from '@wallarm-org/design-system/Select';
|
|
94
|
+
import { type TableCellContext, type TableColumnDef, Table, TableEmptyState } from '@wallarm-org/design-system/Table';
|
|
95
|
+
|
|
96
|
+
export const Default = () => {
|
|
97
|
+
const [query, setQuery] = useState('');
|
|
98
|
+
const [types, setTypes] = useState<string[]>([]);
|
|
99
|
+
const [status, setStatus] = useState<string[]>([]);
|
|
100
|
+
const [scope, setScope] = useState<string[]>([]);
|
|
101
|
+
const [view, setView] = useState('table');
|
|
102
|
+
|
|
103
|
+
const TYPE_LABELS: Record<AttackType, string> = {
|
|
104
|
+
sqli: 'SQL injection',
|
|
105
|
+
xss: 'XSS',
|
|
106
|
+
rce: 'RCE',
|
|
107
|
+
ptrav: 'Path traversal',
|
|
108
|
+
ssrf: 'SSRF',
|
|
109
|
+
};
|
|
110
|
+
const typeItems = Object.entries(TYPE_LABELS).map(([value, label]) => ({
|
|
111
|
+
value,
|
|
112
|
+
label,
|
|
113
|
+
count: ATTACKS.filter(attack => attack.type === value).length,
|
|
114
|
+
}));
|
|
115
|
+
const typeOptions = createListCollection({ items: typeItems });
|
|
116
|
+
const statusOptions = createListCollection({
|
|
117
|
+
items: [
|
|
118
|
+
{ value: 'blocked', label: 'Blocked' },
|
|
119
|
+
{ value: 'monitored', label: 'Monitored' },
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
const scopeOptions = createFilterCascadeCollection(SCOPES);
|
|
123
|
+
|
|
124
|
+
const renderType = ({ row }: TableCellContext<Attack, unknown>) => TYPE_LABELS[row.original.type];
|
|
125
|
+
|
|
126
|
+
const renderStatus = ({ row }: TableCellContext<Attack, unknown>) =>
|
|
127
|
+
row.original.status === 'blocked' ? (
|
|
128
|
+
<Badge variant='dotted' type='secondary' color='red'>
|
|
129
|
+
Blocked
|
|
130
|
+
</Badge>
|
|
131
|
+
) : (
|
|
132
|
+
<Badge variant='dotted' type='secondary' color='yellow'>
|
|
133
|
+
Monitored
|
|
134
|
+
</Badge>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const columns: TableColumnDef<Attack>[] = [
|
|
138
|
+
{ accessorKey: 'type', header: 'Type', size: 160, cell: renderType },
|
|
139
|
+
{ accessorKey: 'path', header: 'Request', size: 280 },
|
|
140
|
+
{ accessorKey: 'source', header: 'Source IP', size: 160 },
|
|
141
|
+
{ accessorKey: 'status', header: 'Status', size: 140, cell: renderStatus },
|
|
142
|
+
{ accessorKey: 'hits', header: 'Hits', size: 100 },
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const search = query.trim().toLowerCase();
|
|
146
|
+
const rows = ATTACKS.filter(
|
|
147
|
+
attack =>
|
|
148
|
+
(attack.path.toLowerCase().includes(search) || attack.source.includes(search)) &&
|
|
149
|
+
(types.length === 0 || types.includes(attack.type)) &&
|
|
150
|
+
(status.length === 0 || status.includes(attack.status)) &&
|
|
151
|
+
(scope.length === 0 || attack.deployment === scope[0]) &&
|
|
152
|
+
(scope.length < 2 || attack.application === scope[1]),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const handleTypesChange = (details: FilterDropdownValueChangeDetails) => setTypes(details.value);
|
|
156
|
+
const handleStatusChange = (details: FilterDropdownValueChangeDetails) =>
|
|
157
|
+
setStatus(details.value);
|
|
158
|
+
const handleScopeChange = (details: FilterCascadeValueChangeDetails) => setScope(details.value);
|
|
159
|
+
|
|
160
|
+
const handleReset = () => {
|
|
161
|
+
setQuery('');
|
|
162
|
+
setTypes([]);
|
|
163
|
+
setStatus([]);
|
|
164
|
+
setScope([]);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Page name='attacks' fullSize fixedHeight data-testid='attacks-page'>
|
|
169
|
+
<PageHeader>
|
|
170
|
+
<PageHeaderGroup className='flex-1'>
|
|
171
|
+
<PageTitle>Attacks</PageTitle>
|
|
172
|
+
<PageDescription>
|
|
173
|
+
Malicious requests the filtering nodes detected in the last 7 days.
|
|
174
|
+
</PageDescription>
|
|
175
|
+
</PageHeaderGroup>
|
|
176
|
+
</PageHeader>
|
|
177
|
+
|
|
178
|
+
<PageToolbar>
|
|
179
|
+
<div className='flex items-center gap-8'>
|
|
180
|
+
<SearchInput
|
|
181
|
+
value={query}
|
|
182
|
+
onChange={setQuery}
|
|
183
|
+
placeholder='Search request or IP'
|
|
184
|
+
className='w-[320px]'
|
|
185
|
+
data-testid='attacks-search'
|
|
186
|
+
/>
|
|
187
|
+
<FilterDropdown
|
|
188
|
+
label='Type'
|
|
189
|
+
multiple
|
|
190
|
+
collection={typeOptions}
|
|
191
|
+
value={types}
|
|
192
|
+
onValueChange={handleTypesChange}
|
|
193
|
+
data-testid='attacks-type-filter'
|
|
194
|
+
>
|
|
195
|
+
<FilterDropdownTrigger />
|
|
196
|
+
<FilterDropdownContent>
|
|
197
|
+
{/* Under 8 options the menu has no search, so the options are listed directly.
|
|
198
|
+
From 8, render them from `useFilterDropdown().groups` in a child component. */}
|
|
199
|
+
{typeItems.map(item => (
|
|
200
|
+
<FilterDropdownOption key={item.value} item={item} hint={item.count} />
|
|
201
|
+
))}
|
|
202
|
+
<FilterDropdownFooter />
|
|
203
|
+
</FilterDropdownContent>
|
|
204
|
+
</FilterDropdown>
|
|
205
|
+
<FilterDropdown
|
|
206
|
+
label='Status'
|
|
207
|
+
allLabel='All statuses'
|
|
208
|
+
collection={statusOptions}
|
|
209
|
+
value={status}
|
|
210
|
+
onValueChange={handleStatusChange}
|
|
211
|
+
data-testid='attacks-status-filter'
|
|
212
|
+
>
|
|
213
|
+
<FilterDropdownTrigger />
|
|
214
|
+
<FilterDropdownContent>
|
|
215
|
+
<FilterDropdownAllOption />
|
|
216
|
+
{statusOptions.items.map(item => (
|
|
217
|
+
<FilterDropdownOption key={item.value} item={item} />
|
|
218
|
+
))}
|
|
219
|
+
</FilterDropdownContent>
|
|
220
|
+
</FilterDropdown>
|
|
221
|
+
<FilterCascade
|
|
222
|
+
label='Scope'
|
|
223
|
+
collection={scopeOptions}
|
|
224
|
+
parentLabel='Deployment level'
|
|
225
|
+
value={scope}
|
|
226
|
+
onValueChange={handleScopeChange}
|
|
227
|
+
data-testid='attacks-scope-filter'
|
|
228
|
+
>
|
|
229
|
+
<FilterCascadeTrigger />
|
|
230
|
+
<FilterCascadeContent />
|
|
231
|
+
</FilterCascade>
|
|
232
|
+
</div>
|
|
233
|
+
<SegmentedControl
|
|
234
|
+
value={view}
|
|
235
|
+
onChange={setView}
|
|
236
|
+
className='ml-auto'
|
|
237
|
+
data-testid='attacks-view-toggle'
|
|
238
|
+
>
|
|
239
|
+
<SegmentedControlItem value='table'>
|
|
240
|
+
<List />
|
|
241
|
+
<span className='sr-only'>Table view</span>
|
|
242
|
+
</SegmentedControlItem>
|
|
243
|
+
<SegmentedControlItem value='schema'>
|
|
244
|
+
<Workflow />
|
|
245
|
+
<span className='sr-only'>Schema view</span>
|
|
246
|
+
</SegmentedControlItem>
|
|
247
|
+
</SegmentedControl>
|
|
248
|
+
</PageToolbar>
|
|
249
|
+
|
|
250
|
+
<PageContent>
|
|
251
|
+
<Table
|
|
252
|
+
aria-label='Attacks'
|
|
253
|
+
data={rows}
|
|
254
|
+
columns={columns}
|
|
255
|
+
getRowId={getAttackId}
|
|
256
|
+
data-testid='attacks-table'
|
|
257
|
+
>
|
|
258
|
+
<TableEmptyState>
|
|
259
|
+
<EmptyState type='collection-empty' data-testid='attacks-no-results'>
|
|
260
|
+
<EmptyStateIllustration>
|
|
261
|
+
<SearchX />
|
|
262
|
+
</EmptyStateIllustration>
|
|
263
|
+
<EmptyStateMessage>
|
|
264
|
+
<EmptyStateTitle>No results found</EmptyStateTitle>
|
|
265
|
+
<EmptyStateDescription>
|
|
266
|
+
No attacks match your search or filters.
|
|
267
|
+
</EmptyStateDescription>
|
|
268
|
+
</EmptyStateMessage>
|
|
269
|
+
<EmptyStateActions>
|
|
270
|
+
<Button size='medium' variant='outline' color='neutral' onClick={handleReset}>
|
|
271
|
+
<FilterX />
|
|
272
|
+
Reset filters
|
|
273
|
+
</Button>
|
|
274
|
+
</EmptyStateActions>
|
|
275
|
+
</EmptyState>
|
|
276
|
+
</TableEmptyState>
|
|
277
|
+
</Table>
|
|
278
|
+
</PageContent>
|
|
279
|
+
</Page>
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
From eight options a filter menu gets a search, and its options follow the query.
|
|
285
|
+
|
|
286
|
+
Options are grouped by deployment and carry attack counts. On reopen, picked options are
|
|
287
|
+
pinned under «Selected»; a query with no match shows an empty message and keeps the menu open.
|
|
288
|
+
|
|
289
|
+
```tsx story=SearchableFilter
|
|
290
|
+
import { useState } from 'react';
|
|
291
|
+
import { FilterDropdown, FilterDropdownTrigger, type FilterDropdownValueChangeDetails } from '@wallarm-org/design-system/FilterDropdown';
|
|
292
|
+
import { createListCollection } from '@wallarm-org/design-system/Select';
|
|
293
|
+
|
|
294
|
+
export const SearchableFilter = () => {
|
|
295
|
+
const [applications, setApplications] = useState<string[]>([]);
|
|
296
|
+
const applicationOptions = createListCollection({
|
|
297
|
+
items: APPLICATIONS,
|
|
298
|
+
groupBy: item => item.deployment,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const handleApplicationsChange = (details: FilterDropdownValueChangeDetails) =>
|
|
302
|
+
setApplications(details.value);
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<div className='p-24'>
|
|
306
|
+
<FilterDropdown
|
|
307
|
+
label='Application'
|
|
308
|
+
multiple
|
|
309
|
+
collection={applicationOptions}
|
|
310
|
+
value={applications}
|
|
311
|
+
onValueChange={handleApplicationsChange}
|
|
312
|
+
data-testid='applications-filter'
|
|
313
|
+
>
|
|
314
|
+
<FilterDropdownTrigger />
|
|
315
|
+
<ApplicationMenu />
|
|
316
|
+
</FilterDropdown>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
A scope chip whose applications load on demand and whose deployments can be picked.
|
|
323
|
+
|
|
324
|
+
Each option shows its policy count, "No policies" for zero. ✕ on the trigger returns to every
|
|
325
|
+
scope, not one level up.
|
|
326
|
+
|
|
327
|
+
```tsx story=ScopeFilter
|
|
328
|
+
import { useState } from 'react';
|
|
329
|
+
import { createFilterCascadeCollection, FilterCascade, FilterCascadeContent, FilterCascadeItems, type FilterCascadeLevelData, FilterCascadeLevels, FilterCascadeParentItem, FilterCascadeSearch, FilterCascadeTrigger, type FilterCascadeValueChangeDetails } from '@wallarm-org/design-system/FilterCascade';
|
|
330
|
+
|
|
331
|
+
export const ScopeFilter = () => {
|
|
332
|
+
const [scope, setScope] = useState<string[]>([]);
|
|
333
|
+
const scopes = createFilterCascadeCollection(DEPLOYMENTS, {
|
|
334
|
+
getValue: node => node.id,
|
|
335
|
+
getLabel: node => node.name,
|
|
336
|
+
hasChildren: node => node.kind === 'deployment',
|
|
337
|
+
getIcon: node => (
|
|
338
|
+
<span
|
|
339
|
+
aria-hidden
|
|
340
|
+
className={
|
|
341
|
+
node.kind === 'deployment'
|
|
342
|
+
? 'size-6 rounded-full bg-badge-sky-strong'
|
|
343
|
+
: 'size-6 rounded-full bg-badge-teal-strong'
|
|
344
|
+
}
|
|
345
|
+
/>
|
|
346
|
+
),
|
|
347
|
+
getDescription: node =>
|
|
348
|
+
node.policies === 0
|
|
349
|
+
? 'No policies'
|
|
350
|
+
: `${node.policies} ${node.policies === 1 ? 'policy' : 'policies'}`,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const loadApplications = (deployment: ScopeNode) => fetchApplications(deployment.id);
|
|
354
|
+
const handleScopeChange = (details: FilterCascadeValueChangeDetails) => setScope(details.value);
|
|
355
|
+
const renderLevel = (level: FilterCascadeLevelData) =>
|
|
356
|
+
level.depth === 0 ? (
|
|
357
|
+
<FilterCascadeItems />
|
|
358
|
+
) : (
|
|
359
|
+
<>
|
|
360
|
+
<FilterCascadeParentItem />
|
|
361
|
+
<FilterCascadeItems />
|
|
362
|
+
</>
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<div className='p-24'>
|
|
367
|
+
<FilterCascade
|
|
368
|
+
label='Scope'
|
|
369
|
+
collection={scopes}
|
|
370
|
+
loadChildren={loadApplications}
|
|
371
|
+
parentLabel='Deployment level'
|
|
372
|
+
value={scope}
|
|
373
|
+
onValueChange={handleScopeChange}
|
|
374
|
+
data-testid='scope-filter'
|
|
375
|
+
>
|
|
376
|
+
<FilterCascadeTrigger />
|
|
377
|
+
<FilterCascadeContent>
|
|
378
|
+
<FilterCascadeSearch placeholder='Search' />
|
|
379
|
+
<FilterCascadeLevels>{renderLevel}</FilterCascadeLevels>
|
|
380
|
+
</FilterCascadeContent>
|
|
381
|
+
</FilterCascade>
|
|
382
|
+
</div>
|
|
383
|
+
);
|
|
384
|
+
};
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
A searchable select in a form, with the menu matching the trigger.
|
|
388
|
+
|
|
389
|
+
A settings field saves on pick, with no Save button. A query with no match shows
|
|
390
|
+
`SelectEmptyState` and keeps the menu open.
|
|
391
|
+
|
|
392
|
+
```tsx story=SearchableSelect
|
|
393
|
+
import { useState } from 'react';
|
|
394
|
+
import { Field, FieldDescription, FieldLabel } from '@wallarm-org/design-system/Field';
|
|
395
|
+
import { createListCollection, Select, SelectContent, SelectEmptyState, SelectHeader, SelectInput, SelectOption, SelectOptionIndicator, SelectOptionText, SelectPositioner, SelectSearchInput, useSelectSearch } from '@wallarm-org/design-system/Select';
|
|
396
|
+
|
|
397
|
+
export const SearchableSelect = () => {
|
|
398
|
+
const [timeZone, setTimeZone] = useState('UTC');
|
|
399
|
+
const timeZones = createListCollection({ items: TIME_ZONES });
|
|
400
|
+
const { searchValue, onSearchChange, filteredCollection } = useSelectSearch(timeZones);
|
|
401
|
+
|
|
402
|
+
const handleTimeZoneChange = (details: { value: string[] }) => {
|
|
403
|
+
const next = details.value[0] ?? timeZone;
|
|
404
|
+
setTimeZone(next);
|
|
405
|
+
onTimeZoneSaved(next);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
return (
|
|
409
|
+
<div className='w-[400px] p-24'>
|
|
410
|
+
<Field>
|
|
411
|
+
<FieldLabel>Time zone</FieldLabel>
|
|
412
|
+
<Select
|
|
413
|
+
collection={timeZones}
|
|
414
|
+
value={[timeZone]}
|
|
415
|
+
positioning={{ sameWidth: true }}
|
|
416
|
+
onValueChange={handleTimeZoneChange}
|
|
417
|
+
data-testid='timezone-select'
|
|
418
|
+
>
|
|
419
|
+
<SelectInput placeholder='Choose a time zone' data-testid='timezone-input' />
|
|
420
|
+
<SelectPositioner className='min-w-full max-w-full'>
|
|
421
|
+
<SelectHeader>
|
|
422
|
+
<SelectSearchInput value={searchValue} onChange={onSearchChange} />
|
|
423
|
+
</SelectHeader>
|
|
424
|
+
<SelectContent>
|
|
425
|
+
{filteredCollection.size === 0 ? (
|
|
426
|
+
<SelectEmptyState description={`No results for "${searchValue}"`} />
|
|
427
|
+
) : (
|
|
428
|
+
filteredCollection.items.map(item => (
|
|
429
|
+
<SelectOption key={item.value} item={item}>
|
|
430
|
+
<SelectOptionText>{item.label}</SelectOptionText>
|
|
431
|
+
<SelectOptionIndicator />
|
|
432
|
+
</SelectOption>
|
|
433
|
+
))
|
|
434
|
+
)}
|
|
435
|
+
</SelectContent>
|
|
436
|
+
</SelectPositioner>
|
|
437
|
+
</Select>
|
|
438
|
+
<FieldDescription>
|
|
439
|
+
Dates in reports and on the Attacks page use this time zone.
|
|
440
|
+
</FieldDescription>
|
|
441
|
+
</Field>
|
|
442
|
+
</div>
|
|
443
|
+
);
|
|
444
|
+
};
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
A picker dialog whose primary counts the selection: disabled "Add users", then "Add 2 users".
|
|
448
|
+
|
|
449
|
+
Search and status tabs sit over a selectable `Table`. Picked rows stay picked while the search
|
|
450
|
+
changes, because rows are keyed by `getRowId`.
|
|
451
|
+
|
|
452
|
+
```tsx story=PickerDialog
|
|
453
|
+
import { useState } from 'react';
|
|
454
|
+
import { Avatar, AvatarContent, AvatarDescription, AvatarFallback, AvatarName } from '@wallarm-org/design-system/Avatar';
|
|
455
|
+
import { Button } from '@wallarm-org/design-system/Button';
|
|
456
|
+
import { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogFooterControls, DialogHeader, DialogTitle } from '@wallarm-org/design-system/Dialog';
|
|
457
|
+
import { EmptyState, EmptyStateDescription, EmptyStateMessage, EmptyStateTitle } from '@wallarm-org/design-system/EmptyState';
|
|
458
|
+
import { UserPlus } from '@wallarm-org/design-system/icons';
|
|
459
|
+
import { NumericBadge } from '@wallarm-org/design-system/NumericBadge';
|
|
460
|
+
import { SearchInput } from '@wallarm-org/design-system/SearchInput';
|
|
461
|
+
import { SegmentedTabs, SegmentedTabsList, SegmentedTabsTrigger } from '@wallarm-org/design-system/SegmentedTabs';
|
|
462
|
+
import { type TableCellContext, type TableColumnDef, type TableRowSelectionState, Table } from '@wallarm-org/design-system/Table';
|
|
463
|
+
|
|
464
|
+
export const PickerDialog = () => {
|
|
465
|
+
const [open, setOpen] = useState(false);
|
|
466
|
+
const [query, setQuery] = useState('');
|
|
467
|
+
const [status, setStatus] = useState('all');
|
|
468
|
+
const [selection, setSelection] = useState<TableRowSelectionState>({});
|
|
469
|
+
|
|
470
|
+
const renderMember = ({ row }: TableCellContext<Member, unknown>) => (
|
|
471
|
+
<Avatar size='md'>
|
|
472
|
+
<AvatarFallback name={row.original.name} />
|
|
473
|
+
<AvatarContent>
|
|
474
|
+
<AvatarName>{row.original.name}</AvatarName>
|
|
475
|
+
<AvatarDescription>{row.original.email}</AvatarDescription>
|
|
476
|
+
</AvatarContent>
|
|
477
|
+
</Avatar>
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
const renderStatus = ({ row }: TableCellContext<Member, unknown>) =>
|
|
481
|
+
row.original.status === 'active' ? 'Active' : 'Invited';
|
|
482
|
+
|
|
483
|
+
const columns: TableColumnDef<Member>[] = [
|
|
484
|
+
{ accessorKey: 'name', header: 'User', size: 520, cell: renderMember },
|
|
485
|
+
{ accessorKey: 'status', header: 'Status', size: 200, cell: renderStatus },
|
|
486
|
+
];
|
|
487
|
+
|
|
488
|
+
const search = query.trim().toLowerCase();
|
|
489
|
+
const matching = MEMBERS.filter(
|
|
490
|
+
member =>
|
|
491
|
+
member.name.toLowerCase().includes(search) || member.email.toLowerCase().includes(search),
|
|
492
|
+
);
|
|
493
|
+
const activeCount = matching.filter(member => member.status === 'active').length;
|
|
494
|
+
const invitedCount = matching.length - activeCount;
|
|
495
|
+
const rows = status === 'all' ? matching : matching.filter(member => member.status === status);
|
|
496
|
+
const count = Object.keys(selection).length;
|
|
497
|
+
|
|
498
|
+
const handleOpenChange = (next: boolean) => {
|
|
499
|
+
setOpen(next);
|
|
500
|
+
if (!next) {
|
|
501
|
+
setQuery('');
|
|
502
|
+
setStatus('all');
|
|
503
|
+
setSelection({});
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const handleOpen = () => setOpen(true);
|
|
507
|
+
const handleAdd = () => {
|
|
508
|
+
onAddUsers(Object.keys(selection));
|
|
509
|
+
handleOpenChange(false);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
return (
|
|
513
|
+
<div className='p-24'>
|
|
514
|
+
<Button size='medium' onClick={handleOpen} data-testid='members-add'>
|
|
515
|
+
<UserPlus />
|
|
516
|
+
Add users
|
|
517
|
+
</Button>
|
|
518
|
+
<Dialog open={open} onOpenChange={handleOpenChange} width={960} data-testid='members-picker'>
|
|
519
|
+
<DialogContent>
|
|
520
|
+
<DialogHeader>
|
|
521
|
+
<DialogTitle>Add users to Security team</DialogTitle>
|
|
522
|
+
</DialogHeader>
|
|
523
|
+
<DialogBody>
|
|
524
|
+
<div className='flex flex-col gap-8'>
|
|
525
|
+
<div className='flex items-center gap-12'>
|
|
526
|
+
<SearchInput
|
|
527
|
+
value={query}
|
|
528
|
+
onChange={setQuery}
|
|
529
|
+
placeholder='Search name or email'
|
|
530
|
+
className='flex-1'
|
|
531
|
+
data-testid='members-search'
|
|
532
|
+
/>
|
|
533
|
+
<SegmentedTabs
|
|
534
|
+
value={status}
|
|
535
|
+
onChange={setStatus}
|
|
536
|
+
data-testid='members-status-tabs'
|
|
537
|
+
>
|
|
538
|
+
<SegmentedTabsList>
|
|
539
|
+
<SegmentedTabsTrigger value='all'>
|
|
540
|
+
All <NumericBadge>{matching.length}</NumericBadge>
|
|
541
|
+
</SegmentedTabsTrigger>
|
|
542
|
+
<SegmentedTabsTrigger value='active'>
|
|
543
|
+
Active <NumericBadge>{activeCount}</NumericBadge>
|
|
544
|
+
</SegmentedTabsTrigger>
|
|
545
|
+
<SegmentedTabsTrigger value='invited'>
|
|
546
|
+
Invited <NumericBadge>{invitedCount}</NumericBadge>
|
|
547
|
+
</SegmentedTabsTrigger>
|
|
548
|
+
</SegmentedTabsList>
|
|
549
|
+
</SegmentedTabs>
|
|
550
|
+
</div>
|
|
551
|
+
<Table
|
|
552
|
+
aria-label='Users to add'
|
|
553
|
+
data={rows}
|
|
554
|
+
columns={columns}
|
|
555
|
+
getRowId={getMemberId}
|
|
556
|
+
rowSelection={selection}
|
|
557
|
+
onRowSelectionChange={setSelection}
|
|
558
|
+
data-testid='members-table'
|
|
559
|
+
>
|
|
560
|
+
{rows.length === 0 && (
|
|
561
|
+
<EmptyState type='collection-empty' data-testid='members-no-results'>
|
|
562
|
+
<EmptyStateMessage>
|
|
563
|
+
<EmptyStateTitle>No users found</EmptyStateTitle>
|
|
564
|
+
<EmptyStateDescription>No users match your search.</EmptyStateDescription>
|
|
565
|
+
</EmptyStateMessage>
|
|
566
|
+
</EmptyState>
|
|
567
|
+
)}
|
|
568
|
+
</Table>
|
|
569
|
+
</div>
|
|
570
|
+
</DialogBody>
|
|
571
|
+
<DialogFooter>
|
|
572
|
+
<DialogFooterControls>
|
|
573
|
+
<DialogClose asChild>
|
|
574
|
+
<Button variant='ghost' color='neutral' size='large'>
|
|
575
|
+
Cancel
|
|
576
|
+
</Button>
|
|
577
|
+
</DialogClose>
|
|
578
|
+
<Button
|
|
579
|
+
size='large'
|
|
580
|
+
disabled={count === 0}
|
|
581
|
+
onClick={handleAdd}
|
|
582
|
+
data-testid='members-confirm'
|
|
583
|
+
>
|
|
584
|
+
{count === 0 ? 'Add users' : `Add ${count} ${count === 1 ? 'user' : 'users'}`}
|
|
585
|
+
</Button>
|
|
586
|
+
</DialogFooterControls>
|
|
587
|
+
</DialogFooter>
|
|
588
|
+
</DialogContent>
|
|
589
|
+
</Dialog>
|
|
590
|
+
</div>
|
|
591
|
+
);
|
|
592
|
+
};
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
## States
|
|
596
|
+
|
|
597
|
+
| State | Show | Example component |
|
|
598
|
+
| --- | --- | --- |
|
|
599
|
+
| Unset | Single: `allLabel`; multi: `label` | `FilterDropdownTrigger` |
|
|
600
|
+
| One value / several | "Type • Lua" / "Type • 2", built in; never custom text or a tag per value | `FilterDropdownTrigger` |
|
|
601
|
+
| Reset one filter | Multi: ✕ or Backspace; single: «All». No per-filter Reset button | `FilterDropdown` |
|
|
602
|
+
| Reset scope | ✕ returns to the page default, not one level up | `FilterCascadeTrigger` |
|
|
603
|
+
| 8+ options | Search appears (`searchThreshold`) | `FilterDropdownSearch`, `SelectSearchInput` |
|
|
604
|
+
| Menu search, no match | Empty message; menu stays open | `FilterDropdownEmpty`, `SelectEmptyState` |
|
|
605
|
+
| Cascade level loading or failed | Built-in loading rows, then Retry | `FilterCascade` |
|
|
606
|
+
| Filters match no rows | `type='collection-empty'` + outline neutral "Reset filters"; never a create CTA | `TableEmptyState` |
|
|
607
|
+
| Default value | Pinned first in a "Suggested" group | `SelectGroup` |
|
|
608
|
+
| Select on settings page | Saves on pick, toast; no Save button | `Select`, `Toast` |
|
|
609
|
+
| Picker running | Primary `loading`, dialog open; on success close and toast "3 users added" | `Button`, `Dialog` |
|
|
610
|
+
| Picker, no match | `EmptyState type='collection-empty'` as a direct `Table` child; `TableEmptyState` is too tall | `EmptyState` |
|
|
611
|
+
| Picker, already a member | Leave the row out of `data` | `Table` |
|
|
612
|
+
|
|
613
|
+
## What your app owns
|
|
614
|
+
|
|
615
|
+
| You own | The DS owns |
|
|
616
|
+
| --- | --- |
|
|
617
|
+
| Applying `details.value` to your data | Filter values and trigger text |
|
|
618
|
+
| URL sync (no router integration) | Nothing |
|
|
619
|
+
| "Reset all": every filter `[]`, search `''` | Per-filter clear |
|
|
620
|
+
| Option counts (`hint`, `getDescription`); a pinned option goes first in its own `category` | Rendering them |
|
|
621
|
+
| Scope dots: `size-6 rounded-full` span, `bg-badge-violet-strong` / `-sky-strong` / `-teal-strong`, via `getIcon` | The icon slot |
|
|
622
|
+
| Server search: debounce `query`, refetch `data` | Client filtering only |
|
|
623
|
+
| Picker selection across pages: keep `rowSelection` keys (row ids) when `data` changes | Checkbox column |
|
|
624
|
+
| Picker user cell (name, muted email): see [Entity table](./entity-table.md) | Nothing |
|
|
625
|
+
|
|
626
|
+
## Related
|
|
627
|
+
|
|
628
|
+
- [Resource list page](./resource-list-page.md), [Entity table](./entity-table.md), [Empty states](./empty-states.md)
|
|
629
|
+
- [Feedback toasts](./feedback-toasts.md), [Settings page](./settings-page.md), [Create and edit forms](./create-edit-forms.md)
|
|
630
|
+
- [Spacing](../foundations/spacing.md)
|