@trackunit/filters-graphql-hook 0.0.440 → 0.0.441

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
@@ -4,9 +4,9 @@ require('react/jsx-runtime');
4
4
  var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
5
5
  var filtersFilterBar = require('@trackunit/filters-filter-bar');
6
6
  var sharedUtils = require('@trackunit/shared-utils');
7
+ var zod = require('zod');
7
8
  var reactCoreHooks = require('@trackunit/react-core-hooks');
8
9
  var react = require('react');
9
- var zod = require('zod');
10
10
 
11
11
  var defaultTranslations = {
12
12
 
@@ -181,6 +181,10 @@ input) => {
181
181
  }
182
182
  return null;
183
183
  };
184
+ const geoJsonSimplifiedPolygonSchema = zod.z.strictObject({
185
+ type: zod.z.literal("Polygon"),
186
+ coordinates: zod.z.array(zod.z.array(zod.z.tuple([zod.z.number(), zod.z.number()]))),
187
+ });
184
188
 
185
189
  const assetActivityState = {
186
190
  IDLING: "IDLING",
@@ -330,13 +334,13 @@ const useActiveAssetFilters = (filters) => {
330
334
  return {};
331
335
  }
332
336
  const followExist = filters.followed === "ALL" ? undefined : true;
333
- const parsedBoundingBox = boundingBoxSchema.optional().safeParse(filters.boundingBox);
334
337
  const parsedServiceBooked = booleanArraySchema.safeParse(filters.serviceBooked);
338
+ const parsedArea = geoJsonSimplifiedPolygonSchema.safeParse(filters.area);
335
339
  return {
336
340
  assetIds: stringArrayOrUndefined(filters.assetIds),
337
341
  searchQuery: typeof filters.search === "string" && filters.search !== "" ? filters.search : undefined,
338
342
  activities: fixTypes(filters.activity, assetActivityState),
339
- boundingBox: parsedBoundingBox.success ? parsedBoundingBox.data : undefined,
343
+ area: parsedArea.success ? parsedArea.data : undefined,
340
344
  brands: stringArrayOrUndefined(filters.brands),
341
345
  types: stringArrayOrUndefined(filters.types),
342
346
  criticalities: fixTypes(filters.criticality, assetCriticalityState),
@@ -371,13 +375,6 @@ const useActiveAssetFilters = (filters) => {
371
375
  }, [filters, customFields, systemOfMeasurement]);
372
376
  return filter;
373
377
  };
374
- const latitudeSchema = zod.z.number().min(-90).max(90);
375
- const longitudeSchema = zod.z.number().min(-180).max(180);
376
- const coordinateSchema = zod.z.object({ latitude: latitudeSchema, longitude: longitudeSchema });
377
- const boundingBoxSchema = zod.z.object({
378
- nw: coordinateSchema,
379
- se: coordinateSchema,
380
- });
381
378
  const booleanArraySchema = zod.z.array(zod.z.boolean());
382
379
 
383
380
  /**
@@ -442,6 +439,7 @@ exports.CustomFieldPrefix = CustomFieldPrefix;
442
439
  exports.convertToAssetSortInput = convertToAssetSortInput;
443
440
  exports.fixType = fixType;
444
441
  exports.fixTypes = fixTypes;
442
+ exports.geoJsonSimplifiedPolygonSchema = geoJsonSimplifiedPolygonSchema;
445
443
  exports.isStringArrayValue = isStringArrayValue;
446
444
  exports.isValueName = isValueName;
447
445
  exports.positiveValueBooleanOrNull = positiveValueBooleanOrNull;
package/index.esm.js CHANGED
@@ -2,9 +2,9 @@ import 'react/jsx-runtime';
2
2
  import { registerTranslations } from '@trackunit/i18n-library-translation';
3
3
  import { isStringArrayFilterValue, isMinMaxFilterValue, isDateRangeValue, isBooleanValue } from '@trackunit/filters-filter-bar';
4
4
  import { truthy } from '@trackunit/shared-utils';
5
+ import { z } from 'zod';
5
6
  import { useCurrentUserSystemOfMeasurement, useAssetSorting } from '@trackunit/react-core-hooks';
6
7
  import { useMemo } from 'react';
7
- import { z } from 'zod';
8
8
 
9
9
  var defaultTranslations = {
10
10
 
@@ -179,6 +179,10 @@ input) => {
179
179
  }
180
180
  return null;
181
181
  };
182
+ const geoJsonSimplifiedPolygonSchema = z.strictObject({
183
+ type: z.literal("Polygon"),
184
+ coordinates: z.array(z.array(z.tuple([z.number(), z.number()]))),
185
+ });
182
186
 
183
187
  const assetActivityState = {
184
188
  IDLING: "IDLING",
@@ -328,13 +332,13 @@ const useActiveAssetFilters = (filters) => {
328
332
  return {};
329
333
  }
330
334
  const followExist = filters.followed === "ALL" ? undefined : true;
331
- const parsedBoundingBox = boundingBoxSchema.optional().safeParse(filters.boundingBox);
332
335
  const parsedServiceBooked = booleanArraySchema.safeParse(filters.serviceBooked);
336
+ const parsedArea = geoJsonSimplifiedPolygonSchema.safeParse(filters.area);
333
337
  return {
334
338
  assetIds: stringArrayOrUndefined(filters.assetIds),
335
339
  searchQuery: typeof filters.search === "string" && filters.search !== "" ? filters.search : undefined,
336
340
  activities: fixTypes(filters.activity, assetActivityState),
337
- boundingBox: parsedBoundingBox.success ? parsedBoundingBox.data : undefined,
341
+ area: parsedArea.success ? parsedArea.data : undefined,
338
342
  brands: stringArrayOrUndefined(filters.brands),
339
343
  types: stringArrayOrUndefined(filters.types),
340
344
  criticalities: fixTypes(filters.criticality, assetCriticalityState),
@@ -369,13 +373,6 @@ const useActiveAssetFilters = (filters) => {
369
373
  }, [filters, customFields, systemOfMeasurement]);
370
374
  return filter;
371
375
  };
372
- const latitudeSchema = z.number().min(-90).max(90);
373
- const longitudeSchema = z.number().min(-180).max(180);
374
- const coordinateSchema = z.object({ latitude: latitudeSchema, longitude: longitudeSchema });
375
- const boundingBoxSchema = z.object({
376
- nw: coordinateSchema,
377
- se: coordinateSchema,
378
- });
379
376
  const booleanArraySchema = z.array(z.boolean());
380
377
 
381
378
  /**
@@ -436,4 +433,4 @@ const useAssetQueryFilters = (props) => {
436
433
  */
