@etsoo/react 1.4.6 → 1.4.7
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.
|
@@ -3,18 +3,25 @@ import { RouteComponentProps } from '@reach/router';
|
|
|
3
3
|
/**
|
|
4
4
|
* Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
|
|
5
5
|
*/
|
|
6
|
-
export declare type EditPageRouterProps
|
|
6
|
+
export declare type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
7
|
+
/**
|
|
8
|
+
* Get edit page id
|
|
9
|
+
* @param props Route props
|
|
10
|
+
* @param type Target data type
|
|
11
|
+
* @returns Data
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEditPageId<T extends DataTypes.BasicNames = 'number'>(props: EditPageRouterProps, type: T): DataTypes.BasicConditional<T> | undefined;
|
|
7
14
|
/**
|
|
8
15
|
* Id router props, include 'id' (/:id) query parameter
|
|
9
16
|
*/
|
|
10
|
-
export declare type IdRouterProps
|
|
11
|
-
id:
|
|
17
|
+
export declare type IdRouterProps = RouteComponentProps<{
|
|
18
|
+
id: string;
|
|
12
19
|
}>;
|
|
13
20
|
/**
|
|
14
21
|
* Wildcard router props, (/*) query parameter
|
|
15
22
|
*/
|
|
16
|
-
export declare type WildcardRouterProps
|
|
17
|
-
'*':
|
|
23
|
+
export declare type WildcardRouterProps = RouteComponentProps<{
|
|
24
|
+
'*': string;
|
|
18
25
|
}>;
|
|
19
26
|
/**
|
|
20
27
|
* Id state router props, include 'id' in location.state
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Get edit page id
|
|
4
|
+
* @param props Route props
|
|
5
|
+
* @param type Target data type
|
|
6
|
+
* @returns Data
|
|
7
|
+
*/
|
|
8
|
+
export function getEditPageId(props, type) {
|
|
9
|
+
var _a;
|
|
10
|
+
const id = (_a = props.id) !== null && _a !== void 0 ? _a : props['*'];
|
|
11
|
+
if (id == null || id === '')
|
|
12
|
+
return undefined;
|
|
13
|
+
return DataTypes.convertByType(id, type);
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { RouteComponentProps } from '@reach/router';
|
|
3
|
+
import { Props } from 'react-input-mask';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
|
|
6
7
|
*/
|
|
7
|
-
export type EditPageRouterProps
|
|
8
|
-
|
|
8
|
+
export type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get edit page id
|
|
12
|
+
* @param props Route props
|
|
13
|
+
* @param type Target data type
|
|
14
|
+
* @returns Data
|
|
15
|
+
*/
|
|
16
|
+
export function getEditPageId<T extends DataTypes.BasicNames = 'number'>(
|
|
17
|
+
props: EditPageRouterProps,
|
|
18
|
+
type: T
|
|
19
|
+
): DataTypes.BasicConditional<T> | undefined {
|
|
20
|
+
const id = props.id ?? props['*'];
|
|
21
|
+
if (id == null || id === '') return undefined;
|
|
22
|
+
return DataTypes.convertByType(id, type);
|
|
23
|
+
}
|
|
9
24
|
|
|
10
25
|
/**
|
|
11
26
|
* Id router props, include 'id' (/:id) query parameter
|
|
12
27
|
*/
|
|
13
|
-
export type IdRouterProps
|
|
14
|
-
RouteComponentProps<{ id: T }>;
|
|
28
|
+
export type IdRouterProps = RouteComponentProps<{ id: string }>;
|
|
15
29
|
|
|
16
30
|
/**
|
|
17
31
|
* Wildcard router props, (/*) query parameter
|
|
18
32
|
*/
|
|
19
|
-
export type WildcardRouterProps
|
|
20
|
-
RouteComponentProps<{ '*': T }>;
|
|
33
|
+
export type WildcardRouterProps = RouteComponentProps<{ '*': string }>;
|
|
21
34
|
|
|
22
35
|
/**
|
|
23
36
|
* Id state router props, include 'id' in location.state
|