@trackunit/react-core-hooks 0.2.45 → 0.2.46
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/index.cjs +37 -0
- package/index.js +37 -1
- package/package.json +3 -3
- package/src/index.d.ts +1 -0
package/index.cjs
CHANGED
|
@@ -188,6 +188,42 @@ const useCustomFieldRuntime = () => {
|
|
|
188
188
|
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
193
|
+
*
|
|
194
|
+
* @param entity The entity to fetch and set custom fields for.
|
|
195
|
+
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
196
|
+
*/
|
|
197
|
+
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
198
|
+
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
199
|
+
const [customFields, setCustomFields] = React.useState();
|
|
200
|
+
React.useEffect(() => {
|
|
201
|
+
if (entity.id) {
|
|
202
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
setCustomFields(yield getCustomFieldsFor(entity));
|
|
204
|
+
}))();
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
setCustomFields([]);
|
|
208
|
+
}
|
|
209
|
+
}, [entity, getCustomFieldsFor]);
|
|
210
|
+
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
if (entity.id) {
|
|
212
|
+
yield setCustomFieldsFor(entity, values);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
|
+
if (entity.id) {
|
|
217
|
+
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
customFields,
|
|
222
|
+
setCustomFieldsFromFormDataForEntity,
|
|
223
|
+
setCustomFieldsForEntity,
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
191
227
|
/**
|
|
192
228
|
* A hook to expose rest runtime to be used in React components
|
|
193
229
|
*
|
|
@@ -297,6 +333,7 @@ exports.useAssetRuntime = useAssetRuntime;
|
|
|
297
333
|
exports.useAssetSorting = useAssetSorting;
|
|
298
334
|
exports.useCurrentUser = useCurrentUser;
|
|
299
335
|
exports.useCustomFieldRuntime = useCustomFieldRuntime;
|
|
336
|
+
exports.useCustomFieldRuntimeForEntity = useCustomFieldRuntimeForEntity;
|
|
300
337
|
exports.useDeveloperSettings = useDeveloperSettings;
|
|
301
338
|
exports.useEnvironment = useEnvironment;
|
|
302
339
|
exports.useGlobalSelection = useGlobalSelection;
|
package/index.js
CHANGED
|
@@ -162,6 +162,42 @@ const useCustomFieldRuntime = () => {
|
|
|
162
162
|
return CustomFieldRuntime;
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
167
|
+
*
|
|
168
|
+
* @param entity The entity to fetch and set custom fields for.
|
|
169
|
+
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
170
|
+
*/
|
|
171
|
+
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
172
|
+
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
173
|
+
const [customFields, setCustomFields] = useState();
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (entity.id) {
|
|
176
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
setCustomFields(yield getCustomFieldsFor(entity));
|
|
178
|
+
}))();
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
setCustomFields([]);
|
|
182
|
+
}
|
|
183
|
+
}, [entity, getCustomFieldsFor]);
|
|
184
|
+
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
if (entity.id) {
|
|
186
|
+
yield setCustomFieldsFor(entity, values);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
if (entity.id) {
|
|
191
|
+
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
customFields,
|
|
196
|
+
setCustomFieldsFromFormDataForEntity,
|
|
197
|
+
setCustomFieldsForEntity,
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
165
201
|
/**
|
|
166
202
|
* A hook to expose rest runtime to be used in React components
|
|
167
203
|
*
|
|
@@ -258,4 +294,4 @@ const useCurrentUser = () => {
|
|
|
258
294
|
return context;
|
|
259
295
|
};
|
|
260
296
|
|
|
261
|
-
export { AssetSortingProvider, CurrentUserProvider, DeveloperSettingsContext, DeveloperSettingsProvider, EnvironmentContextProvider, GlobalSelectionProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAssetRuntime, useAssetSorting, useCurrentUser, useCustomFieldRuntime, useDeveloperSettings, useEnvironment, useGlobalSelection, useNavigationRuntime, useRestRuntime, useSiteRuntime, useToast, useToken, useURLSynchronization, useUserSubscription };
|
|
297
|
+
export { AssetSortingProvider, CurrentUserProvider, DeveloperSettingsContext, DeveloperSettingsProvider, EnvironmentContextProvider, GlobalSelectionProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAssetRuntime, useAssetSorting, useCurrentUser, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useDeveloperSettings, useEnvironment, useGlobalSelection, useNavigationRuntime, useRestRuntime, useSiteRuntime, useToast, useToken, useURLSynchronization, useUserSubscription };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"types": "./src/index.d.ts",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@trackunit/iris-app-runtime-core": "0.3.
|
|
12
|
-
"@trackunit/iris-app-runtime-core-api": "0.3.
|
|
11
|
+
"@trackunit/iris-app-runtime-core": "0.3.33",
|
|
12
|
+
"@trackunit/iris-app-runtime-core-api": "0.3.28",
|
|
13
13
|
"@trackunit/react-core-contexts-api": "0.2.26",
|
|
14
14
|
"react": "18.2.0",
|
|
15
15
|
"react-router-dom": "6.4.5"
|
package/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./runtimes/navigation";
|
|
|
6
6
|
export * from "./runtimes/navigation/useNavigationRuntime";
|
|
7
7
|
export * from "./runtimes/useAssetRuntime";
|
|
8
8
|
export * from "./runtimes/useCustomFieldRuntime";
|
|
9
|
+
export * from "./runtimes/useCustomFieldRuntimeForEntity";
|
|
9
10
|
export * from "./runtimes/useRestRuntime";
|
|
10
11
|
export * from "./runtimes/useSiteRuntime";
|
|
11
12
|
export * from "./subscription/UserSubscriptionProvider";
|