From dbb58e7072b87cc47cb6b4c4c41b1fdd808f80b3 Mon Sep 17 00:00:00 2001 From: "Yassine R." Date: Thu, 28 Nov 2024 02:23:39 +0100 Subject: [PATCH] refactor(frontend): enforce performance of sort & filter --- packages/backend/package.json | 2 +- .../1731349672897-manual-migration.ts | 3 +- .../usager/UsagerSubscriber.typeorm.ts | 2 +- .../usagers/controllers/usagers.controller.ts | 3 +- packages/backend/src/util/index.ts | 1 - packages/common/jest.config.ts | 3 - packages/common/package.json | 1 + .../src/search/functions}/index.ts | 0 .../functions}/normalize-string.spec.ts | 6 +- .../src/search/functions}/normalize-string.ts | 0 packages/common/src/search/index.ts | 1 + packages/frontend/package.json | 2 +- .../contact-support.component.ts | 4 +- .../manage-filters.component.spec.ts | 4 +- .../manage-filters.component.ts | 18 +- .../manage-usagers-page.component.spec.ts | 2 +- .../manage-usagers-page.component.ts | 14 +- .../manage-usagers-table.html | 4 +- .../usager-filter/UsagersFilterCriteria.ts | 5 +- .../checkers/usagerPassageChecker.service.ts | 4 +- .../usagersSearchStringFilter.service.spec.ts | 101 ----- .../usagersSearchStringFilter.service.ts | 77 ++-- .../services/usagersSorter.service.spec.ts | 280 ++++++++++-- .../services/usagersSorter.service.ts | 124 ++---- .../usager-filter/usagersFilter.service.ts | 61 ++- .../manage-usagers/pipes/sort-label.pipe.ts | 2 +- .../manage-usagers/utils/search/diacritics.ts | 402 ------------------ .../utils/search/search.spec.ts | 94 ---- .../manage-usagers/utils/search/search.ts | 39 +- .../utils/search/searchCore.spec.ts | 4 +- .../manage-usagers/utils/search/searchCore.ts | 10 +- .../utils/sorter/SortableAttribute.type.ts | 7 - .../sorter/SortableAttributeType.type.ts | 1 - .../utils/sorter/dataCompare.service.spec.ts | 53 --- .../utils/sorter/dataCompare.service.ts | 39 -- .../utils/sorter/dataObjectCompare.service.ts | 74 ---- .../utils/sorter/dataSorter.service.spec.ts | 78 +--- .../utils/sorter/dataSorter.service.ts | 90 ++-- .../manage-usagers/utils/sorter/index.ts | 5 +- .../modules/shared/services/auth.service.ts | 2 +- .../utils/languages/LANGUAGES.const.ts | 54 +-- packages/frontend/src/assets/files/news.json | 29 ++ yarn.lock | 3 +- 43 files changed, 523 insertions(+), 1185 deletions(-) rename packages/{backend/src/util/search => common/src/search/functions}/index.ts (100%) rename packages/{backend/src/util/search => common/src/search/functions}/normalize-string.spec.ts (89%) rename packages/{backend/src/util/search => common/src/search/functions}/normalize-string.ts (100%) delete mode 100644 packages/frontend/src/app/modules/manage-usagers/components/usager-filter/services/usagersSearchStringFilter.service.spec.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/search/diacritics.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/search/search.spec.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/sorter/SortableAttribute.type.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/sorter/SortableAttributeType.type.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/sorter/dataCompare.service.spec.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/sorter/dataCompare.service.ts delete mode 100644 packages/frontend/src/app/modules/manage-usagers/utils/sorter/dataObjectCompare.service.ts diff --git a/packages/backend/package.json b/packages/backend/package.json index 155b2b5719..dbdfc8e211 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -1,7 +1,7 @@ { "name": "@domifa/backend", "private": true, - "version": "2.173.26", + "version": "2.186.0", "description": "", "author": "", "license": "MIT", diff --git a/packages/backend/src/_migrations/1731349672897-manual-migration.ts b/packages/backend/src/_migrations/1731349672897-manual-migration.ts index f4897c5979..d608bfe8fd 100644 --- a/packages/backend/src/_migrations/1731349672897-manual-migration.ts +++ b/packages/backend/src/_migrations/1731349672897-manual-migration.ts @@ -1,7 +1,8 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import { domifaConfig } from "../config"; -import { appLogger, normalizeString } from "../util"; +import { appLogger } from "../util"; +import { normalizeString } from "@domifa/common"; const batchSize = 5000; export class ManualMigration1731349672897 implements MigrationInterface { diff --git a/packages/backend/src/database/entities/usager/UsagerSubscriber.typeorm.ts b/packages/backend/src/database/entities/usager/UsagerSubscriber.typeorm.ts index e9e347a817..badb13279e 100644 --- a/packages/backend/src/database/entities/usager/UsagerSubscriber.typeorm.ts +++ b/packages/backend/src/database/entities/usager/UsagerSubscriber.typeorm.ts @@ -4,7 +4,7 @@ import { InsertEvent, UpdateEvent, } from "typeorm"; -import { normalizeString } from "../../../util"; +import { normalizeString } from "@domifa/common"; import { UsagerTable } from "./UsagerTable.typeorm"; @EventSubscriber() diff --git a/packages/backend/src/usagers/controllers/usagers.controller.ts b/packages/backend/src/usagers/controllers/usagers.controller.ts index bca5017555..96e60d0415 100644 --- a/packages/backend/src/usagers/controllers/usagers.controller.ts +++ b/packages/backend/src/usagers/controllers/usagers.controller.ts @@ -32,7 +32,7 @@ import { usagerEntretienRepository, } from "../../database"; -import { cleanPath, normalizeString } from "../../util"; +import { cleanPath } from "../../util"; import { UserStructureAuthenticated, USER_STRUCTURE_ROLE_ALL, @@ -59,6 +59,7 @@ import { CerfaDocType, UsagerDecision, getUsagerDeadlines, + normalizeString, } from "@domifa/common"; import { UsagerHistoryStateService } from "../services/usagerHistoryState.service"; import { domifaConfig } from "../../config"; diff --git a/packages/backend/src/util/index.ts b/packages/backend/src/util/index.ts index 3901d9bdfe..d85378034f 100644 --- a/packages/backend/src/util/index.ts +++ b/packages/backend/src/util/index.ts @@ -6,6 +6,5 @@ export * from "./file-manager"; export * from "./functions"; export * from "./logs"; export * from "./phone"; -export * from "./search"; export * from "./sentry"; export * from "./territoires"; diff --git a/packages/common/jest.config.ts b/packages/common/jest.config.ts index ac84dda13a..246b0a64ae 100644 --- a/packages/common/jest.config.ts +++ b/packages/common/jest.config.ts @@ -1,9 +1,6 @@ import type { Config } from "jest"; const jestConfig: Config = { - collectCoverage: false, - coverageReporters: ["cobertura"], - coverageDirectory: "./coverage/", modulePathIgnorePatterns: ["/dist/"], preset: "ts-jest/presets/js-with-ts", }; diff --git a/packages/common/package.json b/packages/common/package.json index e63ef35bb7..7bef273a38 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -34,6 +34,7 @@ "lint-staged": "^15.2.10", "prettier": "2.8.8", "ts-jest": "^29.1.1", + "ts-node": "^10.9.2", "typescript": "^4.3.5" }, "dependencies": { diff --git a/packages/backend/src/util/search/index.ts b/packages/common/src/search/functions/index.ts similarity index 100% rename from packages/backend/src/util/search/index.ts rename to packages/common/src/search/functions/index.ts diff --git a/packages/backend/src/util/search/normalize-string.spec.ts b/packages/common/src/search/functions/normalize-string.spec.ts similarity index 89% rename from packages/backend/src/util/search/normalize-string.spec.ts rename to packages/common/src/search/functions/normalize-string.spec.ts index 8764c1d54b..a633b69284 100644 --- a/packages/backend/src/util/search/normalize-string.spec.ts +++ b/packages/common/src/search/functions/normalize-string.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { normalizeString } from "./normalize-string"; // Tests de tous les cas possibles @@ -50,7 +51,8 @@ describe("normalizeString", () => { test("cas limites", () => { expect(normalizeString("")).toBe(""); expect(normalizeString(" ")).toBe(" "); - expect(normalizeString(null)).toBe(""); - expect(normalizeString(undefined)).toBe(""); + // skipcq: JS-0323 + expect(normalizeString(null as any)).toBe(""); + expect(normalizeString(undefined as any)).toBe(""); }); }); diff --git a/packages/backend/src/util/search/normalize-string.ts b/packages/common/src/search/functions/normalize-string.ts similarity index 100% rename from packages/backend/src/util/search/normalize-string.ts rename to packages/common/src/search/functions/normalize-string.ts diff --git a/packages/common/src/search/index.ts b/packages/common/src/search/index.ts index 4c003c2422..3ce6d8ee46 100644 --- a/packages/common/src/search/index.ts +++ b/packages/common/src/search/index.ts @@ -1,3 +1,4 @@ // @index('./*', f => `export * from '${f.path}'`) +export * from "./functions"; export * from "./Timings.type"; export * from "./USAGER_DEADLINES.const"; diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 416a3fc934..3dedcfcf88 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@domifa/frontend", - "version": "2.173.26", + "version": "2.186.0", "main": "index.js", "author": "Incubateur des Ministères Sociaux (https://incubateur.social.gouv.fr)", "license": "Apache-2.0", diff --git a/packages/frontend/src/app/modules/general/components/contact-support/contact-support.component.ts b/packages/frontend/src/app/modules/general/components/contact-support/contact-support.component.ts index 52d3b16a97..d8ca8d9de6 100644 --- a/packages/frontend/src/app/modules/general/components/contact-support/contact-support.component.ts +++ b/packages/frontend/src/app/modules/general/components/contact-support/contact-support.component.ts @@ -1,4 +1,3 @@ -import { GeneralService } from "./../../services/general.service"; import { UserStructure } from "@domifa/common"; import { Component, OnDestroy, OnInit } from "@angular/core"; import { @@ -17,6 +16,7 @@ import { validateUpload, } from "../../../../shared"; import { Subscription } from "rxjs"; +import { GeneralService } from "../../services/general.service"; @Component({ selector: "app-contact-support", @@ -149,7 +149,7 @@ export class ContactSupportComponent implements OnInit, OnDestroy { this.submitted = false; this.contactForm.reset(); this.toastService.success( - "Message envoyé avec succès, l'équipe vous recontactera très prochainnement" + "Message envoyé avec succès, l'équipe vous recontactera très prochainement" ); }, error: () => { diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.spec.ts b/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.spec.ts index fc0a55dbe8..6c27727de3 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.spec.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.spec.ts @@ -27,7 +27,7 @@ describe("ManageFiltersComponent", () => { searchStringField: "DEFAULT", page: 0, lastInteractionDate: null, - sortKey: "NAME", + sortKey: "NOM", sortValue: "asc", statut: "VALIDE", }; @@ -43,7 +43,7 @@ describe("ManageFiltersComponent", () => { it("devrait toujours retourner les éléments de tri de base", () => { const result = component.getSortKeys(); expect(result).toContainEqual({ id: "ID", label: "ID" }); - expect(result).toContainEqual({ id: "NAME", label: "nom" }); + expect(result).toContainEqual({ id: "NOM", label: "nom" }); expect(result).toContainEqual({ id: "ECHEANCE", label: expect.any(String), diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.ts b/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.ts index ab3bc7f3dc..2e00defdfd 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-filters/manage-filters.component.ts @@ -1,4 +1,11 @@ -import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; +import { + Component, + EventEmitter, + Input, + OnChanges, + OnInit, + Output, +} from "@angular/core"; import { UsagersFilterCriteria, UsagersFilterCriteriaSortKey, @@ -14,7 +21,7 @@ import { templateUrl: "./manage-filters.component.html", styleUrls: ["../manage-usagers-page/manage-usagers-page.component.scss"], }) -export class ManageFiltersComponent implements OnInit { +export class ManageFiltersComponent implements OnInit, OnChanges { @Input() public filters: UsagersFilterCriteria; @Input() public usagersRadiesLoadedCount: number; @Input() public usagersRadiesTotalCount: number; @@ -57,6 +64,11 @@ export class ManageFiltersComponent implements OnInit { ngOnInit(): void { this.sortMenuItems = this.getSortKeys(); } + + ngOnChanges() { + this.sortMenuItems = this.getSortKeys(); + } + public getSortKeys(): Array<{ id: UsagersFilterCriteriaSortKey; label: string; @@ -66,7 +78,7 @@ export class ManageFiltersComponent implements OnInit { label: string; }> = [ { id: "ID", label: "ID" }, - { id: "NAME", label: "nom" }, + { id: "NOM", label: "nom" }, { id: "ECHEANCE", label: this.getEcheanceLabel() }, ]; diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.spec.ts b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.spec.ts index 413abd5449..34074b3a72 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.spec.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.spec.ts @@ -52,7 +52,7 @@ describe("ManageUsagersPageComponent", () => { searchStringField: "DEFAULT", page: 1, lastInteractionDate: null, - sortKey: "NAME", + sortKey: "NOM", sortValue: "asc", statut: "VALIDE", }); diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts index 5de466fec3..d8bbe59740 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts @@ -460,12 +460,12 @@ export class ManageUsagersPageComponent if (element === "statut" && this.filters[element] !== value) { this.resetFiltersInStatus(); this.filters[element] = value; - this.setSortKeyAndValue("NAME", this.filters.sortValue); + this.setSortKeyAndValue("NOM", this.filters.sortValue); } else if ( ["interactionType", "lastInteractionDate", "echeance"].includes(element) ) { this.filters[element] = this.filters[element] === value ? null : value; - this.setSortKeyAndValue("NAME", "asc"); + this.setSortKeyAndValue("NOM", "asc"); } else { this.filters[element] = value; } @@ -496,7 +496,6 @@ export class ManageUsagersPageComponent filters: UsagersFilterCriteria; allUsagers: UsagerLight[]; }): void { - console.log("applyFilters"); this.searching = true; this.resetCheckboxes(); @@ -542,10 +541,7 @@ export class ManageUsagersPageComponent this.usagers = []; return; } - console.log({ - sortKey: this.filters.sortKey, - sortValue: this.filters.sortValue, - }); + this.filteredUsagers = usagersSorter.sortBy(this.filteredUsagers, { sortKey: this.filters.sortKey, sortValue: this.filters.sortValue, @@ -598,10 +594,10 @@ export class ManageUsagersPageComponent } private setFilters() { - localStorage.setItem("MANAGE_USAGERS", JSON.stringify(this.filters)); + localStorage.setItem("MANAGE", JSON.stringify(this.filters)); } private getFilters(): null | Partial { - const filters = localStorage.getItem("MANAGE_USAGERS"); + const filters = localStorage.getItem("MANAGE"); return filters === null ? {} : JSON.parse(filters); } diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-table/manage-usagers-table.html b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-table/manage-usagers-table.html index 56a0020b2f..57a48c7c4a 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-table/manage-usagers-table.html +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-table/manage-usagers-table.html @@ -102,8 +102,8 @@