@etsoo/react 1.4.79 → 1.4.80

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.
@@ -35,11 +35,11 @@ export interface ViewPageProps<T extends {}> extends Exclude<CommonPageProps, 'c
35
35
  /**
36
36
  * Actions
37
37
  */
38
- actions?: React.ReactNode | ((data: T) => React.ReactNode);
38
+ actions?: React.ReactNode | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
39
39
  /**
40
40
  * Children
41
41
  */
42
- children?: React.ReactNode | ((data: T) => React.ReactNode);
42
+ children?: React.ReactNode | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
43
43
  /**
44
44
  * Fields to display
45
45
  */
@@ -63,13 +63,13 @@ export function ViewPage(props) {
63
63
  // Data
64
64
  const [data, setData] = React.useState();
65
65
  // Load data
66
- const onRefresh = async () => {
66
+ const refresh = async () => {
67
67
  const result = await loadData();
68
68
  if (result == null)
69
69
  return;
70
70
  setData(result);
71
71
  };
72
- return (React.createElement(CommonPage, { paddings: paddings, onRefresh: supportRefresh ? onRefresh : undefined, onUpdate: supportRefresh ? undefined : onRefresh, ...rest, scrollContainer: global }, data == null ? (React.createElement(LinearProgress, null)) : (React.createElement(React.Fragment, null,
72
+ return (React.createElement(CommonPage, { paddings: paddings, onRefresh: supportRefresh ? refresh : undefined, onUpdate: supportRefresh ? undefined : refresh, ...rest, scrollContainer: global }, data == null ? (React.createElement(LinearProgress, null)) : (React.createElement(React.Fragment, null,
73
73
  React.createElement(Grid, { container: true, justifyContent: "left", spacing: paddings, className: "ET-ViewPage", sx: {
74
74
  '.MuiTypography-subtitle2': {
75
75
  fontWeight: 'bold'
@@ -77,7 +77,8 @@ export function ViewPage(props) {
77
77
  } }, fields.map((field, index) => {
78
78
  // Get data
79
79
  const [itemData, itemLabel, gridProps] = getItemField(field, data);
80
- if (itemData == null)
80
+ // Some callback function may return '' instead of undefined
81
+ if (itemData == null || itemData === '')
81
82
  return undefined;
82
83
  // Layout
83
84
  return (React.createElement(Grid, { item: true, ...gridProps, key: index },
@@ -86,6 +87,6 @@ export function ViewPage(props) {
86
87
  ":"),
87
88
  React.createElement(Typography, { variant: "subtitle2" }, itemData)));
88
89
  })),
89
- actions != null && (React.createElement(Stack, { className: "ET-ViewPage-Actions", direction: "row", width: "100%", flexWrap: "wrap", justifyContent: "flex-end", paddingTop: paddings, paddingBottom: paddings, gap: paddings }, Utils.getResult(actions, data))),
90
- Utils.getResult(children, data)))));
90
+ actions != null && (React.createElement(Stack, { className: "ET-ViewPage-Actions", direction: "row", width: "100%", flexWrap: "wrap", justifyContent: "flex-end", paddingTop: paddings, paddingBottom: paddings, gap: paddings }, Utils.getResult(actions, data, refresh))),
91
+ Utils.getResult(children, data, refresh)))));
91
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.79",
3
+ "version": "1.4.80",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -60,12 +60,16 @@ export interface ViewPageProps<T extends {}>
60
60
  /**
61
61
  * Actions
62
62
  */
63
- actions?: React.ReactNode | ((data: T) => React.ReactNode);
63
+ actions?:
64
+ | React.ReactNode
65
+ | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
64
66
 
65
67
  /**
66
68
  * Children
67
69
  */
68
- children?: React.ReactNode | ((data: T) => React.ReactNode);
70
+ children?:
71
+ | React.ReactNode
72
+ | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
69
73
 
70
74
  /**
71
75
  * Fields to display
@@ -164,7 +168,7 @@ export function ViewPage<T extends {}>(props: ViewPageProps<T>) {
164
168
  const [data, setData] = React.useState<T>();
165
169
 
166
170
  // Load data
167
- const onRefresh = async () => {
171
+ const refresh = async () => {
168
172
  const result = await loadData();
169
173
  if (result == null) return;
170
174
  setData(result);
@@ -173,8 +177,8 @@ export function ViewPage<T extends {}>(props: ViewPageProps<T>) {
173
177
  return (
174
178
  <CommonPage
175
179
  paddings={paddings}
176
- onRefresh={supportRefresh ? onRefresh : undefined}
177
- onUpdate={supportRefresh ? undefined : onRefresh}
180
+ onRefresh={supportRefresh ? refresh : undefined}
181
+ onUpdate={supportRefresh ? undefined : refresh}
178
182
  {...rest}
179
183
  scrollContainer={global}
180
184
  >
@@ -198,7 +202,9 @@ export function ViewPage<T extends {}>(props: ViewPageProps<T>) {
198
202
  const [itemData, itemLabel, gridProps] =
199
203
  getItemField(field, data);
200
204
 
201
- if (itemData == null) return undefined;
205
+ // Some callback function may return '' instead of undefined
206
+ if (itemData == null || itemData === '')
207
+ return undefined;
202
208
 
203
209
  // Layout
204
210
  return (
@@ -227,10 +233,10 @@ export function ViewPage<T extends {}>(props: ViewPageProps<T>) {
227
233
  paddingBottom={paddings}
228
234
  gap={paddings}
229
235
  >
230
- {Utils.getResult(actions, data)}
236
+ {Utils.getResult(actions, data, refresh)}
231
237
  </Stack>
232
238
  )}
233
- {Utils.getResult(children, data)}
239
+ {Utils.getResult(children, data, refresh)}
234
240
  </React.Fragment>
235
241
  )}
236
242
  </CommonPage>