studiokit-scaffolding-js 5.1.2 → 5.1.3
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/CollectionComponent.d.ts +1 -1
- package/lib/components/HOC/CollectionComponent.js +4 -2
- package/lib/components/HOC/CollectionItemComponent.d.ts +1 -1
- package/lib/components/HOC/CollectionItemComponent.js +4 -2
- package/lib/components/HOC/SearchPersistorComponent.d.ts +8 -4
- package/lib/components/HOC/SearchPersistorComponent.js +12 -8
- package/lib/components/SearchControls.d.ts +2 -0
- package/lib/components/SearchControls.js +2 -2
- package/lib/components/UserRoles/index.d.ts +1 -1
- package/lib/hooks/useCollection.js +15 -4
- package/lib/hooks/useCollectionItem.js +15 -4
- package/lib/types/Collection.d.ts +3 -1
- package/package.json +1 -1
|
@@ -46,7 +46,7 @@ export declare function configureCollectionComponent<TModel extends Model, TOwnP
|
|
|
46
46
|
};
|
|
47
47
|
contextType?: React.Context<any> | undefined;
|
|
48
48
|
};
|
|
49
|
-
export declare const configureMapStateToProps: <TModel extends Model, TOwnProps extends Pick<CollectionComponentProps<TModel>, "match" | "queryParams" | "modelName" | "guid" | "location" | "history" | "staticContext" | "pathParams" | "disableAutoLoad">>(modelName: string) => (state: BaseReduxState, ownProps: TOwnProps & Partial<CollectionComponentProps<TModel>>) => import("../../types").CollectionSelectorMethodResponse<Model>;
|
|
49
|
+
export declare const configureMapStateToProps: <TModel extends Model, TOwnProps extends Pick<CollectionComponentProps<TModel>, "match" | "queryParams" | "modelName" | "guid" | "location" | "history" | "staticContext" | "pathParams" | "disableAutoLoad" | "disableAutoLoadOnParamsChange">>(modelName: string) => (state: BaseReduxState, ownProps: TOwnProps & Partial<CollectionComponentProps<TModel>>) => import("../../types").CollectionSelectorMethodResponse<Model>;
|
|
50
50
|
/**
|
|
51
51
|
* HOC that provides "collection" related functionality, using redux `connect()`, react-router-dom `withRouter()`, and `GuidComponent`.
|
|
52
52
|
*
|
|
@@ -126,10 +126,12 @@ function configureCollectionComponent(WrappedComponent, LoaderComponent) {
|
|
|
126
126
|
};
|
|
127
127
|
CollectionComponent.prototype.componentDidUpdate = function (prevProps) {
|
|
128
128
|
var prevModel = prevProps.model, prevModelName = prevProps.modelName, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
129
|
-
var _a = this.props, model = _a.model, modelName = _a.modelName, pathParams = _a.pathParams, queryParams = _a.queryParams;
|
|
129
|
+
var _a = this.props, model = _a.model, modelName = _a.modelName, pathParams = _a.pathParams, queryParams = _a.queryParams, disableAutoLoadOnParamsChange = _a.disableAutoLoadOnParamsChange;
|
|
130
130
|
var fetchingId = this.state.fetchingId;
|
|
131
131
|
model_1.handleModelFetchFinish(model, prevModel, fetchingId, this.changeModelStatus);
|
|
132
|
-
|
|
132
|
+
if (!disableAutoLoadOnParamsChange) {
|
|
133
|
+
collection_1.handleCollectionParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
134
|
+
}
|
|
133
135
|
};
|
|
134
136
|
CollectionComponent.prototype.componentWillUnmount = function () {
|
|
135
137
|
var model = this.props.model;
|
|
@@ -45,7 +45,7 @@ export declare function configureCollectionItemComponent<TModel extends Model, T
|
|
|
45
45
|
};
|
|
46
46
|
contextType?: React.Context<any> | undefined;
|
|
47
47
|
};
|
|
48
|
-
export declare const configureMapStateToProps: <TModel extends Model, TOwnProps extends Pick<CollectionItemComponentProps<TModel>, "match" | "queryParams" | "modelName" | "guid" | "location" | "history" | "staticContext" | "pathParams" | "disableAutoLoad">>(modelName: string) => (state: BaseReduxState, ownProps: TOwnProps) => import("../../types").CollectionSelectorMethodResponse<Model>;
|
|
48
|
+
export declare const configureMapStateToProps: <TModel extends Model, TOwnProps extends Pick<CollectionItemComponentProps<TModel>, "match" | "queryParams" | "modelName" | "guid" | "location" | "history" | "staticContext" | "pathParams" | "disableAutoLoad" | "disableAutoLoadOnParamsChange">>(modelName: string) => (state: BaseReduxState, ownProps: TOwnProps) => import("../../types").CollectionSelectorMethodResponse<Model>;
|
|
49
49
|
/**
|
|
50
50
|
* HOC that provides "collection" related functionality for a single item in a collection, using redux `connect()`, react-router-dom `withRouter()`, and `GuidComponent`.
|
|
51
51
|
*
|
|
@@ -128,9 +128,11 @@ function configureCollectionItemComponent(WrappedComponent, LoaderComponent) {
|
|
|
128
128
|
};
|
|
129
129
|
CollectionItemComponent.prototype.componentDidUpdate = function (prevProps) {
|
|
130
130
|
var prevModel = prevProps.model, prevModelName = prevProps.modelName, prevPathParams = prevProps.pathParams, prevQueryParams = prevProps.queryParams;
|
|
131
|
-
var _a = this.props, modelName = _a.modelName, model = _a.model, pathParams = _a.pathParams, queryParams = _a.queryParams;
|
|
131
|
+
var _a = this.props, modelName = _a.modelName, model = _a.model, pathParams = _a.pathParams, queryParams = _a.queryParams, disableAutoLoadOnParamsChange = _a.disableAutoLoadOnParamsChange;
|
|
132
132
|
model_1.handleModelFetchFinish(model, prevModel, undefined, this.setModelStatus);
|
|
133
|
-
|
|
133
|
+
if (!disableAutoLoadOnParamsChange) {
|
|
134
|
+
collection_1.handleCollectionItemParamsChange(modelName, prevModelName, pathParams, prevPathParams, queryParams, prevQueryParams, this.load);
|
|
135
|
+
}
|
|
134
136
|
};
|
|
135
137
|
CollectionItemComponent.prototype.render = function () {
|
|
136
138
|
var _a = this.props, history = _a.history, match = _a.match, location = _a.location, staticContext = _a.staticContext, otherProps = __rest(_a, ["history", "match", "location", "staticContext"]);
|
|
@@ -22,8 +22,8 @@ export interface SearchPersistorMethods<T extends Search = Search> {
|
|
|
22
22
|
export interface SearchPersistorWrappedProps<T extends Search = Search> extends SearchPersistorProps<T>, SearchPersistorMethods<T> {
|
|
23
23
|
search?: T;
|
|
24
24
|
}
|
|
25
|
-
export declare function configureSearchPersistorComponent<TOwnProps extends {}>(WrappedComponent: ComponentType<TOwnProps & SearchPersistorWrappedProps
|
|
26
|
-
export declare function configureSearchPersistorComponent<TOwnProps extends {}, TSearchType extends Search>(WrappedComponent: ComponentType<TOwnProps & SearchPersistorWrappedProps<TSearchType
|
|
25
|
+
export declare function configureSearchPersistorComponent<TOwnProps extends {}>(WrappedComponent: ComponentType<TOwnProps & SearchPersistorWrappedProps>, disableLocalSearch?: boolean): ComponentType<TOwnProps & SearchPersistorProps>;
|
|
26
|
+
export declare function configureSearchPersistorComponent<TOwnProps extends {}, TSearchType extends Search>(WrappedComponent: ComponentType<TOwnProps & SearchPersistorWrappedProps<TSearchType>>, disableLocalSearch?: boolean): ComponentType<TOwnProps & SearchPersistorProps<TSearchType>>;
|
|
27
27
|
export declare const configureMapStateToProps: <TSearchType extends Search>(key: string) => (state: BaseReduxState) => SearchPersistorProps<TSearchType>;
|
|
28
28
|
export declare const configureMapDispatchToProps: <TSearchType extends Search>(key: string) => (dispatch: Dispatch) => SearchPersistorProps<TSearchType>;
|
|
29
29
|
/**
|
|
@@ -44,9 +44,11 @@ export declare const configureMapDispatchToProps: <TSearchType extends Search>(k
|
|
|
44
44
|
*
|
|
45
45
|
* @param WrappedComponent The component to wrap
|
|
46
46
|
* @param key The key under "search" in redux where the component’s search params will be stored
|
|
47
|
+
* @param disableLocalSearch By default, `doSearch` is only called at initialization and when `queryAll` is `true`, and searching happens locally (see ManageTable).
|
|
48
|
+
* If `disableLocalSearch` is `true` then the legacy logic is used, where `doSearch` is always called for all searches.
|
|
47
49
|
* @returns The wrapped component, passing down `search` and `persistSearch` as props
|
|
48
50
|
*/
|
|
49
|
-
export default function searchPersistorComponent<TOwnProps extends SearchPersistorWrappedProps>(WrappedComponent: ComponentType<TOwnProps>, key: string): ComponentClass<Omit<TOwnProps, keyof SearchPersistorWrappedProps>>;
|
|
51
|
+
export default function searchPersistorComponent<TOwnProps extends SearchPersistorWrappedProps>(WrappedComponent: ComponentType<TOwnProps>, key: string, disableLocalSearch?: boolean): ComponentClass<Omit<TOwnProps, keyof SearchPersistorWrappedProps>>;
|
|
50
52
|
/**
|
|
51
53
|
* HOC to handle persistence and restoration of "Manage" components search parameters.
|
|
52
54
|
* Note: if you store a search date in a child component, make sure it’s called `date`.
|
|
@@ -65,6 +67,8 @@ export default function searchPersistorComponent<TOwnProps extends SearchPersist
|
|
|
65
67
|
*
|
|
66
68
|
* @param WrappedComponent The component to wrap
|
|
67
69
|
* @param key The key under "search" in redux where the component’s search params will be stored
|
|
70
|
+
* @param disableLocalSearch By default, `doSearch` is only called at initialization and when `queryAll` is `true`, and searching happens locally (see ManageTable).
|
|
71
|
+
* If `disableLocalSearch` is `true` then the legacy logic is used, where `doSearch` is always called for all searches.
|
|
68
72
|
* @returns The wrapped component, passing down `search` and `persistSearch` as props
|
|
69
73
|
*/
|
|
70
|
-
export default function searchPersistorComponent<TOwnProps extends SearchPersistorWrappedProps<TSearchType>, TSearchType extends Search>(WrappedComponent: ComponentType<TOwnProps>, key: string): ComponentClass<Omit<TOwnProps, keyof SearchPersistorWrappedProps<TSearchType>>>;
|
|
74
|
+
export default function searchPersistorComponent<TOwnProps extends SearchPersistorWrappedProps<TSearchType>, TSearchType extends Search>(WrappedComponent: ComponentType<TOwnProps>, key: string, disableLocalSearch?: boolean): ComponentClass<Omit<TOwnProps, keyof SearchPersistorWrappedProps<TSearchType>>>;
|
|
@@ -48,7 +48,7 @@ var lodash_1 = require("lodash");
|
|
|
48
48
|
var react_1 = __importStar(require("react"));
|
|
49
49
|
var react_redux_1 = require("react-redux");
|
|
50
50
|
var actions_1 = require("../../redux/actions");
|
|
51
|
-
function configureSearchPersistorComponent(WrappedComponent) {
|
|
51
|
+
function configureSearchPersistorComponent(WrappedComponent, disableLocalSearch) {
|
|
52
52
|
return /** @class */ (function (_super) {
|
|
53
53
|
__extends(SearchPersistorComponent, _super);
|
|
54
54
|
function SearchPersistorComponent(props) {
|
|
@@ -105,8 +105,8 @@ function configureSearchPersistorComponent(WrappedComponent) {
|
|
|
105
105
|
pageSize: search.pageSize,
|
|
106
106
|
pageByTab: search.pageByTab
|
|
107
107
|
}),
|
|
108
|
-
// do not trigger a re-load unless queryAll is true
|
|
109
|
-
search.queryAll ? _this.doSearch : undefined);
|
|
108
|
+
// do not trigger a re-load unless queryAll is true, or local search is disabled
|
|
109
|
+
disableLocalSearch || search.queryAll ? _this.doSearch : undefined);
|
|
110
110
|
};
|
|
111
111
|
_this.setSelectedTab = function (selectedTab) {
|
|
112
112
|
var _a, _b;
|
|
@@ -126,16 +126,20 @@ function configureSearchPersistorComponent(WrappedComponent) {
|
|
|
126
126
|
};
|
|
127
127
|
_this.handleKeywordsKeyDown = function (event) {
|
|
128
128
|
var _a;
|
|
129
|
-
if (event.key === 'Enter' && ((_a = _this.state.search) === null || _a === void 0 ? void 0 : _a.queryAll)) {
|
|
129
|
+
if (event.key === 'Enter' && (disableLocalSearch || ((_a = _this.state.search) === null || _a === void 0 ? void 0 : _a.queryAll))) {
|
|
130
130
|
_this.handleSearchClick();
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
_this.setQueryAll = function (event) {
|
|
134
|
+
var _a;
|
|
134
135
|
var queryAll = event.target.checked;
|
|
135
136
|
_this.updateAndPersistSearch({
|
|
136
137
|
queryAll: queryAll,
|
|
137
|
-
requiredMessage
|
|
138
|
-
|
|
138
|
+
// clear the `requiredMessage` when turning off `queryAll` and local search is enabled
|
|
139
|
+
requiredMessage: !queryAll && !disableLocalSearch ? null : (_a = _this.state.search) === null || _a === void 0 ? void 0 : _a.requiredMessage
|
|
140
|
+
},
|
|
141
|
+
// only automatically trigger re-load when local search is enabled
|
|
142
|
+
!disableLocalSearch ? _this.doSearch : undefined);
|
|
139
143
|
};
|
|
140
144
|
_this.setSortingRules = function (newSortingRules) {
|
|
141
145
|
_this.updateAndPersistSearch({
|
|
@@ -213,8 +217,8 @@ var configureMapDispatchToProps = function (key) { return function (dispatch) {
|
|
|
213
217
|
};
|
|
214
218
|
}; };
|
|
215
219
|
exports.configureMapDispatchToProps = configureMapDispatchToProps;
|
|
216
|
-
function searchPersistorComponent(WrappedComponent, key) {
|
|
217
|
-
var SearchPersistorComponent = configureSearchPersistorComponent(WrappedComponent);
|
|
220
|
+
function searchPersistorComponent(WrappedComponent, key, disableLocalSearch) {
|
|
221
|
+
var SearchPersistorComponent = configureSearchPersistorComponent(WrappedComponent, disableLocalSearch);
|
|
218
222
|
var mapStateToProps = exports.configureMapStateToProps(key);
|
|
219
223
|
var mapDispatchToProps = exports.configureMapDispatchToProps(key);
|
|
220
224
|
// @ts-ignore: could not match inferred type from the `connect` HOC
|
|
@@ -9,6 +9,8 @@ export interface SearchControlsProps extends Search, SearchControlsMethods {
|
|
|
9
9
|
handleDateChange?: (dateString: string, date?: Date) => void;
|
|
10
10
|
canReadAnyGlobally?: boolean;
|
|
11
11
|
canReadSome?: boolean;
|
|
12
|
+
/** force Search button to be visible. otherwise only shows when `queryAll` is `true`. */
|
|
13
|
+
showSearchButton?: boolean;
|
|
12
14
|
}
|
|
13
15
|
export declare const SearchControls: FunctionComponent<SearchControlsProps>;
|
|
14
16
|
export {};
|
|
@@ -12,7 +12,7 @@ var react_bootstrap_1 = require("react-bootstrap");
|
|
|
12
12
|
var AlertWithIcon_1 = require("./AlertWithIcon");
|
|
13
13
|
var DateField_1 = require("./Forms/DateField");
|
|
14
14
|
var SearchControls = function (_a) {
|
|
15
|
-
var keywords = _a.keywords, invalidKeywords = _a.invalidKeywords, dateString = _a.dateString, queryAll = _a.queryAll, requiredMessage = _a.requiredMessage, setKeywords = _a.setKeywords, handleKeywordsKeyDown = _a.handleKeywordsKeyDown, handleSearchClick = _a.handleSearchClick, resetSearch = _a.resetSearch, setQueryAll = _a.setQueryAll, keywordPlaceholder = _a.keywordPlaceholder, handleDateChange = _a.handleDateChange, queryAllText = _a.queryAllText, canReadAnyGlobally = _a.canReadAnyGlobally, canReadSome = _a.canReadSome;
|
|
15
|
+
var keywords = _a.keywords, invalidKeywords = _a.invalidKeywords, dateString = _a.dateString, queryAll = _a.queryAll, requiredMessage = _a.requiredMessage, setKeywords = _a.setKeywords, handleKeywordsKeyDown = _a.handleKeywordsKeyDown, handleSearchClick = _a.handleSearchClick, resetSearch = _a.resetSearch, setQueryAll = _a.setQueryAll, keywordPlaceholder = _a.keywordPlaceholder, handleDateChange = _a.handleDateChange, queryAllText = _a.queryAllText, canReadAnyGlobally = _a.canReadAnyGlobally, canReadSome = _a.canReadSome, showSearchButton = _a.showSearchButton;
|
|
16
16
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
17
17
|
!!requiredMessage && (react_1.default.createElement(AlertWithIcon_1.AlertWithIcon, { variant: "danger", className: "mb0", id: "requiredMessageAlert" },
|
|
18
18
|
react_1.default.createElement("p", null, requiredMessage))),
|
|
@@ -25,7 +25,7 @@ var SearchControls = function (_a) {
|
|
|
25
25
|
react_1.default.createElement(DateField_1.DateField, { id: "date", onChange: handleDateChange, label: "Date", "aria-label": "Active date", className: "fl-ns mw5-ns mr3-ns mb3 mb0-ns w-100-lt-xs date-align", value: dateString }))),
|
|
26
26
|
react_1.default.createElement("div", { className: "fl-ns mt3-ns pt3-ns w-100-lt-xs" },
|
|
27
27
|
canReadAnyGlobally && !!setQueryAll && (react_1.default.createElement(react_bootstrap_1.FormCheck, { name: "queryAll", id: "queryAll", checked: queryAll, disabled: canReadAnyGlobally && !canReadSome, onChange: setQueryAll, className: "fl-ns f6 mr2-ns mb3 mt2 w-100-lt-xs", label: react_1.default.createElement("span", { className: "b black" }, queryAllText || 'Search All') })),
|
|
28
|
-
canReadAnyGlobally && queryAll && (react_1.default.createElement(Button_1.default, { className: "btn-primary fr-ns ml2-ns mb3 w-100-lt-xs search-button", onClick: handleSearchClick, color: "primary", disabled: (!keywords || keywords.length < 3 || !!invalidKeywords) && !dateString },
|
|
28
|
+
(showSearchButton || (canReadAnyGlobally && queryAll)) && (react_1.default.createElement(Button_1.default, { className: "btn-primary fr-ns ml2-ns mb3 w-100-lt-xs search-button", onClick: handleSearchClick, color: "primary", disabled: (!keywords || keywords.length < 3 || !!invalidKeywords) && !dateString },
|
|
29
29
|
react_1.default.createElement(Search_1.default, null),
|
|
30
30
|
"Search")),
|
|
31
31
|
react_1.default.createElement(Button_1.default, { className: "btn-text color-pink fr-ns mb3 w-100-lt-xs", onClick: resetSearch },
|
|
@@ -107,5 +107,5 @@ export declare class UserRoles extends Component<UserRolesProps, UserRolesState>
|
|
|
107
107
|
render(): JSX.Element;
|
|
108
108
|
}
|
|
109
109
|
export declare const mapStateToProps: (state: BaseReduxState, ownProps: UserRolesOwnProps) => UserRolesReduxProps;
|
|
110
|
-
declare const _default: import("react-redux").ConnectedComponent<typeof UserRoles, Pick<React.ClassAttributes<UserRoles> & UserRolesProps, "ref" | "queryParams" | "modelName" | "externalProviders" | "model" | "key" | "readOnly" | "guid" | "entityName" | "load" | "pathParams" | "modelStatus" | "disableAutoLoad" | "modelArray" | "stopPeriodicLoad" | "create" | "update" | "delete" | "previousModelStatus" | "fetchingId" | "textForRole" | "defaultRole" | "roleDescriptions" | "renderAddDescription" | "isUpdateDisabled" | "isDeleteDisabled" | "allowMultipleRoles" | "requiredRole" | "isAddDisabled" | "modifyUserRoleActivityName" | "deleteOwnUserRoleActivityName" | "addRoleExcludeList" | "entity" | "filterUsers" | "onAdd" | "onUpdate" | "onRemove" | "renderTableDescription" | "lowercaseTextForRole" | "singularArticleForRole"> & UserRolesOwnProps>;
|
|
110
|
+
declare const _default: import("react-redux").ConnectedComponent<typeof UserRoles, Pick<React.ClassAttributes<UserRoles> & UserRolesProps, "ref" | "queryParams" | "modelName" | "externalProviders" | "model" | "key" | "readOnly" | "guid" | "entityName" | "load" | "pathParams" | "modelStatus" | "disableAutoLoad" | "disableAutoLoadOnParamsChange" | "modelArray" | "stopPeriodicLoad" | "create" | "update" | "delete" | "previousModelStatus" | "fetchingId" | "textForRole" | "defaultRole" | "roleDescriptions" | "renderAddDescription" | "isUpdateDisabled" | "isDeleteDisabled" | "allowMultipleRoles" | "requiredRole" | "isAddDisabled" | "modifyUserRoleActivityName" | "deleteOwnUserRoleActivityName" | "addRoleExcludeList" | "entity" | "filterUsers" | "onAdd" | "onUpdate" | "onRemove" | "renderTableDescription" | "lowercaseTextForRole" | "singularArticleForRole"> & UserRolesOwnProps>;
|
|
111
111
|
export default _default;
|
|
@@ -5,7 +5,7 @@ var react_1 = require("react");
|
|
|
5
5
|
var collection_1 = require("../utils/collection");
|
|
6
6
|
var useCollectionConfiguration_1 = require("./useCollectionConfiguration");
|
|
7
7
|
function useCollection(props) {
|
|
8
|
-
var modelName = props.modelName;
|
|
8
|
+
var modelName = props.modelName, disableAutoLoadOnParamsChange = props.disableAutoLoadOnParamsChange;
|
|
9
9
|
// state, route, and redux
|
|
10
10
|
var config = useCollectionConfiguration_1.useCollectionConfiguration(props, collection_1.selectCollectionFromState);
|
|
11
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;
|
|
@@ -33,10 +33,21 @@ function useCollection(props) {
|
|
|
33
33
|
setIsInitialized(true);
|
|
34
34
|
}
|
|
35
35
|
}, [isInitialized, load, methodConfig, model, setIsInitialized]);
|
|
36
|
-
// re-load if `pathParams` or `queryParams` change
|
|
36
|
+
// re-load if `pathParams` or `queryParams` change, unless `disableAutoLoadOnParamsChange` is true
|
|
37
37
|
react_1.useEffect(function () {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (!disableAutoLoadOnParamsChange) {
|
|
39
|
+
collection_1.handleCollectionParamsChange(modelName, previousModelName, pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
40
|
+
}
|
|
41
|
+
}, [
|
|
42
|
+
disableAutoLoadOnParamsChange,
|
|
43
|
+
load,
|
|
44
|
+
modelName,
|
|
45
|
+
pathParams,
|
|
46
|
+
previousModelName,
|
|
47
|
+
previousPathParams,
|
|
48
|
+
previousQueryParams,
|
|
49
|
+
queryParams
|
|
50
|
+
]);
|
|
40
51
|
// cleanup on unmount
|
|
41
52
|
react_1.useEffect(function () {
|
|
42
53
|
return function cleanup() {
|
|
@@ -5,7 +5,7 @@ var react_1 = require("react");
|
|
|
5
5
|
var collection_1 = require("../utils/collection");
|
|
6
6
|
var useCollectionConfiguration_1 = require("./useCollectionConfiguration");
|
|
7
7
|
function useCollectionItem(props) {
|
|
8
|
-
var modelName = props.modelName;
|
|
8
|
+
var modelName = props.modelName, disableAutoLoadOnParamsChange = props.disableAutoLoadOnParamsChange;
|
|
9
9
|
// state, route, and redux
|
|
10
10
|
var config = useCollectionConfiguration_1.useCollectionConfiguration(props, collection_1.selectCollectionItemFromState);
|
|
11
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;
|
|
@@ -34,10 +34,21 @@ function useCollectionItem(props) {
|
|
|
34
34
|
setIsInitialized(true);
|
|
35
35
|
}
|
|
36
36
|
}, [isInitialized, load, methodConfig, model, setIsInitialized]);
|
|
37
|
-
// re-load if `pathParams` or `queryParams` change
|
|
37
|
+
// re-load if `pathParams` or `queryParams` change, unless `disableAutoLoadOnParamsChange` is true
|
|
38
38
|
react_1.useEffect(function () {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (!disableAutoLoadOnParamsChange) {
|
|
40
|
+
collection_1.handleCollectionItemParamsChange(modelName, previousModelName, pathParams, previousPathParams, queryParams, previousQueryParams, load);
|
|
41
|
+
}
|
|
42
|
+
}, [
|
|
43
|
+
disableAutoLoadOnParamsChange,
|
|
44
|
+
load,
|
|
45
|
+
modelName,
|
|
46
|
+
pathParams,
|
|
47
|
+
previousModelName,
|
|
48
|
+
previousPathParams,
|
|
49
|
+
previousQueryParams,
|
|
50
|
+
queryParams
|
|
51
|
+
]);
|
|
41
52
|
return {
|
|
42
53
|
guid: guid,
|
|
43
54
|
model: model,
|
|
@@ -14,8 +14,10 @@ export interface CollectionCommonProps {
|
|
|
14
14
|
pathParams: string[];
|
|
15
15
|
/** Custom queryParams for use in all requests. */
|
|
16
16
|
queryParams?: Dictionary<string>;
|
|
17
|
-
/** Whether
|
|
17
|
+
/** Whether to disable triggering `load()` after mounting. Default is `false`. */
|
|
18
18
|
disableAutoLoad?: boolean;
|
|
19
|
+
/** Whether to disable triggering `load()` when `pathParams` or `queryParams` change. Default is `false`. */
|
|
20
|
+
disableAutoLoadOnParamsChange?: boolean;
|
|
19
21
|
}
|
|
20
22
|
/** See `CollectionSelectorMethod` */
|
|
21
23
|
export interface CollectionSelectorMethodParams {
|
package/package.json
CHANGED