studiokit-scaffolding-js 4.5.1 → 4.5.2
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/lib/components/HOC/ActivityRequiredComponent.d.ts +19 -22
- package/lib/components/HOC/ActivityRequiredComponent.js +29 -13
- package/lib/components/HOC/CollectionComponent.js +3 -3
- package/lib/components/HOC/CollectionItemComponent.js +2 -2
- package/lib/components/HOC/GroupActivityRequiredComponent.d.ts +9 -6
- package/lib/components/HOC/GroupActivityRequiredComponent.js +12 -8
- package/lib/components/UserRoles/index.d.ts +7 -3
- package/lib/components/UserRoles/index.js +11 -11
- package/lib/hooks/useCollection.js +3 -3
- package/lib/hooks/useCollectionConfiguration.d.ts +1 -0
- package/lib/hooks/useCollectionConfiguration.js +2 -0
- package/lib/hooks/useCollectionItem.js +3 -3
- package/lib/utils/collection.d.ts +2 -2
- package/lib/utils/collection.js +7 -4
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { BaseReduxState, OptionalRecord } from '../../types';
|
|
|
4
4
|
import { ActivityOptions } from '../../utils/baseActivity';
|
|
5
5
|
export interface ActivityRequiredStateProps {
|
|
6
6
|
hasAccess: boolean;
|
|
7
|
+
redirectPath: string;
|
|
7
8
|
}
|
|
8
9
|
export declare const configureActivityRequiredComponent: <TOwnProps extends {}>(WrappedComponent: React.ComponentType<TOwnProps>) => {
|
|
9
10
|
new (props: (TOwnProps & ActivityRequiredStateProps) | Readonly<TOwnProps & ActivityRequiredStateProps>): {
|
|
@@ -60,15 +61,14 @@ export declare const configureActivityRequiredComponent: <TOwnProps extends {}>(
|
|
|
60
61
|
};
|
|
61
62
|
/**
|
|
62
63
|
* Return `mapStateToProps` function. Add a `hasAccess` boolean property to the component's props
|
|
63
|
-
* checking whether the user has the passed `requiredActivity
|
|
64
|
+
* checking whether the user has the passed `requiredActivity`.
|
|
64
65
|
*
|
|
65
|
-
* @param
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* activity grants
|
|
66
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
67
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
68
|
+
* @param modelsProperty (Optional) The property used to locate the entity or entities needed for entity-level activity grants
|
|
69
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
70
70
|
*/
|
|
71
|
-
export declare const configureMapStateToProps: <TOwnProps extends {}>(accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string, modelsProperty?: string | undefined) => (state: BaseReduxState, ownProps?: TOwnProps | undefined) => ActivityRequiredStateProps;
|
|
71
|
+
export declare const configureMapStateToProps: <TOwnProps extends {}>(accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string, modelsProperty?: string | undefined, redirectPath?: string | ((options: ActivityOptions) => string | undefined) | undefined) => (state: BaseReduxState, ownProps?: TOwnProps | undefined) => ActivityRequiredStateProps;
|
|
72
72
|
/**
|
|
73
73
|
* This HOC ensures that the wrapped component is only rendered if the predicate provided is satisfied.
|
|
74
74
|
*
|
|
@@ -78,15 +78,14 @@ export declare const configureMapStateToProps: <TOwnProps extends {}>(accessPred
|
|
|
78
78
|
* If a lambda is passed as the predicate, it is passed (but may or may not opt to utilize) the `requiredActivity`
|
|
79
79
|
* parameter. It can be ignored if not needed by the lambda.
|
|
80
80
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
*
|
|
81
|
+
* @param WrappedComponent The component which requires activity/activities in order to render
|
|
82
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
83
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
84
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
86
85
|
*/
|
|
87
|
-
export default function activityRequiredComponent<TOwnProps extends {}>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options:
|
|
86
|
+
export default function activityRequiredComponent<TOwnProps extends {}>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string, redirectPath?: string | ((options: ActivityOptions) => string | undefined) | undefined): ComponentClass<TOwnProps>;
|
|
88
87
|
/**
|
|
89
|
-
* This HOC ensures that the wrapped component is rendered
|
|
88
|
+
* This HOC ensures that the wrapped component is rendered if the predicate provided is satisfied.
|
|
90
89
|
*
|
|
91
90
|
* Typically this component is used by passing one of the functions in utils/activities as the
|
|
92
91
|
* `accessPredicate` and a constant from "constants/activities" as the `requiredActivity`.
|
|
@@ -94,12 +93,10 @@ export default function activityRequiredComponent<TOwnProps extends {}>(WrappedC
|
|
|
94
93
|
* If a lambda is passed as the predicate, it is passed (but may or may not opt to utilize) the `requiredActivity`
|
|
95
94
|
* and `modelsProperty` parameters. They can be ignored if not needed by the lambda.
|
|
96
95
|
*
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
102
|
-
* activity grants
|
|
103
|
-
*
|
|
96
|
+
* @param WrappedComponent The component which requires activity/activities in order to render
|
|
97
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
98
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
99
|
+
* @param modelsProperty The property used to locate the entity or entities needed for entity-level activity grants
|
|
100
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
104
101
|
*/
|
|
105
|
-
export default function activityRequiredComponent<TOwnProps extends {}, TPropName extends string>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options:
|
|
102
|
+
export default function activityRequiredComponent<TOwnProps extends {}, TPropName extends string>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string, modelsProperty: TPropName, redirectPath?: string | ((options: ActivityOptions) => string | undefined) | undefined): ComponentClass<TOwnProps & OptionalRecord<TPropName, Model>>;
|
|
@@ -66,9 +66,9 @@ var configureActivityRequiredComponent = function (WrappedComponent) {
|
|
|
66
66
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
67
67
|
}
|
|
68
68
|
ActivityRequiredComponent.prototype.render = function () {
|
|
69
|
-
var _a = this.props, hasAccess = _a.hasAccess, rest = __rest(_a, ["hasAccess"]);
|
|
70
|
-
if (!
|
|
71
|
-
return react_1.default.createElement(react_router_dom_1.Redirect, { to:
|
|
69
|
+
var _a = this.props, hasAccess = _a.hasAccess, redirectPath = _a.redirectPath, rest = __rest(_a, ["hasAccess", "redirectPath"]);
|
|
70
|
+
if (!hasAccess) {
|
|
71
|
+
return react_1.default.createElement(react_router_dom_1.Redirect, { to: redirectPath });
|
|
72
72
|
}
|
|
73
73
|
return react_1.default.createElement(WrappedComponent, __assign({}, rest));
|
|
74
74
|
};
|
|
@@ -78,23 +78,39 @@ var configureActivityRequiredComponent = function (WrappedComponent) {
|
|
|
78
78
|
exports.configureActivityRequiredComponent = configureActivityRequiredComponent;
|
|
79
79
|
/**
|
|
80
80
|
* Return `mapStateToProps` function. Add a `hasAccess` boolean property to the component's props
|
|
81
|
-
* checking whether the user has the passed `requiredActivity
|
|
81
|
+
* checking whether the user has the passed `requiredActivity`.
|
|
82
82
|
*
|
|
83
|
-
* @param
|
|
84
|
-
*
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* activity grants
|
|
83
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
84
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
85
|
+
* @param modelsProperty (Optional) The property used to locate the entity or entities needed for entity-level activity grants
|
|
86
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
88
87
|
*/
|
|
89
|
-
var configureMapStateToProps = function (accessPredicate, requiredActivity, modelsProperty) { return function (state, ownProps) {
|
|
88
|
+
var configureMapStateToProps = function (accessPredicate, requiredActivity, modelsProperty, redirectPath) { return function (state, ownProps) {
|
|
89
|
+
var options = baseActivity_1.defaultOptions(state, ownProps, modelsProperty);
|
|
90
90
|
return {
|
|
91
|
-
hasAccess: accessPredicate(requiredActivity,
|
|
91
|
+
hasAccess: accessPredicate(requiredActivity, options),
|
|
92
|
+
redirectPath: (typeof redirectPath === 'function' ? redirectPath(options) : redirectPath) || '/'
|
|
92
93
|
};
|
|
93
94
|
}; };
|
|
94
95
|
exports.configureMapStateToProps = configureMapStateToProps;
|
|
95
|
-
|
|
96
|
+
/**
|
|
97
|
+
* This HOC ensures that the wrapped component is rendered if the predicate provided is satisfied.
|
|
98
|
+
*
|
|
99
|
+
* Typically this component is used by passing one of the functions in utils/activities as the
|
|
100
|
+
* `accessPredicate` and a constant from "constants/activities" as the `requiredActivity`.
|
|
101
|
+
*
|
|
102
|
+
* If a lambda is passed as the predicate, it is passed (but may or may not opt to utilize) the `requiredActivity`
|
|
103
|
+
* and `modelsProperty` parameters. They can be ignored if not needed by the lambda.
|
|
104
|
+
*
|
|
105
|
+
* @param WrappedComponent The component which requires activity/activities in order to render
|
|
106
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
107
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
108
|
+
* @param modelsProperty The property used to locate the entity or entities needed for entity-level activity grants
|
|
109
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
110
|
+
*/
|
|
111
|
+
function activityRequiredComponent(WrappedComponent, accessPredicate, requiredActivity, modelsProperty, redirectPath) {
|
|
96
112
|
var ActivityRequiredComponent = exports.configureActivityRequiredComponent(WrappedComponent);
|
|
97
|
-
var mapStateToProps = exports.configureMapStateToProps(accessPredicate, requiredActivity, modelsProperty);
|
|
113
|
+
var mapStateToProps = exports.configureMapStateToProps(accessPredicate, requiredActivity, modelsProperty, redirectPath);
|
|
98
114
|
// @ts-ignore: could not match inferred type from the `connect` HOC
|
|
99
115
|
return react_redux_1.connect(mapStateToProps)(ActivityRequiredComponent);
|
|
100
116
|
}
|
|
@@ -123,11 +123,11 @@ function configureCollectionComponent(WrappedComponent, LoaderComponent) {
|
|
|
123
123
|
collection_1.initializeCollection(model, this.load, this.getCollectionMethodConfig());
|
|
124
124
|
};
|
|
125
125
|
CollectionComponent.prototype.componentDidUpdate = function (prevProps) {
|
|
126
|
-
var prevModel = prevProps.model, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
127
|
-
var _a = this.props, model = _a.model, pathParams = _a.pathParams, queryParams = _a.queryParams;
|
|
126
|
+
var prevModel = prevProps.model, prevModelName = prevProps.modelName, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
127
|
+
var _a = this.props, model = _a.model, modelName = _a.modelName, pathParams = _a.pathParams, queryParams = _a.queryParams;
|
|
128
128
|
var fetchingId = this.state.fetchingId;
|
|
129
129
|
model_1.handleModelFetchFinish(model, prevModel, fetchingId, this.changeModelStatus);
|
|
130
|
-
collection_1.handleCollectionParamsChange(pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
130
|
+
collection_1.handleCollectionParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
131
131
|
};
|
|
132
132
|
CollectionComponent.prototype.componentWillUnmount = function () {
|
|
133
133
|
var model = this.props.model;
|
|
@@ -125,10 +125,10 @@ function configureCollectionItemComponent(WrappedComponent, LoaderComponent) {
|
|
|
125
125
|
collection_1.initializeCollectionItem(model, this.load, this.getCollectionMethodConfig());
|
|
126
126
|
};
|
|
127
127
|
CollectionItemComponent.prototype.componentDidUpdate = function (prevProps) {
|
|
128
|
-
var prevModel = prevProps.model, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
128
|
+
var prevModel = prevProps.model, prevModelName = prevProps.modelName, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
129
129
|
var _a = this.props, modelName = _a.modelName, model = _a.model, pathParams = _a.pathParams, queryParams = _a.queryParams;
|
|
130
130
|
model_1.handleModelFetchFinish(model, prevModel, undefined, this.setModelStatus);
|
|
131
|
-
collection_1.handleCollectionItemParamsChange(modelName, pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
131
|
+
collection_1.handleCollectionItemParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
132
132
|
};
|
|
133
133
|
CollectionItemComponent.prototype.render = function () {
|
|
134
134
|
var _a = this.props, history = _a.history, match = _a.match, location = _a.location, staticContext = _a.staticContext, otherProps = __rest(_a, ["history", "match", "location", "staticContext"]);
|
|
@@ -15,15 +15,18 @@ export interface GroupRelatedEntity extends Model {
|
|
|
15
15
|
* checking whether the user has the passed `requiredActivity` for the group referenced by
|
|
16
16
|
* `ownProps.model.groupId`, if any.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
18
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
19
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
20
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
21
21
|
*/
|
|
22
|
-
export declare const configureMapStateToProps: <TOwnProps extends CollectionItemComponentWrappedProps<GroupRelatedEntity>>(accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string) => (state: BaseReduxState, ownProps?: TOwnProps | undefined) => ActivityRequiredStateProps;
|
|
22
|
+
export declare const configureMapStateToProps: <TOwnProps extends CollectionItemComponentWrappedProps<GroupRelatedEntity>>(accessPredicate: (requiredActivity: string, options: ActivityOptions) => boolean, requiredActivity: string, redirectPath?: string | ((options: ActivityOptions) => string | undefined) | undefined) => (state: BaseReduxState, ownProps?: TOwnProps | undefined) => ActivityRequiredStateProps;
|
|
23
23
|
/**
|
|
24
24
|
* This HOC ensures that the wrapped component is only rendered if the group referenced by
|
|
25
25
|
* `props.model.groupId`, if any, satisfies the `accessPredicate` for the `requiredActivity`.
|
|
26
26
|
*
|
|
27
|
-
* @
|
|
27
|
+
* @param WrappedComponent The component which requires activity/activities in order to render
|
|
28
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
29
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
30
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
28
31
|
*/
|
|
29
|
-
export default function groupActivityRequiredComponent<TOwnProps extends CollectionItemComponentWrappedProps<GroupRelatedEntity>>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options: any) => boolean, requiredActivity: string): ComponentClass<TOwnProps>;
|
|
32
|
+
export default function groupActivityRequiredComponent<TOwnProps extends CollectionItemComponentWrappedProps<GroupRelatedEntity>>(WrappedComponent: ComponentType<TOwnProps>, accessPredicate: (requiredActivity: string, options: any) => boolean, requiredActivity: string, redirectPath?: string | undefined | ((options: ActivityOptions) => string | undefined)): ComponentClass<TOwnProps>;
|
|
@@ -20,17 +20,18 @@ var ActivityRequiredComponent_1 = require("./ActivityRequiredComponent");
|
|
|
20
20
|
* checking whether the user has the passed `requiredActivity` for the group referenced by
|
|
21
21
|
* `ownProps.model.groupId`, if any.
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
23
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
24
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
25
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
26
26
|
*/
|
|
27
|
-
var configureMapStateToProps = function (accessPredicate, requiredActivity) { return function (state, ownProps) {
|
|
27
|
+
var configureMapStateToProps = function (accessPredicate, requiredActivity, redirectPath) { return function (state, ownProps) {
|
|
28
28
|
var entity = ownProps && ownProps.model && state.models && state.models.groups
|
|
29
29
|
? state.models.groups[ownProps.model.groupId]
|
|
30
30
|
: undefined;
|
|
31
31
|
var options = __assign(__assign({}, baseActivity_1.defaultOptions(state, ownProps)), { entity: entity });
|
|
32
32
|
return {
|
|
33
|
-
hasAccess: accessPredicate(requiredActivity, options)
|
|
33
|
+
hasAccess: accessPredicate(requiredActivity, options),
|
|
34
|
+
redirectPath: (typeof redirectPath === 'function' ? redirectPath(options) : redirectPath) || '/'
|
|
34
35
|
};
|
|
35
36
|
}; };
|
|
36
37
|
exports.configureMapStateToProps = configureMapStateToProps;
|
|
@@ -38,11 +39,14 @@ exports.configureMapStateToProps = configureMapStateToProps;
|
|
|
38
39
|
* This HOC ensures that the wrapped component is only rendered if the group referenced by
|
|
39
40
|
* `props.model.groupId`, if any, satisfies the `accessPredicate` for the `requiredActivity`.
|
|
40
41
|
*
|
|
41
|
-
* @
|
|
42
|
+
* @param WrappedComponent The component which requires activity/activities in order to render
|
|
43
|
+
* @param accessPredicate A predicate accepting a required activity and an optional entity and/or userInfo object
|
|
44
|
+
* @param requiredActivity The required activity which is passed to the predicate for evaluation
|
|
45
|
+
* @param redirectPath (Optional) A string or function that provides the redirect path for when `accessPredicate` is false. Defaults to '/'.
|
|
42
46
|
*/
|
|
43
|
-
function groupActivityRequiredComponent(WrappedComponent, accessPredicate, requiredActivity) {
|
|
47
|
+
function groupActivityRequiredComponent(WrappedComponent, accessPredicate, requiredActivity, redirectPath) {
|
|
44
48
|
var ActivityRequiredComponent = ActivityRequiredComponent_1.configureActivityRequiredComponent(WrappedComponent);
|
|
45
|
-
var mapStateToProps = exports.configureMapStateToProps(accessPredicate, requiredActivity);
|
|
49
|
+
var mapStateToProps = exports.configureMapStateToProps(accessPredicate, requiredActivity, redirectPath);
|
|
46
50
|
// @ts-ignore: could not match inferred type from the `connect` HOC
|
|
47
51
|
return react_redux_1.connect(mapStateToProps)(ActivityRequiredComponent);
|
|
48
52
|
}
|
|
@@ -39,8 +39,12 @@ export interface UserRolesOwnProps extends CollectionComponentWrappedProps<UserR
|
|
|
39
39
|
externalProviders?: ModelCollection<ExternalProvider>;
|
|
40
40
|
/** (Optional) Allow users to be excluded from being displayed in the table */
|
|
41
41
|
filterUsers?: (users: UserWithRoles[]) => UserWithRoles[];
|
|
42
|
-
/** (Optional) Callback that is called after
|
|
43
|
-
|
|
42
|
+
/** (Optional) Callback that is called after user roles are added */
|
|
43
|
+
onAdd?: (userRoles: UserRole[]) => void;
|
|
44
|
+
/** (Optional) Callback that is called after a user role is updated */
|
|
45
|
+
onUpdate?: (userRole: UserRole, role: string) => void;
|
|
46
|
+
/** (Optional) Callback that is called after a user role is removed */
|
|
47
|
+
onRemove?: (userRole: UserRole) => void;
|
|
44
48
|
/** (Optional) Render custom components between the Add and Table components */
|
|
45
49
|
renderTableDescription?: (canModify?: boolean) => JSX.Element;
|
|
46
50
|
/** (Optional) Render custom components at the start of the Add component */
|
|
@@ -100,5 +104,5 @@ export declare class UserRoles extends Component<UserRolesProps, UserRolesState>
|
|
|
100
104
|
render(): JSX.Element;
|
|
101
105
|
}
|
|
102
106
|
export declare const mapStateToProps: (state: BaseReduxState, ownProps: UserRolesOwnProps) => UserRolesReduxProps;
|
|
103
|
-
declare const _default: import("react-redux").ConnectedComponent<typeof UserRoles, Pick<React.ClassAttributes<UserRoles> & UserRolesProps, "externalProviders" | "model" | "ref" | "
|
|
107
|
+
declare const _default: import("react-redux").ConnectedComponent<typeof UserRoles, Pick<React.ClassAttributes<UserRoles> & UserRolesProps, "externalProviders" | "model" | "ref" | "key" | "guid" | "load" | "modelName" | "pathParams" | "modelStatus" | "queryParams" | "disableAutoLoad" | "modelArray" | "stopPeriodicLoad" | "create" | "update" | "delete" | "previousModelStatus" | "fetchingId" | "textForRole" | "entityName" | "defaultRole" | "roleDescriptions" | "renderAddDescription" | "isUpdateDisabled" | "isDeleteDisabled" | "allowMultipleRoles" | "requiredRole" | "isAddDisabled" | "modifyUserRoleActivityName" | "deleteOwnUserRoleActivityName" | "addRoleExcludeList" | "entity" | "filterUsers" | "onAdd" | "onUpdate" | "onRemove" | "renderTableDescription" | "singularArticleForRole"> & UserRolesOwnProps>;
|
|
104
108
|
export default _default;
|
|
@@ -136,7 +136,7 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
136
136
|
});
|
|
137
137
|
};
|
|
138
138
|
_this.didAdd = function (data) {
|
|
139
|
-
var _a = _this.props, entityName = _a.entityName,
|
|
139
|
+
var _a = _this.props, entityName = _a.entityName, onAdd = _a.onAdd, model = _a.model, modelName = _a.modelName, pathParams = _a.pathParams;
|
|
140
140
|
var _b = _this.state, roleForAdd = _b.roleForAdd, identifiersToAdd = _b.identifiersToAdd;
|
|
141
141
|
if (!roleForAdd || !identifiersToAdd || identifiersToAdd.length === 0) {
|
|
142
142
|
throw new Error('didAdd was called in the incorrect state');
|
|
@@ -209,8 +209,8 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
209
209
|
modelName: prepareFetchResult.modelName,
|
|
210
210
|
data: updatedModel_1
|
|
211
211
|
});
|
|
212
|
-
if (
|
|
213
|
-
|
|
212
|
+
if (onAdd) {
|
|
213
|
+
onAdd(addedUserRoles);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
};
|
|
@@ -233,7 +233,7 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
233
233
|
});
|
|
234
234
|
};
|
|
235
235
|
_this.didUpdate = function (isSuccess) {
|
|
236
|
-
var _a = _this.props, entityName = _a.entityName,
|
|
236
|
+
var _a = _this.props, entityName = _a.entityName, onUpdate = _a.onUpdate;
|
|
237
237
|
var _b = _this.state, userRoleToUpdate = _b.userRoleToUpdate, roleForUpdate = _b.roleForUpdate;
|
|
238
238
|
if (userRoleToUpdate === undefined) {
|
|
239
239
|
throw new Error('`didUpdate` was called without setting `userRoleToUpdate` in state');
|
|
@@ -255,15 +255,15 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
257
|
var successMessage = name + " was successfully updated to " + singularArticleString + " " + roleString + (entityName ? " in your " + entityName : '') + ".";
|
|
258
|
+
if (onUpdate) {
|
|
259
|
+
onUpdate(userRoleToUpdate, roleForUpdate);
|
|
260
|
+
}
|
|
258
261
|
_this.setState({
|
|
259
262
|
isUpdating: false,
|
|
260
263
|
userRoleToUpdate: undefined,
|
|
261
264
|
roleForUpdate: undefined,
|
|
262
265
|
successMessage: successMessage
|
|
263
266
|
});
|
|
264
|
-
if (onChange) {
|
|
265
|
-
onChange();
|
|
266
|
-
}
|
|
267
267
|
};
|
|
268
268
|
//#endregion Update
|
|
269
269
|
//#region Remove User
|
|
@@ -333,7 +333,7 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
333
333
|
});
|
|
334
334
|
};
|
|
335
335
|
_this.didRemove = function (isSuccess) {
|
|
336
|
-
var _a = _this.props, entityName = _a.entityName,
|
|
336
|
+
var _a = _this.props, entityName = _a.entityName, onRemove = _a.onRemove;
|
|
337
337
|
var userRoleToRemove = _this.state.userRoleToRemove;
|
|
338
338
|
if (userRoleToRemove === undefined) {
|
|
339
339
|
throw new Error('`didRemove` was called without setting `userRoleToRemove` in state');
|
|
@@ -349,14 +349,14 @@ var UserRoles = /** @class */ (function (_super) {
|
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
351
|
var successMessage = name + " was successfully removed" + (entityName ? " from your " + entityName : '') + ".";
|
|
352
|
+
if (onRemove) {
|
|
353
|
+
onRemove(userRoleToRemove);
|
|
354
|
+
}
|
|
352
355
|
_this.setState({
|
|
353
356
|
isRemoving: false,
|
|
354
357
|
userRoleToRemove: undefined,
|
|
355
358
|
successMessage: successMessage
|
|
356
359
|
});
|
|
357
|
-
if (onChange) {
|
|
358
|
-
onChange();
|
|
359
|
-
}
|
|
360
360
|
};
|
|
361
361
|
return _this;
|
|
362
362
|
}
|
|
@@ -8,7 +8,7 @@ function useCollection(props) {
|
|
|
8
8
|
var modelName = props.modelName;
|
|
9
9
|
// state, route, and redux
|
|
10
10
|
var config = useCollectionConfiguration_1.useCollectionConfiguration(props, collection_1.selectCollectionFromState);
|
|
11
|
-
var guid = config.guid, model = config.model, pathParams = config.pathParams, previousPathParams = config.previousPathParams, queryParams = config.queryParams, previousQueryParams = config.previousQueryParams, fetchingId = config.fetchingId, modelStatus = config.modelStatus, previousModelStatus = config.previousModelStatus, isInitialized = config.isInitialized, setIsInitialized = config.setIsInitialized, methodConfig = config.methodConfig, modelArray = config.modelArray;
|
|
11
|
+
var previousModelName = config.previousModelName, guid = config.guid, model = config.model, pathParams = config.pathParams, previousPathParams = config.previousPathParams, queryParams = config.queryParams, previousQueryParams = config.previousQueryParams, fetchingId = config.fetchingId, modelStatus = config.modelStatus, previousModelStatus = config.previousModelStatus, isInitialized = config.isInitialized, setIsInitialized = config.setIsInitialized, methodConfig = config.methodConfig, modelArray = config.modelArray;
|
|
12
12
|
// decorated methods
|
|
13
13
|
var load = react_1.useCallback(function (params) {
|
|
14
14
|
if (params === void 0) { params = {}; }
|
|
@@ -35,8 +35,8 @@ function useCollection(props) {
|
|
|
35
35
|
}, [isInitialized, load, methodConfig, model, setIsInitialized]);
|
|
36
36
|
// re-load if `pathParams` or `queryParams` change
|
|
37
37
|
react_1.useEffect(function () {
|
|
38
|
-
collection_1.handleCollectionParamsChange(pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
39
|
-
}, [load, modelName, pathParams, previousPathParams, previousQueryParams, queryParams]);
|
|
38
|
+
collection_1.handleCollectionParamsChange(modelName, previousModelName, pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
39
|
+
}, [load, modelName, pathParams, previousModelName, previousPathParams, previousQueryParams, queryParams]);
|
|
40
40
|
// cleanup on unmount
|
|
41
41
|
react_1.useEffect(function () {
|
|
42
42
|
return function cleanup() {
|
|
@@ -4,6 +4,7 @@ import { Model, ModelCollection } from 'studiokit-net-js';
|
|
|
4
4
|
import { CollectionCommonProps, CollectionCommonState, CollectionMethodConfiguration, CollectionSelectorMethod } from '../types/Collection';
|
|
5
5
|
/** Configuration returned by `useCollectionConfiguration` for use in `useCollection` and `useCollectionItem` */
|
|
6
6
|
export interface CollectionConfiguration<TModel extends Model> extends CollectionCommonState {
|
|
7
|
+
previousModelName: string;
|
|
7
8
|
guid: string;
|
|
8
9
|
model: TModel | ModelCollection<TModel>;
|
|
9
10
|
modelArray?: TModel[];
|
|
@@ -26,6 +26,7 @@ function useCollectionConfiguration(props, selectorFunction) {
|
|
|
26
26
|
var _d = react_redux_1.useSelector(function (state) {
|
|
27
27
|
return selectorFunction({ guid: guid, modelName: modelName, pathParams: propPathParams, routeMatchParams: routeMatchParams, state: state });
|
|
28
28
|
}), pathParams = _d.pathParams, model = _d.model, modelArray = _d.modelArray, modelMinusRelations = _d.modelMinusRelations;
|
|
29
|
+
var previousModelName = usePrevious_1.usePrevious(modelName);
|
|
29
30
|
var previousModel = usePrevious_1.usePrevious(model);
|
|
30
31
|
var previousPathParams = usePrevious_1.usePrevious(pathParams);
|
|
31
32
|
var previousQueryParams = usePrevious_1.usePrevious(queryParams);
|
|
@@ -47,6 +48,7 @@ function useCollectionConfiguration(props, selectorFunction) {
|
|
|
47
48
|
model_1.handleModelFetchFinish(model, previousModel, fetchingId, changeModelStatus);
|
|
48
49
|
}, [fetchingId, model, previousModel]);
|
|
49
50
|
return {
|
|
51
|
+
previousModelName: previousModelName,
|
|
50
52
|
guid: guid,
|
|
51
53
|
model: model,
|
|
52
54
|
modelArray: modelArray,
|
|
@@ -8,7 +8,7 @@ function useCollectionItem(props) {
|
|
|
8
8
|
var modelName = props.modelName;
|
|
9
9
|
// state, route, and redux
|
|
10
10
|
var config = useCollectionConfiguration_1.useCollectionConfiguration(props, collection_1.selectCollectionItemFromState);
|
|
11
|
-
var guid = config.guid, model = config.model, pathParams = config.pathParams, previousPathParams = config.previousPathParams, queryParams = config.queryParams, previousQueryParams = config.previousQueryParams, modelStatus = config.modelStatus, previousModelStatus = config.previousModelStatus, isInitialized = config.isInitialized, setIsInitialized = config.setIsInitialized, methodConfig = config.methodConfig, modelMinusRelations = config.modelMinusRelations;
|
|
11
|
+
var previousModelName = config.previousModelName, guid = config.guid, model = config.model, pathParams = config.pathParams, previousPathParams = config.previousPathParams, queryParams = config.queryParams, previousQueryParams = config.previousQueryParams, modelStatus = config.modelStatus, previousModelStatus = config.previousModelStatus, isInitialized = config.isInitialized, setIsInitialized = config.setIsInitialized, methodConfig = config.methodConfig, modelMinusRelations = config.modelMinusRelations;
|
|
12
12
|
// decorated methods
|
|
13
13
|
var load = react_1.useCallback(function (params) {
|
|
14
14
|
if (params === void 0) { params = {}; }
|
|
@@ -36,8 +36,8 @@ function useCollectionItem(props) {
|
|
|
36
36
|
}, [isInitialized, load, methodConfig, model, setIsInitialized]);
|
|
37
37
|
// re-load if `pathParams` or `queryParams` change
|
|
38
38
|
react_1.useEffect(function () {
|
|
39
|
-
collection_1.handleCollectionItemParamsChange(modelName, pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
40
|
-
}, [load, modelName, pathParams, previousPathParams, previousQueryParams, queryParams]);
|
|
39
|
+
collection_1.handleCollectionItemParamsChange(modelName, previousModelName, pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
40
|
+
}, [load, modelName, pathParams, previousModelName, previousPathParams, previousQueryParams, queryParams]);
|
|
41
41
|
return {
|
|
42
42
|
guid: guid,
|
|
43
43
|
model: model,
|
|
@@ -32,11 +32,11 @@ export declare function initializeCollection(model: Model, load: (params?: Colle
|
|
|
32
32
|
/**
|
|
33
33
|
* When `pathParams` or `queryParams` change, call `load`
|
|
34
34
|
*/
|
|
35
|
-
export declare function handleCollectionItemParamsChange(modelName: string, pathParams: string[], prevPathParams: string[] | undefined, queryParams: Dictionary<string> | undefined, prevQueryParams: Dictionary<string> | undefined, load: (params?: CollectionItemLoadParams) => void): void;
|
|
35
|
+
export declare function handleCollectionItemParamsChange(modelName: string, prevModelName: string, pathParams: string[], prevPathParams: string[] | undefined, queryParams: Dictionary<string> | undefined, prevQueryParams: Dictionary<string> | undefined, load: (params?: CollectionItemLoadParams) => void): void;
|
|
36
36
|
/**
|
|
37
37
|
* When `pathParams` or `queryParams` change, call `load`
|
|
38
38
|
*/
|
|
39
|
-
export declare function handleCollectionParamsChange(pathParams: string[], prevPathParams: string[] | undefined, queryParams: Dictionary<string> | undefined, prevQueryParams: Dictionary<string> | undefined, load: (params?: CollectionLoadParams) => void): void;
|
|
39
|
+
export declare function handleCollectionParamsChange(modelName: string, prevModelName: string, pathParams: string[], prevPathParams: string[] | undefined, queryParams: Dictionary<string> | undefined, prevQueryParams: Dictionary<string> | undefined, load: (params?: CollectionLoadParams) => void): void;
|
|
40
40
|
/**
|
|
41
41
|
* Delete the guid in the model
|
|
42
42
|
*/
|
package/lib/utils/collection.js
CHANGED
|
@@ -291,8 +291,9 @@ exports.initializeCollection = initializeCollection;
|
|
|
291
291
|
/**
|
|
292
292
|
* When `pathParams` or `queryParams` change, call `load`
|
|
293
293
|
*/
|
|
294
|
-
function handleCollectionItemParamsChange(modelName, pathParams, prevPathParams, queryParams, prevQueryParams, load) {
|
|
295
|
-
if (
|
|
294
|
+
function handleCollectionItemParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, load) {
|
|
295
|
+
if (modelName !== prevModelName ||
|
|
296
|
+
(pathParams.length === route_1.getMinRequiredPathParamsCount(modelName) + 1 && !lodash_1.isEqual(prevPathParams, pathParams)) ||
|
|
296
297
|
!lodash_1.isEqual(prevQueryParams, queryParams)) {
|
|
297
298
|
load({ pathParams: pathParams, queryParams: queryParams });
|
|
298
299
|
}
|
|
@@ -301,8 +302,10 @@ exports.handleCollectionItemParamsChange = handleCollectionItemParamsChange;
|
|
|
301
302
|
/**
|
|
302
303
|
* When `pathParams` or `queryParams` change, call `load`
|
|
303
304
|
*/
|
|
304
|
-
function handleCollectionParamsChange(pathParams, prevPathParams, queryParams, prevQueryParams, load) {
|
|
305
|
-
if (
|
|
305
|
+
function handleCollectionParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, load) {
|
|
306
|
+
if (modelName !== prevModelName ||
|
|
307
|
+
(pathParams.length > 0 && !lodash_1.isEqual(prevPathParams, pathParams)) ||
|
|
308
|
+
!lodash_1.isEqual(prevQueryParams, queryParams)) {
|
|
306
309
|
load({ pathParams: pathParams, queryParams: queryParams });
|
|
307
310
|
}
|
|
308
311
|
}
|
package/package.json
CHANGED