@ansible/ansible-ui-framework 0.0.190 → 0.0.192

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Ansible UI Framework
2
+
3
+ Framework for building web applications using PatternFly.
4
+
5
+ Developed by the Ansible UI developers to make a consistent framework for build web applications using PatternFly.
6
+
7
+ ## Getting Started
8
+
9
+ ```
10
+ npm install @ansible/ansible-ui-framework
11
+ ```
@@ -0,0 +1,208 @@
1
+ # Table Guide
2
+
3
+ - [Typescript Interface](#typescript-interface)
4
+ - [Page layout](#page-layout)
5
+ - [View](#view)
6
+ - [Table Columns](#table-columns)
7
+ - [Page Table](#page-table)
8
+ - [Toolbar Filters](#toolbar-filters)
9
+ - [Toolbar Actions](#toolbar-actions)
10
+ - [Row Actions](#row-actions)
11
+
12
+ ## Typescript Interface
13
+
14
+ ```ts
15
+ export interface IPerson {
16
+ name: string
17
+ }
18
+ ```
19
+
20
+ ## Page layout
21
+
22
+ The page layout enables the layout to be responsive - responding to different page sizes and adjusting padding and borders.
23
+
24
+ ```tsx
25
+ export function Persons() {
26
+ return (
27
+ <PageLayout>
28
+ <PageHeader title="Persons" />
29
+ <PageBody>Table will go here</PageBody>
30
+ </PageLayout>
31
+ )
32
+ }
33
+ ```
34
+
35
+ ## View
36
+
37
+ Each table uses a view using a React hook. The view handles the state for the table. Sorting, filtering, pagination, etc...
38
+
39
+ ```tsx
40
+ const view = useView()
41
+ ```
42
+
43
+ For different backends, the view can be wrapped to make a specific view hook for the API.
44
+
45
+ ```tsx
46
+ export function Persons() {
47
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
48
+ ...
49
+ }
50
+ ```
51
+
52
+ ## Table Columns
53
+
54
+ ```tsx
55
+ export function Persons() {
56
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
57
+ const tableColumns = useMemo<ITableColumn<IPerson>[]>(
58
+ () => [
59
+ {
60
+ header: 'Name',
61
+ cell: (person) => <TextCell text={person.name} />,
62
+ sort: 'name',
63
+ },
64
+ ],
65
+ []
66
+ )
67
+ ...
68
+ }
69
+ ```
70
+
71
+ ## Page Table
72
+
73
+ The PageTable component takes in the properties from the view and shows a table for the view using the columns.
74
+
75
+ ```tsx
76
+ export function Persons() {
77
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
78
+ const tableColumns = useMemo<ITableColumn<IPerson>[]>(
79
+ () => [
80
+ {
81
+ header: 'Name',
82
+ cell: (person) => <TextCell text={person.name} />,
83
+ sort: 'name',
84
+ },
85
+ ],
86
+ []
87
+ )
88
+ return (
89
+ <PageLayout>
90
+ <PageHeader title="Persons" />
91
+ <PageBody>
92
+ <PageTable<IPerson> tableColumns={tableColumns} {...view} />
93
+ </PageBody>
94
+ </PageLayout>
95
+ )
96
+ }
97
+ ```
98
+
99
+ ## Toolbar Filters
100
+
101
+ Filters are specified using IToolbarFilter. The key is used for url querystring persistence. The query is used by the view to make the API call with the filter.
102
+
103
+ ```tsx
104
+ export function Persons() {
105
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
106
+ const tableColumns = ...
107
+ const toolbarFilters = useMemo<IToolbarFilter[]>(
108
+ () => [
109
+ {
110
+ key: 'name',
111
+ label: 'Name',
112
+ type: 'string',
113
+ query: 'name',
114
+ },
115
+ ],
116
+ []
117
+ )
118
+ return (
119
+ <PageLayout>
120
+ <PageHeader title="Persons" />
121
+ <PageBody>
122
+ <PageTable<IPerson>
123
+ tableColumns={tableColumns}
124
+ toolbarFilters={toolbarFilters}
125
+ {...view} />
126
+ </PageBody>
127
+ </PageLayout>
128
+ )
129
+ }
130
+ ```
131
+
132
+ ## Toolbar Actions
133
+
134
+ Toolbar actions are specified using ITypedAction.
135
+
136
+ ```tsx
137
+ export function Persons() {
138
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
139
+ const tableColumns = ...
140
+ const toolbarFilters = ...
141
+ const toolbarActions = useMemo<ITypedAction<IPerson>[]>(
142
+ () => [
143
+ {
144
+ type: TypedActionType.button,
145
+ variant: ButtonVariant.primary,
146
+ icon: PlusIcon,
147
+ label: 'Create person',
148
+ onClick: () => alert("TODO"),
149
+ },
150
+ {
151
+ type: TypedActionType.bulk,
152
+ icon: TrashIcon,
153
+ label: 'Deleted selected persons',
154
+ onClick: (persons) => alert("TODO"),
155
+ },
156
+ ],
157
+ []
158
+ )
159
+ return (
160
+ <PageLayout>
161
+ <PageHeader title="Persons" />
162
+ <PageBody>
163
+ <PageTable<IPerson>
164
+ tableColumns={tableColumns}
165
+ toolbarFilters={toolbarFilters}
166
+ toolbarActions={toolbarActions}
167
+ {...view} />
168
+ </PageBody>
169
+ </PageLayout>
170
+ )
171
+ }
172
+ ```
173
+
174
+ ## Row Actions
175
+
176
+ Row actions are specified using ITypedAction.
177
+
178
+ ```tsx
179
+ export function Persons() {
180
+ const view = useMyApiView<IPerson>({ url: '/api/persons' })
181
+ const tableColumns = ...
182
+ const toolbarFilters = ...
183
+ const toolbarActions = ...
184
+ const rowActions = useMemo<IItemAction<Team>[]>(
185
+ () => [
186
+ {
187
+ icon: EditIcon,
188
+ label: 'Edit person',
189
+ onClick: (person) => alert("TODO"),
190
+ },
191
+ ],
192
+ [t]
193
+ )
194
+ return (
195
+ <PageLayout>
196
+ <PageHeader title="Persons" />
197
+ <PageBody>
198
+ <PageTable<IPerson>
199
+ tableColumns={tableColumns}
200
+ toolbarFilters={toolbarFilters}
201
+ toolbarActions={toolbarActions}
202
+ rowActions={rowActions}
203
+ {...view} />
204
+ </PageBody>
205
+ </PageLayout>
206
+ )
207
+ }
208
+ ```
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@ansible/ansible-ui-framework",
3
3
  "description": "Framework for building web applications using PatternFly.",
4
- "version": "0.0.190",
4
+ "version": "0.0.192",
5
5
  "author": "Red Hat",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/ansible/ansible-ui.git"
10
10
  },
11
- "homepage": "https://github.com/ansible/ansible-ui/framework#readme",
11
+ "homepage": "https://github.com/ansible/ansible-ui/tree/main/framework#readme",
12
12
  "type": "module",
13
13
  "exports": {
14
14
  ".": {