@trackunit/filters-graphql-hook 2.6.16 → 2.6.17

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
@@ -347,6 +347,27 @@ const deviceHealthIssueType = {
347
347
  OPERATING_HOURS_REPORTING_24_HOURS_PER_DAY: "OPERATING_HOURS_REPORTING_24_HOURS_PER_DAY",
348
348
  UNUSUAL_OPERATING_HOURS: "UNUSUAL_OPERATING_HOURS",
349
349
  };
350
+ const inspectionLastPerformed = {
351
+ MORE_THAN_LAST_2_HOURS: "MORE_THAN_LAST_2_HOURS",
352
+ MORE_THAN_LAST_7_DAYS: "MORE_THAN_LAST_7_DAYS",
353
+ MORE_THAN_LAST_8_HOURS: "MORE_THAN_LAST_8_HOURS",
354
+ MORE_THAN_LAST_12_HOURS: "MORE_THAN_LAST_12_HOURS",
355
+ MORE_THAN_LAST_24_HOURS: "MORE_THAN_LAST_24_HOURS",
356
+ WITHIN_LAST_2_HOURS: "WITHIN_LAST_2_HOURS",
357
+ WITHIN_LAST_7_DAYS: "WITHIN_LAST_7_DAYS",
358
+ WITHIN_LAST_8_HOURS: "WITHIN_LAST_8_HOURS",
359
+ WITHIN_LAST_12_HOURS: "WITHIN_LAST_12_HOURS",
360
+ WITHIN_LAST_24_HOURS: "WITHIN_LAST_24_HOURS"};
361
+ const inspectionResponseStatus = {
362
+ FAILED_CRITICAL: "FAILED_CRITICAL",
363
+ FAILED_LOW: "FAILED_LOW",
364
+ PASSED: "PASSED",
365
+ SKIPPED: "SKIPPED",
366
+ };
367
+ const inspectionTemplateAssigned = {
368
+ HAS_TEMPLATE: "HAS_TEMPLATE",
369
+ NO_TEMPLATE: "NO_TEMPLATE",
370
+ };
350
371
  const metadataCompleteness = {
351
372
  COMPLETE: "COMPLETE",
352
373
  PARTIAL: "PARTIAL",
@@ -455,6 +476,60 @@ const useCustomFieldFilters = (filters) => {
455
476
  */
456
477
  const CustomFieldPrefix = "cf__";
457
478
 
479
+ /**
480
+ * Sentinel value used by the "last inspection result" filter bar to represent assets that have no
481
+ * last inspection. It is not an `InspectionResponseStatus`; it is translated to
482
+ * `inspectionLastFilters.includeNeverInspected` at this boundary.
483
+ */
484
+ const NO_LAST_INSPECTION = "NO_LAST_INSPECTION";
485
+ /**
486
+ * Sentinel value used by the "last performed inspection" filter bar to represent assets that have
487
+ * never been inspected. Translated to `inspectionLastFilters.includeNeverInspected`.
488
+ */
489
+ const NEVER_PERFORMED = "NEVER";
490
+ /**
491
+ * Maps the "last performed inspection" filter bar option values (UI/URL state) to the schema's
492
+ * `InspectionLastPerformed` enum. `ALL` and `NEVER` are handled separately and intentionally absent.
493
+ */
494
+ const lastPerformedInspectionToPerformedEnum = {
495
+ WITHIN_2_HOURS: inspectionLastPerformed.WITHIN_LAST_2_HOURS,
496
+ WITHIN_8_HOURS: inspectionLastPerformed.WITHIN_LAST_8_HOURS,
497
+ WITHIN_12_HOURS: inspectionLastPerformed.WITHIN_LAST_12_HOURS,
498
+ WITHIN_24_HOURS: inspectionLastPerformed.WITHIN_LAST_24_HOURS,
499
+ WITHIN_7_DAYS: inspectionLastPerformed.WITHIN_LAST_7_DAYS,
500
+ MORE_THAN_2_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_2_HOURS,
501
+ MORE_THAN_8_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_8_HOURS,
502
+ MORE_THAN_12_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_12_HOURS,
503
+ MORE_THAN_24_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_24_HOURS,
504
+ MORE_THAN_7_DAYS_AGO: inspectionLastPerformed.MORE_THAN_LAST_7_DAYS,
505
+ };
506
+ /**
507
+ * Builds the `inspectionLastFilters` GraphQL input from the "last inspection result" (checkbox) and
508
+ * "last performed inspection" (radio) filter bar values.
509
+ *
510
+ * - `lastInspectionResult` supplies `statuses` (PASSED / FAILED_LOW / FAILED_CRITICAL / SKIPPED) and,
511
+ * via the `NO_LAST_INSPECTION` sentinel, `includeNeverInspected`.
512
+ * - `lastPerformedInspection` supplies `performed` (relative time bucket) and, via the `NEVER`
513
+ * sentinel, `includeNeverInspected`.
514
+ *
515
+ * @param filters - Filter bar values
516
+ * @returns {InspectionLastFilters | undefined} The combined input, or undefined when nothing is set
517
+ */
518
+ const buildInspectionLastFilters = (filters) => {
519
+ const lastInspectionResultValues = stringArrayOrUndefined(filters.lastInspectionResult) ?? [];
520
+ const statuses = fixTypes(lastInspectionResultValues.filter(value => value !== NO_LAST_INSPECTION), inspectionResponseStatus);
521
+ const lastPerformedInspectionValue = valueNameOrUndefined(filters.lastPerformedInspection)?.value;
522
+ const performed = lastPerformedInspectionValue
523
+ ? lastPerformedInspectionToPerformedEnum[lastPerformedInspectionValue]
524
+ : undefined;
525
+ const includeNeverInspected = lastInspectionResultValues.includes(NO_LAST_INSPECTION) || lastPerformedInspectionValue === NEVER_PERFORMED
526
+ ? true
527
+ : undefined;
528
+ if (!statuses && !performed && !includeNeverInspected) {
529
+ return undefined;
530
+ }
531
+ return { statuses, performed, includeNeverInspected };
532
+ };
458
533
  /**
459
534
  * Converts field filters to a format that can be used by the GraphQL API for AssetFiltersInput
460
535
  *
@@ -494,6 +569,13 @@ const useActiveAssetFilters = (filters) => {
494
569
  valueNameOrUndefined(filters.metadataCompleteness)?.value === "ALL"
495
570
  ? undefined
496
571
  : fixType(valueNameOrUndefined(filters.metadataCompleteness)?.value, metadataCompleteness),
572
+ // Combines the "last inspection result" (statuses) and "last performed inspection" (time bucket)
573
+ // filter bar values into the single `inspectionLastFilters` input.
574
+ inspectionLastFilters: buildInspectionLastFilters(filters),
575
+ inspectionTemplateAssigned: !valueNameOrUndefined(filters.inspectionTemplateAssigned) ||
576
+ valueNameOrUndefined(filters.inspectionTemplateAssigned)?.value === "ALL"
577
+ ? undefined
578
+ : fixType(valueNameOrUndefined(filters.inspectionTemplateAssigned)?.value, inspectionTemplateAssigned),
497
579
  serviceBooked: parsedServiceBooked.success ? parsedServiceBooked.data : undefined,
498
580
  servicePlanAssignments: fixTypes(filters.servicePlanStatus, servicePlanStatus),
499
581
  servicePlanIds: valueNameArrayOrUndefined(filters.servicePlan),
package/index.esm.js CHANGED
@@ -345,6 +345,27 @@ const deviceHealthIssueType = {
345
345
  OPERATING_HOURS_REPORTING_24_HOURS_PER_DAY: "OPERATING_HOURS_REPORTING_24_HOURS_PER_DAY",
346
346
  UNUSUAL_OPERATING_HOURS: "UNUSUAL_OPERATING_HOURS",
347
347
  };
348
+ const inspectionLastPerformed = {
349
+ MORE_THAN_LAST_2_HOURS: "MORE_THAN_LAST_2_HOURS",
350
+ MORE_THAN_LAST_7_DAYS: "MORE_THAN_LAST_7_DAYS",
351
+ MORE_THAN_LAST_8_HOURS: "MORE_THAN_LAST_8_HOURS",
352
+ MORE_THAN_LAST_12_HOURS: "MORE_THAN_LAST_12_HOURS",
353
+ MORE_THAN_LAST_24_HOURS: "MORE_THAN_LAST_24_HOURS",
354
+ WITHIN_LAST_2_HOURS: "WITHIN_LAST_2_HOURS",
355
+ WITHIN_LAST_7_DAYS: "WITHIN_LAST_7_DAYS",
356
+ WITHIN_LAST_8_HOURS: "WITHIN_LAST_8_HOURS",
357
+ WITHIN_LAST_12_HOURS: "WITHIN_LAST_12_HOURS",
358
+ WITHIN_LAST_24_HOURS: "WITHIN_LAST_24_HOURS"};
359
+ const inspectionResponseStatus = {
360
+ FAILED_CRITICAL: "FAILED_CRITICAL",
361
+ FAILED_LOW: "FAILED_LOW",
362
+ PASSED: "PASSED",
363
+ SKIPPED: "SKIPPED",
364
+ };
365
+ const inspectionTemplateAssigned = {
366
+ HAS_TEMPLATE: "HAS_TEMPLATE",
367
+ NO_TEMPLATE: "NO_TEMPLATE",
368
+ };
348
369
  const metadataCompleteness = {
349
370
  COMPLETE: "COMPLETE",
350
371
  PARTIAL: "PARTIAL",
@@ -453,6 +474,60 @@ const useCustomFieldFilters = (filters) => {
453
474
  */
454
475
  const CustomFieldPrefix = "cf__";
455
476
 
477
+ /**
478
+ * Sentinel value used by the "last inspection result" filter bar to represent assets that have no
479
+ * last inspection. It is not an `InspectionResponseStatus`; it is translated to
480
+ * `inspectionLastFilters.includeNeverInspected` at this boundary.
481
+ */
482
+ const NO_LAST_INSPECTION = "NO_LAST_INSPECTION";
483
+ /**
484
+ * Sentinel value used by the "last performed inspection" filter bar to represent assets that have
485
+ * never been inspected. Translated to `inspectionLastFilters.includeNeverInspected`.
486
+ */
487
+ const NEVER_PERFORMED = "NEVER";
488
+ /**
489
+ * Maps the "last performed inspection" filter bar option values (UI/URL state) to the schema's
490
+ * `InspectionLastPerformed` enum. `ALL` and `NEVER` are handled separately and intentionally absent.
491
+ */
492
+ const lastPerformedInspectionToPerformedEnum = {
493
+ WITHIN_2_HOURS: inspectionLastPerformed.WITHIN_LAST_2_HOURS,
494
+ WITHIN_8_HOURS: inspectionLastPerformed.WITHIN_LAST_8_HOURS,
495
+ WITHIN_12_HOURS: inspectionLastPerformed.WITHIN_LAST_12_HOURS,
496
+ WITHIN_24_HOURS: inspectionLastPerformed.WITHIN_LAST_24_HOURS,
497
+ WITHIN_7_DAYS: inspectionLastPerformed.WITHIN_LAST_7_DAYS,
498
+ MORE_THAN_2_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_2_HOURS,
499
+ MORE_THAN_8_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_8_HOURS,
500
+ MORE_THAN_12_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_12_HOURS,
501
+ MORE_THAN_24_HOURS_AGO: inspectionLastPerformed.MORE_THAN_LAST_24_HOURS,
502
+ MORE_THAN_7_DAYS_AGO: inspectionLastPerformed.MORE_THAN_LAST_7_DAYS,
503
+ };
504
+ /**
505
+ * Builds the `inspectionLastFilters` GraphQL input from the "last inspection result" (checkbox) and
506
+ * "last performed inspection" (radio) filter bar values.
507
+ *
508
+ * - `lastInspectionResult` supplies `statuses` (PASSED / FAILED_LOW / FAILED_CRITICAL / SKIPPED) and,
509
+ * via the `NO_LAST_INSPECTION` sentinel, `includeNeverInspected`.
510
+ * - `lastPerformedInspection` supplies `performed` (relative time bucket) and, via the `NEVER`
511
+ * sentinel, `includeNeverInspected`.
512
+ *
513
+ * @param filters - Filter bar values
514
+ * @returns {InspectionLastFilters | undefined} The combined input, or undefined when nothing is set
515
+ */
516
+ const buildInspectionLastFilters = (filters) => {
517
+ const lastInspectionResultValues = stringArrayOrUndefined(filters.lastInspectionResult) ?? [];
518
+ const statuses = fixTypes(lastInspectionResultValues.filter(value => value !== NO_LAST_INSPECTION), inspectionResponseStatus);
519
+ const lastPerformedInspectionValue = valueNameOrUndefined(filters.lastPerformedInspection)?.value;
520
+ const performed = lastPerformedInspectionValue
521
+ ? lastPerformedInspectionToPerformedEnum[lastPerformedInspectionValue]
522
+ : undefined;
523
+ const includeNeverInspected = lastInspectionResultValues.includes(NO_LAST_INSPECTION) || lastPerformedInspectionValue === NEVER_PERFORMED
524
+ ? true
525
+ : undefined;
526
+ if (!statuses && !performed && !includeNeverInspected) {
527
+ return undefined;
528
+ }
529
+ return { statuses, performed, includeNeverInspected };
530
+ };
456
531
  /**
457
532
  * Converts field filters to a format that can be used by the GraphQL API for AssetFiltersInput
458
533
  *
@@ -492,6 +567,13 @@ const useActiveAssetFilters = (filters) => {
492
567
  valueNameOrUndefined(filters.metadataCompleteness)?.value === "ALL"
493
568
  ? undefined
494
569
  : fixType(valueNameOrUndefined(filters.metadataCompleteness)?.value, metadataCompleteness),
570
+ // Combines the "last inspection result" (statuses) and "last performed inspection" (time bucket)
571
+ // filter bar values into the single `inspectionLastFilters` input.
572
+ inspectionLastFilters: buildInspectionLastFilters(filters),
573
+ inspectionTemplateAssigned: !valueNameOrUndefined(filters.inspectionTemplateAssigned) ||
574
+ valueNameOrUndefined(filters.inspectionTemplateAssigned)?.value === "ALL"
575
+ ? undefined
576
+ : fixType(valueNameOrUndefined(filters.inspectionTemplateAssigned)?.value, inspectionTemplateAssigned),
495
577
  serviceBooked: parsedServiceBooked.success ? parsedServiceBooked.data : undefined,
496
578
  servicePlanAssignments: fixTypes(filters.servicePlanStatus, servicePlanStatus),
497
579
  servicePlanIds: valueNameArrayOrUndefined(filters.servicePlan),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/filters-graphql-hook",
3
- "version": "2.6.16",
3
+ "version": "2.6.17",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,14 +10,14 @@
10
10
  "@graphql-codegen/cli": "^5.0.3",
11
11
  "@graphql-typed-document-node/core": "^3.2.0",
12
12
  "zod": "^3.25.76",
13
- "@trackunit/iris-app-build-utilities": "2.3.5",
14
- "@trackunit/filters-filter-bar": "2.4.10",
13
+ "@trackunit/iris-app-build-utilities": "2.3.6",
14
+ "@trackunit/filters-filter-bar": "2.4.11",
15
15
  "@trackunit/shared-utils": "1.16.4",
16
- "@trackunit/iris-app-api": "2.3.5",
16
+ "@trackunit/iris-app-api": "2.3.6",
17
17
  "@trackunit/react-core-contexts-test": "1.18.4",
18
- "@trackunit/i18n-library-translation": "2.3.5",
18
+ "@trackunit/i18n-library-translation": "2.3.6",
19
19
  "@trackunit/iris-app-runtime-core-api": "1.17.4",
20
- "@trackunit/react-core-hooks": "1.20.5"
20
+ "@trackunit/react-core-hooks": "1.20.6"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@apollo/client": "^3.13.8",