437
434
  setupLibraryTranslations();
438
435
 
439
- export { CustomFieldPrefix, convertToAssetSortInput, fixType, fixTypes, isStringArrayValue, isValueName, positiveValueBooleanOrNull, stringArrayOrUndefined, useActiveAssetFilters, useAssetQueryFilters, useAssetSortInput, useCustomFieldFilters, valueBooleanOrUndefined, valueNameArrayOrUndefined, valuesIfNotEmpty };
436
+ export { CustomFieldPrefix, convertToAssetSortInput, fixType, fixTypes, geoJsonSimplifiedPolygonSchema, isStringArrayValue, isValueName, positiveValueBooleanOrNull, stringArrayOrUndefined, useActiveAssetFilters, useAssetQueryFilters, useAssetSortInput, useCustomFieldFilters, valueBooleanOrUndefined, valueNameArrayOrUndefined, valuesIfNotEmpty };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/filters-graphql-hook",
3
- "version": "0.0.440",
3
+ "version": "0.0.441",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
package/src/fixTypes.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ValueName } from "@trackunit/filters-filter-bar";
2
+ import { z } from "zod";
2
3
  /**
3
4
  * Fix types for filter values
4
5
  *
@@ -43,3 +44,13 @@ export declare const valueBooleanOrUndefined: (input: any) => boolean | undefine
43
44
  *
44
45
  */
45
46
  export declare const positiveValueBooleanOrNull: (input: any) => boolean | null;
47
+ export declare const geoJsonSimplifiedPolygonSchema: z.ZodObject<{
48
+ type: z.ZodLiteral<"Polygon">;
49
+ coordinates: z.ZodArray<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, "many">;
50
+ }, "strict", z.ZodTypeAny, {
51
+ type: "Polygon";
52
+ coordinates: [number, number][][];
53
+ }, {
54
+ type: "Polygon";
55
+ coordinates: [number, number][][];
56
+ }>;
@@ -129,6 +129,10 @@ export type Scalars = {
129
129
  output: any;
130
130
  };
131
131
  };
132
+ export declare const areaFilterGeoJsonGeometryType: {
133
+ readonly Polygon: "Polygon";
134
+ };
135
+ export type AreaFilterGeoJsonGeometryType = (typeof areaFilterGeoJsonGeometryType)[keyof typeof areaFilterGeoJsonGeometryType];
132
136
  export declare const assetActivityState: {
133
137
  readonly IDLING: "IDLING";
134
138
  readonly STOPPED: "STOPPED";
@@ -432,18 +436,32 @@ export declare const systemOfMeasurement: {
432
436
  readonly US_CUSTOMARY: "US_CUSTOMARY";
433
437
  };
434
438
  export type SystemOfMeasurement = (typeof systemOfMeasurement)[keyof typeof systemOfMeasurement];
439
+ export type AreaInput = {
440
+ /** The coordinates of the GeoJSON geometry see [the GeoJSON RFC](https://www.rfc-editor.org/rfc/rfc7946.html#section-3.1) for details. */
441
+ coordinates: Array<Scalars["GeoJSONCoordinates"]["input"]>;
442
+ /** The type of the GeoJSON object. */
443
+ type: AreaFilterGeoJsonGeometryType;
444
+ };
435
445
  export type AssetFiltersInput = {
436
446
  /** Filter by if the asset is active */
437
447
  activeFilter?: InputMaybe<Scalars["Boolean"]["input"]>;
438
448
  /** List of activities */
439
449
  activities?: InputMaybe<Array<AssetActivityState>>;
450
+ /** Filter by area */
451
+ area?: InputMaybe<AreaInput>;
440
452
  /** A list of asset ID's to do a bulk lookup for. */
441
453
  assetIds?: InputMaybe<Array<Scalars["ID"]["input"]>>;
442
454
  /** List of asset types */
443
455
  assetTypes?: InputMaybe<Array<AssetType>>;
444
- /** Filter by bounding box */
456
+ /**
457
+ * Filter by bounding box
458
+ * @deprecated Use area filter instead
459
+ */
445
460
  boundingBox?: InputMaybe<BoundingBoxInput>;
446
- /** Filter by bounding shape */
461
+ /**
462
+ * Filter by bounding shape
463
+ * @deprecated Use area filter instead
464
+ */
447
465
  boundingShape?: InputMaybe<BoundingShapeInput>;
448
466
  /** Filter to only include this list of brands */
449
467
  brands?: InputMaybe<Array<Scalars["String"]["input"]>>;