studiokit-scaffolding-js 7.0.2 → 7.0.3-next.1.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCollectionConfiguration = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
4
5
|
var react_1 = require("react");
|
|
5
6
|
var react_redux_1 = require("react-redux");
|
|
6
7
|
var react_router_1 = require("react-router");
|
|
@@ -24,11 +25,12 @@ function useCollectionConfiguration(props, selectorFunction) {
|
|
|
24
25
|
var _b = react_1.useState(modelStatus_1.MODEL_STATUS.UNINITIALIZED), modelStatus = _b[0], setModelStatus = _b[1];
|
|
25
26
|
var previousModelStatus = usePrevious_1.usePrevious(modelStatus);
|
|
26
27
|
var _c = react_1.useState(), fetchingId = _c[0], setFetchingId = _c[1];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// keep track of new and previous pathParams values
|
|
29
|
+
// this will almost always be a new array, which causes issues for hook deps
|
|
30
|
+
var pathParamsValue = react_1.useMemo(function () { return propPathParams || route_1.getPathParamsFromRouteMatchParams(routeMatchParams, modelName); }, [modelName, propPathParams, routeMatchParams]);
|
|
31
|
+
var previousPathParamsValue = usePrevious_1.usePrevious(pathParamsValue);
|
|
32
|
+
// only update pathParams if the value array actually contains different values, since it will always be a different ref
|
|
33
|
+
var pathParams = react_1.useMemo(function () { return (lodash_1.isEqual(pathParamsValue, previousPathParamsValue) ? previousPathParamsValue : pathParamsValue); }, [pathParamsValue, previousPathParamsValue]);
|
|
32
34
|
var _d = react_redux_1.useSelector(function (state) {
|
|
33
35
|
return selectorFunction({ guid: guid, modelName: modelName, pathParams: pathParams, routeMatchParams: routeMatchParams, state: state });
|
|
34
36
|
}), model = _d.model, isCollectionItem = _d.isCollectionItem;
|
|
@@ -38,11 +40,11 @@ function useCollectionConfiguration(props, selectorFunction) {
|
|
|
38
40
|
var previousQueryParams = usePrevious_1.usePrevious(queryParams);
|
|
39
41
|
var modelArray = react_1.useMemo(function () { return (!isCollectionItem ? model_1.getModelArray(model, guid) : undefined); }, [guid, isCollectionItem, model]);
|
|
40
42
|
var modelMinusRelations = react_1.useMemo(function () { return (isCollectionItem ? model_1.getModelMinusRelations(model) : undefined); }, [isCollectionItem, model]);
|
|
41
|
-
var changeModelStatus = function (newModelStatus, newFetchingId) {
|
|
43
|
+
var changeModelStatus = react_1.useCallback(function (newModelStatus, newFetchingId) {
|
|
42
44
|
setFetchingId(newFetchingId);
|
|
43
45
|
setModelStatus(newModelStatus);
|
|
44
|
-
};
|
|
45
|
-
var methodConfig = {
|
|
46
|
+
}, []);
|
|
47
|
+
var methodConfig = react_1.useMemo(function () { return ({
|
|
46
48
|
modelName: modelName,
|
|
47
49
|
pathParams: pathParams,
|
|
48
50
|
queryParams: queryParams,
|
|
@@ -50,11 +52,11 @@ function useCollectionConfiguration(props, selectorFunction) {
|
|
|
50
52
|
modelStatus: modelStatus,
|
|
51
53
|
changeModelStatus: changeModelStatus,
|
|
52
54
|
disableAutoLoad: disableAutoLoad
|
|
53
|
-
};
|
|
55
|
+
}); }, [modelName, pathParams, queryParams, guid, modelStatus, changeModelStatus, disableAutoLoad]);
|
|
54
56
|
// update `modelStatus` when `model` fetch finishes
|
|
55
57
|
react_1.useEffect(function () {
|
|
56
58
|
model_1.handleModelFetchFinish(model, previousModel, fetchingId, changeModelStatus);
|
|
57
|
-
}, [fetchingId, model, previousModel]);
|
|
59
|
+
}, [fetchingId, model, previousModel, changeModelStatus]);
|
|
58
60
|
return {
|
|
59
61
|
previousModelName: previousModelName,
|
|
60
62
|
guid: guid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "studiokit-scaffolding-js",
|
|
3
|
-
"version": "7.0.2",
|
|
3
|
+
"version": "7.0.3-next.1.2",
|
|
4
4
|
"description": "Common scaffolding for Studio apps at Purdue",
|
|
5
5
|
"repository": "https://gitlab.com/purdue-informatics/studiokit/studiokit-scaffolding-js",
|
|
6
6
|
"license": "MIT",
|