Browse Source

Construct the terms only once for schema filters.

pull/778/head
Sebastian 4 years ago
parent
commit
7d4ba774ab
  1. 2
      frontend/app/features/content/pages/schemas/schemas-page.component.html
  2. 7
      frontend/app/features/content/pages/schemas/schemas-page.component.ts
  3. 2
      frontend/app/features/schemas/pages/schemas/schemas-page.component.html
  4. 6
      frontend/app/features/schemas/pages/schemas/schemas-page.component.ts
  5. 16
      frontend/app/shared/components/schema-category.component.ts
  6. 13
      frontend/app/shared/state/schemas.state.ts

2
frontend/app/features/content/pages/schemas/schemas-page.component.html

@ -21,7 +21,7 @@
<ng-container *ngIf="schemasState.publishedSchemas | async; let schemas"> <ng-container *ngIf="schemasState.publishedSchemas | async; let schemas">
<sqx-schema-category *ngFor="let category of schemasState.categories | async; trackBy: trackByCategory" <sqx-schema-category *ngFor="let category of schemasState.categories | async; trackBy: trackByCategory"
[schemaCategory]="category" [schemaCategory]="category"
[schemasFilter]="schemasFilter.valueChanges | async" [schemasFilter]="schemaFilterFunction | async"
[forContent]="true"> [forContent]="true">
</sqx-schema-category> </sqx-schema-category>
</ng-container> </ng-container>

7
frontend/app/features/content/pages/schemas/schemas-page.component.ts

@ -7,7 +7,8 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { LocalStoreService, SchemaCategory, SchemasState, Settings } from '@app/shared'; import { buildSchemaFilterFunction, LocalStoreService, SchemaCategory, SchemasState, Settings } from '@app/shared';
import { map } from 'rxjs/operators';
@Component({ @Component({
selector: 'sqx-schemas-page', selector: 'sqx-schemas-page',
@ -17,6 +18,10 @@ import { LocalStoreService, SchemaCategory, SchemasState, Settings } from '@app/
export class SchemasPageComponent { export class SchemasPageComponent {
public schemasFilter = new FormControl(); public schemasFilter = new FormControl();
public schemaFilterFunction =
this.schemasFilter.valueChanges.pipe(
map(buildSchemaFilterFunction));
public isCollapsed: boolean; public isCollapsed: boolean;
public get width() { public get width() {

2
frontend/app/features/schemas/pages/schemas/schemas-page.component.html

@ -23,7 +23,7 @@
<div cdkDropListGroup> <div cdkDropListGroup>
<sqx-schema-category *ngFor="let category of schemasState.categories | async; trackBy: trackByCategory" <sqx-schema-category *ngFor="let category of schemasState.categories | async; trackBy: trackByCategory"
[schemaCategory]="category" [schemaCategory]="category"
[schemasFilter]="schemasFilter.valueChanges | async" [schemasFilter]="schemaFilterFunction | async"
(remove)="removeCategory(category.displayName)"> (remove)="removeCategory(category.displayName)">
</sqx-schema-category> </sqx-schema-category>
</div> </div>

6
frontend/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -8,7 +8,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl } from '@angular/forms'; import { FormBuilder, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { CreateCategoryForm, DialogModel, MessageBus, ResourceOwner, SchemaCategory, SchemaDto, SchemasState } from '@app/shared'; import { buildSchemaFilterFunction, CreateCategoryForm, DialogModel, MessageBus, ResourceOwner, SchemaCategory, SchemaDto, SchemasState } from '@app/shared';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { SchemaCloning } from './../messages'; import { SchemaCloning } from './../messages';
@ -23,6 +23,10 @@ export class SchemasPageComponent extends ResourceOwner implements OnInit {
public schemasFilter = new FormControl(); public schemasFilter = new FormControl();
public schemaFilterFunction =
this.schemasFilter.valueChanges.pipe(
map(buildSchemaFilterFunction));
public import: any; public import: any;
constructor( constructor(

16
frontend/app/shared/components/schema-category.component.ts

@ -14,7 +14,7 @@ import { Settings } from '../state/settings';
const ITEM_HEIGHT = 2.5; const ITEM_HEIGHT = 2.5;
@Component({ @Component({
selector: 'sqx-schema-category', selector: 'sqx-schema-category[schemaCategory]',
styleUrls: ['./schema-category.component.scss'], styleUrls: ['./schema-category.component.scss'],
templateUrl: './schema-category.component.html', templateUrl: './schema-category.component.html',
animations: [ animations: [
@ -30,7 +30,7 @@ export class SchemaCategoryComponent implements OnChanges {
public schemaCategory: SchemaCategory; public schemaCategory: SchemaCategory;
@Input() @Input()
public schemasFilter: string; public schemasFilter?: ((schema: SchemaDto) => boolean) | null;
@Input() @Input()
public forContent?: boolean | null; public forContent?: boolean | null;
@ -62,13 +62,11 @@ export class SchemaCategoryComponent implements OnChanges {
this.filteredSchemas = this.filteredSchemas.filter(x => !app.roleProperties[Settings.AppProperties.HIDE_CONTENTS(x.name)]); this.filteredSchemas = this.filteredSchemas.filter(x => !app.roleProperties[Settings.AppProperties.HIDE_CONTENTS(x.name)]);
} }
if (this.schemasFilter) { const filter = this.schemasFilter;
const terms = this.schemasFilter.trim().split(' ').map(x => new RegExp(x.trim(), 'i'));
const matches = (value: string | undefined | null) => value && terms.every(term => value.search(term) >= 0); if (filter) {
this.filteredSchemas = this.filteredSchemas.filter(x => this.filteredSchemas = this.filteredSchemas.filter(x => filter(x));
matches(x.name) ||
matches(x.properties.label) ||
matches(x.properties.hints));
this.isCollapsed = false; this.isCollapsed = false;
} else { } else {
this.isCollapsed = this.localStore.getBoolean(this.configKey()); this.isCollapsed = this.localStore.getBoolean(this.configKey());

13
frontend/app/shared/state/schemas.state.ts

@ -419,3 +419,16 @@ function buildCategories(categories: Set<string>, allSchemas: SchemasList): Read
return result; return result;
} }
export function buildSchemaFilterFunction(filter: string): (schema: SchemaDto) => boolean {
const terms = filter.split(' ').map(filter => new RegExp(filter.trim(), 'i'));
const matches = (value: string | undefined | null) => {
return !!value && terms.every(term => value.search(term) >= 0);
};
return (schema: SchemaDto) =>
matches(schema.name) ||
matches(schema.properties.label) ||
matches(schema.properties.hints);
}

Loading…
Cancel
Save