Skip to content

Commit

Permalink
refactor(frontend): enforce performance of sort & filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Nov 28, 2024
1 parent 9da2b21 commit dbb58e7
Show file tree
Hide file tree
Showing 43 changed files with 523 additions and 1,185 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@domifa/backend",
"private": true,
"version": "2.173.26",
"version": "2.186.0",
"description": "",
"author": "",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
InsertEvent,
UpdateEvent,
} from "typeorm";
import { normalizeString } from "../../../util";
import { normalizeString } from "@domifa/common";
import { UsagerTable } from "./UsagerTable.typeorm";

@EventSubscriber()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
usagerEntretienRepository,
} from "../../database";

import { cleanPath, normalizeString } from "../../util";
import { cleanPath } from "../../util";
import {
UserStructureAuthenticated,
USER_STRUCTURE_ROLE_ALL,
Expand All @@ -59,6 +59,7 @@ import {
CerfaDocType,
UsagerDecision,
getUsagerDeadlines,
normalizeString,
} from "@domifa/common";
import { UsagerHistoryStateService } from "../services/usagerHistoryState.service";
import { domifaConfig } from "../../config";
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
3 changes: 0 additions & 3 deletions packages/common/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { Config } from "jest";

const jestConfig: Config = {
collectCoverage: false,
coverageReporters: ["cobertura"],
coverageDirectory: "./coverage/",
modulePathIgnorePatterns: ["<rootDir>/dist/"],
preset: "ts-jest/presets/js-with-ts",
};
Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { normalizeString } from "./normalize-string";

// Tests de tous les cas possibles
Expand Down Expand Up @@ -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("");
});
});
1 change: 1 addition & 0 deletions packages/common/src/search/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./functions";
export * from "./Timings.type";
export * from "./USAGER_DEADLINES.const";
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@domifa/frontend",
"version": "2.173.26",
"version": "2.186.0",
"main": "index.js",
"author": "Incubateur des Ministères Sociaux <[email protected]> (https://incubateur.social.gouv.fr)",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GeneralService } from "./../../services/general.service";
import { UserStructure } from "@domifa/common";
import { Component, OnDestroy, OnInit } from "@angular/core";
import {
Expand All @@ -17,6 +16,7 @@ import {
validateUpload,
} from "../../../../shared";
import { Subscription } from "rxjs";
import { GeneralService } from "../../services/general.service";

@Component({
selector: "app-contact-support",
Expand Down Expand Up @@ -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: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("ManageFiltersComponent", () => {
searchStringField: "DEFAULT",
page: 0,
lastInteractionDate: null,
sortKey: "NAME",
sortKey: "NOM",
sortValue: "asc",
statut: "VALIDE",
};
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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() },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("ManageUsagersPageComponent", () => {
searchStringField: "DEFAULT",
page: 1,
lastInteractionDate: null,
sortKey: "NAME",
sortKey: "NOM",
sortValue: "asc",
statut: "VALIDE",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -496,7 +496,6 @@ export class ManageUsagersPageComponent
filters: UsagersFilterCriteria;
allUsagers: UsagerLight[];
}): void {
console.log("applyFilters");
this.searching = true;
this.resetCheckboxes();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<UsagersFilterCriteria> {
const filters = localStorage.getItem("MANAGE_USAGERS");
const filters = localStorage.getItem("MANAGE");
return filters === null ? {} : JSON.parse(filters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
<th scope="col">
<button
type="button"
[attr.aria-sort]="filters.sortKey ==='NAME' ? filters.sortValue : null"
(click)="updateFilters.emit({ element: 'sortKey', value: 'NAME' })"
[attr.aria-sort]="filters.sortKey ==='NOM' ? filters.sortValue : null"
(click)="updateFilters.emit({ element: 'sortKey', value: 'NOM' })"
>
<span class="visually-hidden">Trier par</span>
Nom prénom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type UsagersFilterCriteriaStatut =

export type UsagersFilterCriteriaSortKey =
| "PASSAGE"
| "NAME"
| "NOM"
| "ECHEANCE"
| "ID";

Expand All @@ -40,7 +40,6 @@ export class UsagersFilterCriteria {
public page: number;

constructor(search?: Partial<UsagersFilterCriteria> | null) {
console.log({ search });
this.interactionType = search?.interactionType || null;
this.lastInteractionDate = search?.lastInteractionDate || null;
this.entretien = search?.entretien || null;
Expand All @@ -50,7 +49,7 @@ export class UsagersFilterCriteria {
this.statut = search?.statut || "VALIDE";
this.page = search?.page || 1;

this.sortKey = search?.sortKey || "NAME";
this.sortKey = search?.sortKey || "NOM";
this.sortValue = search?.sortValue || "asc";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function check({
const interactionTime = new Date(
usager.lastInteraction.dateInteraction
).getTime();
console.log({ deadlineTime, interactionTime });
return deadlineTime > interactionTime;

return deadlineTime >= interactionTime;
}

return true;
Expand Down

This file was deleted.

Loading

0 comments on commit dbb58e7

Please sign in to comment.