From 2220ab24b385188515da7c176bf9c1ac72651fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Wed, 22 Mar 2023 19:40:49 +0000 Subject: [PATCH] feat: add easy way to configure search filtering for nested properties --- .eslintignore | 1 + .eslintrc.json | 4 +- cypress/integration/context-menu.spec.ts | 6 +- cypress/tsconfig.json | 3 +- ...thing-list-item-virtual-scroll-strategy.ts | 1 + .../context/context-menu.component.spec.ts | 14 +++- .../menu/context/context-menu.component.ts | 27 +++---- .../modules/menu/context/context-menu.html | 32 +++------ .../menu/context/context-menu.service.spec.ts | 22 ++++++ .../menu/context/context-menu.service.ts | 41 ++++++----- src/app/modules/menu/context/context-type.ts | 19 ++++- src/app/modules/menu/context/facet-filter.ts | 70 +++++++++++++++++++ .../page/profile-page-section.component.ts | 2 +- .../profile/page/profile-page.component.ts | 2 +- src/config/README.md | 4 ++ .../profile-page-sections.ts} | 2 +- src/config/search-filter.ts | 52 ++++++++++++++ tsconfig.json | 3 +- 18 files changed, 237 insertions(+), 68 deletions(-) create mode 100644 src/app/modules/menu/context/facet-filter.ts create mode 100644 src/config/README.md rename src/{app/modules/profile/page/sections.ts => config/profile-page-sections.ts} (99%) create mode 100644 src/config/search-filter.ts diff --git a/.eslintignore b/.eslintignore index 15298306..0b48282a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ src/app/_helpers/data +node_modules diff --git a/.eslintrc.json b/.eslintrc.json index e99efd23..828ef112 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,7 @@ "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", - "project": ["tsconfig.json", "e2e/tsconfig.e2e.json"], + "project": ["tsconfig.json", "tsconfig.spec.json", "e2e/tsconfig.e2e.json"], "createDefaultProgram": true }, "extends": [ @@ -44,7 +44,6 @@ ], "unicorn/no-nested-ternary": "off", "unicorn/better-regex": "off", - "jsdoc/no-types": "error", "jsdoc/require-param": "off", "jsdoc/require-param-description": "error", @@ -52,7 +51,6 @@ "jsdoc/require-returns": "off", "jsdoc/require-param-type": "off", "jsdoc/require-returns-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-unused-vars": [ "error", diff --git a/cypress/integration/context-menu.spec.ts b/cypress/integration/context-menu.spec.ts index af21800c..26e587cf 100644 --- a/cypress/integration/context-menu.spec.ts +++ b/cypress/integration/context-menu.spec.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 StApps + * Copyright (C) 2023 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -54,14 +54,14 @@ describe('context menu', function () { it('should truncate categories', function () { cy.get('stapps-context').within(() => { - cy.contains('ion-item', '(4) Universitätsveranstaltung').should('not.exist'); + cy.contains('ion-item', '(1) Universitätsveranstaltung').should('not.exist'); cy.get('.context-filter > ion-button').click(); cy.contains('ion-item', '(4) Universitätsveranstaltung').should('exist'); }); }); it('should truncate long category items', function () { - cy.contains('ion-list', 'Kategorien | Akademische Veranstaltung').within(() => { + cy.contains('ion-list', 'Akademische Veranstaltung / Kategorien').within(() => { cy.contains('ion-item', '(1) Tutorium').should('not.exist'); cy.get('div > ion-button').click(); cy.contains('ion-item', '(1) Tutorium').should('exist'); diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index 79d78d7e..e7094d5c 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -4,5 +4,6 @@ "compilerOptions": { "sourceMap": false, "types": ["cypress"] - } + }, + "exclude": [] } diff --git a/src/app/modules/data/list/sc-thing-list-item-virtual-scroll-strategy.ts b/src/app/modules/data/list/sc-thing-list-item-virtual-scroll-strategy.ts index 76387a29..0b5aea51 100644 --- a/src/app/modules/data/list/sc-thing-list-item-virtual-scroll-strategy.ts +++ b/src/app/modules/data/list/sc-thing-list-item-virtual-scroll-strategy.ts @@ -13,6 +13,7 @@ * this program. If not, see . */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import {CdkVirtualForOf, CdkVirtualScrollViewport, VirtualScrollStrategy} from '@angular/cdk/scrolling'; import {BehaviorSubject, Subject, Subscription, takeUntil, timer} from 'rxjs'; import {debounceTime, distinctUntilChanged, tap} from 'rxjs/operators'; diff --git a/src/app/modules/menu/context/context-menu.component.spec.ts b/src/app/modules/menu/context/context-menu.component.spec.ts index 609d06e8..eade660a 100644 --- a/src/app/modules/menu/context/context-menu.component.spec.ts +++ b/src/app/modules/menu/context/context-menu.component.spec.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 StApps + * Copyright (C) 2023 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -159,6 +159,11 @@ describe('ContextMenuComponent', async () => { { field: 'type', buckets: [{count: 10, key: 'date series', checked: true}], + info: { + onlyOnType: SCThingType.AcademicEvent, + field: 'date series', + sortOrder: 0, + }, }, ]; @@ -210,7 +215,7 @@ function getFilterContextType(): FilterContext { compact: false, options: facetsMock .filter(facet => facet.buckets.length > 0) - .map(facet => { + .map((facet, i) => { return { buckets: facet.buckets.map(bucket => { return { @@ -222,6 +227,11 @@ function getFilterContextType(): FilterContext { compact: false, field: facet.field, onlyOnType: facet.onlyOnType, + info: { + onlyOnType: facet.onlyOnType, + field: facet.field, + sortOrder: i, + }, }; }), }; diff --git a/src/app/modules/menu/context/context-menu.component.ts b/src/app/modules/menu/context/context-menu.component.ts index 1bcbeda4..33cdafff 100644 --- a/src/app/modules/menu/context/context-menu.component.ts +++ b/src/app/modules/menu/context/context-menu.component.ts @@ -17,7 +17,7 @@ import {LangChangeEvent, TranslateService} from '@ngx-translate/core'; import {SCLanguage, SCThingTranslator, SCThingType, SCTranslations} from '@openstapps/core'; import {Subscription} from 'rxjs'; import {ContextMenuService} from './context-menu.service'; -import {FilterContext, SortContext, SortContextOption} from './context-type'; +import {FilterContext, FilterFacet, SortContext, SortContextOption} from './context-type'; /** * The context menu @@ -49,6 +49,19 @@ export class ContextMenuComponent implements OnDestroy { */ filterOption: FilterContext; + /** + * Picks facets based on the compact filter option and sorts + * them based on + * + * No specific type => Type name alphabetically => Bucket count + */ + get facets(): FilterFacet[] { + const options = this.filterOption.compact + ? this.filterOption.options.slice(0, this.compactFilterOptionCount) + : this.filterOption.options; + return options.filter(it => it.buckets.length > 0); + } + /** * Possible languages to be used for translation */ @@ -102,18 +115,6 @@ export class ContextMenuComponent implements OnDestroy { this.contextMenuService.contextFilterChanged(this.filterOption); }; - /** - * Returns translated property name - */ - getTranslatedPropertyName(property: string, onlyForType?: SCThingType): string { - return ( - this.translator.translatedPropertyNames( - onlyForType ?? SCThingType.AcademicEvent, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ) as any - )[property]; - } - /** * Returns translated property value */ diff --git a/src/app/modules/menu/context/context-menu.html b/src/app/modules/menu/context/context-menu.html index cbfca7a8..8e3a5b82 100644 --- a/src/app/modules/menu/context/context-menu.html +++ b/src/app/modules/menu/context/context-menu.html @@ -1,5 +1,5 @@