@trackunit/custom-field-api 0.1.228 → 0.1.229

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.js CHANGED
@@ -2167,7 +2167,7 @@ const getAllCustomFieldValueAndDefinitionFromRelevantNode = (node) => getFragmen
2167
2167
  */
2168
2168
  const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMeasurement, }) => {
2169
2169
  var _a, _b, _c, _d;
2170
- const { data: assetFields, loading: loadingAssetFields } = client.useQuery(GetCustomFieldsForAssetDocument, {
2170
+ const { data: assetFields, loading: loadingAssetFields, refetch: refetchAssetFields, } = client.useQuery(GetCustomFieldsForAssetDocument, {
2171
2171
  variables: {
2172
2172
  // eslint-disable-next-line local-rules/no-typescript-assertion
2173
2173
  entityId: entityId, // Assertion used as ts does not understand the skip removes nulls and undefined.
@@ -2180,7 +2180,7 @@ const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMe
2180
2180
  },
2181
2181
  },
2182
2182
  });
2183
- const { data: siteFields, loading: loadingSiteFields } = client.useQuery(GetCustomFieldsForSiteDocument, {
2183
+ const { data: siteFields, loading: loadingSiteFields, refetch: refetchSiteFields, } = client.useQuery(GetCustomFieldsForSiteDocument, {
2184
2184
  variables: {
2185
2185
  // eslint-disable-next-line local-rules/no-typescript-assertion
2186
2186
  entityId: entityId, // Assertion used as ts does not understand the skip removes nulls and undefined.
@@ -2206,7 +2206,19 @@ const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMe
2206
2206
  }, [(_b = (_a = assetFields === null || assetFields === void 0 ? void 0 : assetFields.asset) === null || _a === void 0 ? void 0 : _a.customFields) === null || _b === void 0 ? void 0 : _b.edges, entityType, (_d = (_c = siteFields === null || siteFields === void 0 ? void 0 : siteFields.site) === null || _c === void 0 ? void 0 : _c.customFields) === null || _d === void 0 ? void 0 : _d.edges]);
2207
2207
  const loading = react.useMemo(() => loadingAssetFields || loadingSiteFields, [loadingAssetFields, loadingSiteFields]);
2208
2208
  const noneNullableFields = react.useMemo(() => fields.filter(sharedUtils.nonNullable), [fields]);
2209
- return react.useMemo(() => ({ fields: noneNullableFields, loading }), [noneNullableFields, loading]);
2209
+ const refetch = react.useCallback(async () => {
2210
+ switch (entityType) {
2211
+ case "ASSET":
2212
+ await refetchAssetFields();
2213
+ break;
2214
+ case "SITE":
2215
+ await refetchSiteFields();
2216
+ break;
2217
+ default:
2218
+ return;
2219
+ }
2220
+ }, [entityType, refetchAssetFields, refetchSiteFields]);
2221
+ return react.useMemo(() => ({ fields: noneNullableFields, loading, refetch }), [noneNullableFields, loading, refetch]);
2210
2222
  };
2211
2223
  /**
2212
2224
  * Utility function that given a {CustomFieldValueAndDefinition} can tell if it contains a value or not
package/index.esm.js CHANGED
@@ -2165,7 +2165,7 @@ const getAllCustomFieldValueAndDefinitionFromRelevantNode = (node) => getFragmen
2165
2165
  */
2166
2166
  const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMeasurement, }) => {
2167
2167
  var _a, _b, _c, _d;
2168
- const { data: assetFields, loading: loadingAssetFields } = useQuery(GetCustomFieldsForAssetDocument, {
2168
+ const { data: assetFields, loading: loadingAssetFields, refetch: refetchAssetFields, } = useQuery(GetCustomFieldsForAssetDocument, {
2169
2169
  variables: {
2170
2170
  // eslint-disable-next-line local-rules/no-typescript-assertion
2171
2171
  entityId: entityId, // Assertion used as ts does not understand the skip removes nulls and undefined.
@@ -2178,7 +2178,7 @@ const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMe
2178
2178
  },
2179
2179
  },
2180
2180
  });
2181
- const { data: siteFields, loading: loadingSiteFields } = useQuery(GetCustomFieldsForSiteDocument, {
2181
+ const { data: siteFields, loading: loadingSiteFields, refetch: refetchSiteFields, } = useQuery(GetCustomFieldsForSiteDocument, {
2182
2182
  variables: {
2183
2183
  // eslint-disable-next-line local-rules/no-typescript-assertion
2184
2184
  entityId: entityId, // Assertion used as ts does not understand the skip removes nulls and undefined.
@@ -2204,7 +2204,19 @@ const useAllCustomFieldsValueAndDefinition = ({ entityId, entityType, systemOfMe
2204
2204
  }, [(_b = (_a = assetFields === null || assetFields === void 0 ? void 0 : assetFields.asset) === null || _a === void 0 ? void 0 : _a.customFields) === null || _b === void 0 ? void 0 : _b.edges, entityType, (_d = (_c = siteFields === null || siteFields === void 0 ? void 0 : siteFields.site) === null || _c === void 0 ? void 0 : _c.customFields) === null || _d === void 0 ? void 0 : _d.edges]);
2205
2205
  const loading = useMemo(() => loadingAssetFields || loadingSiteFields, [loadingAssetFields, loadingSiteFields]);
2206
2206
  const noneNullableFields = useMemo(() => fields.filter(nonNullable), [fields]);
2207
- return useMemo(() => ({ fields: noneNullableFields, loading }), [noneNullableFields, loading]);
2207
+ const refetch = useCallback(async () => {
2208
+ switch (entityType) {
2209
+ case "ASSET":
2210
+ await refetchAssetFields();
2211
+ break;
2212
+ case "SITE":
2213
+ await refetchSiteFields();
2214
+ break;
2215
+ default:
2216
+ return;
2217
+ }
2218
+ }, [entityType, refetchAssetFields, refetchSiteFields]);
2219
+ return useMemo(() => ({ fields: noneNullableFields, loading, refetch }), [noneNullableFields, loading, refetch]);
2208
2220
  };
2209
2221
  /**
2210
2222
  * Utility function that given a {CustomFieldValueAndDefinition} can tell if it contains a value or not
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/custom-field-api",
3
- "version": "0.1.228",
3
+ "version": "0.1.229",
4
4
  "engines": {
5
5
  "node": ">=20.x"
6
6
  },
@@ -19,6 +19,7 @@ export interface UseAllCustomFieldsValueAndDefinitionProps {
19
19
  export interface UseAllCustomFieldsValueAndDefinitionReturnValue {
20
20
  loading: boolean;
21
21
  fields: AllCustomFieldValueAndDefinition[];
22
+ refetch: () => Promise<void>;
22
23
  }
23
24
  /**
24
25
  * Custom hook to fetch custom fields and definitions for a specified entity.