Skip to content

Commit 991aea3

Browse files
feat: 4758 Add filter/search option in schemas with their ID
* 4758 * [skip ci] Add swagger.yaml --------- Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>
1 parent a90f9ed commit 991aea3

File tree

7 files changed

+134
-16
lines changed

7 files changed

+134
-16
lines changed

api-gateway/src/api/service/schema.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ export class SchemaApi {
417417
required: false,
418418
example: 'text'
419419
})
420+
@ApiQuery({
421+
name: 'searchOptions',
422+
type: String,
423+
description: 'Search Options',
424+
required: false,
425+
isArray: true,
426+
example: 'name'
427+
})
420428
@ApiOkResponse({
421429
description: 'Successful operation.',
422430
isArray: true,
@@ -440,6 +448,7 @@ export class SchemaApi {
440448
@Query('toolId') toolId: string,
441449
@Query('topicId') topicId: string,
442450
@Query('search') search: string,
451+
@Query('searchOptions') searchOptions: string[] | string,
443452
@Response() res: any
444453
): Promise<SchemaDTO[]> {
445454
try {
@@ -468,6 +477,13 @@ export class SchemaApi {
468477
if (search) {
469478
options.search = search;
470479
}
480+
if (searchOptions) {
481+
if (Array.isArray(searchOptions)) {
482+
options.searchOptions = searchOptions;
483+
} else if (typeof searchOptions === 'string') {
484+
options.searchOptions = searchOptions.split(',');
485+
}
486+
}
471487
options.fields = Object.values(SCHEMA_REQUIRED_PROPS)
472488

473489
const { items, count } = await guardians.getSchemasByOwnerV2(options, owner);

frontend/src/app/services/schema.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class SchemaService {
104104
category?: SchemaCategory,
105105
topicId?: string,
106106
search?: string,
107+
searchOptions?: string[],
107108
pageIndex?: number,
108109
pageSize?: number | string,
109110
}): Observable<HttpResponse<ISchema[]>> {

frontend/src/app/views/schemas/schemas.component.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@
6363
</p-dropdown>
6464
</div>
6565
<div *ngIf="isPolicy || isTool || isModule" class="guardian-input-container text-search">
66+
<p-multiSelect
67+
[(ngModel)]="textSearchOptionsValue"
68+
[options]="textSearchOptions"
69+
class="guardian-multiselect"
70+
appendTo="body"
71+
placeholder="Not selected"
72+
optionLabel="label"
73+
optionValue="value"
74+
[showHeader]="false"
75+
[filter]="false"
76+
panelStyleClass="guardian-multiselect-panel schema-text-search-options"
77+
(onPanelHide)="onFilter()">
78+
</p-multiSelect>
6679
<input
6780
(change)="onFilter()"
6881
[(ngModel)]="textSearch"

frontend/src/app/views/schemas/schemas.component.scss

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,29 @@ a {
654654

655655
.text-search {
656656
position: relative;
657+
display: grid;
658+
grid-template-columns: 140px auto;
659+
660+
&::ng-deep {
661+
.guardian-multiselect {
662+
.p-multiselect {
663+
border-top-right-radius: 0px;
664+
border-bottom-right-radius: 0px;
665+
}
666+
667+
&:hover {
668+
z-index: 2;
669+
}
670+
}
671+
}
672+
673+
input {
674+
border-top-left-radius: 0px;
675+
border-bottom-left-radius: 0px;
676+
position: relative;
677+
left: -1px;
678+
z-index: 1;
679+
}
657680

658681
.search-icon {
659682
position: absolute;
@@ -664,6 +687,12 @@ a {
664687
}
665688
}
666689

690+
::ng-deep .schema-text-search-options {
691+
.p-multiselect-items-wrapper {
692+
max-height: 300px !important;
693+
}
694+
}
695+
667696
.guardian-user-not-data {
668697
position: absolute;
669698
left: 50%;
@@ -790,7 +819,7 @@ a {
790819
}
791820
}
792821

793-
.p-treetable .p-treetable-thead > tr > th {
822+
.p-treetable .p-treetable-thead>tr>th {
794823
padding: 0;
795824
}
796825

@@ -817,10 +846,12 @@ a {
817846
background-color: var(--color-grey-white, #FFF);
818847
border-top-left-radius: 8px;
819848
border-top-right-radius: 8px;
849+
820850
&:first-child {
821851
border-top-left-radius: 8px;
822852
border-top-right-radius: 8px;
823853
}
854+
824855
&:last-child {
825856
border-top-right-radius: 8px;
826857
}
@@ -882,4 +913,4 @@ a {
882913
}
883914
}
884915
}
885-
}
916+
}

frontend/src/app/views/schemas/schemas.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ export class SchemaConfigComponent implements OnInit {
130130
{ label: 'System Schemas', value: SchemaType.System }
131131
];
132132
public textSearch: any;
133+
public textSearchOptionsValue: string[] = [
134+
'uuid', 'name', 'description', 'references', 'fields'
135+
];
136+
public textSearchOptions: { label: string; value: string }[] = [
137+
{ label: 'UUID', value: 'uuid' },
138+
{ label: 'Name', value: 'name' },
139+
{ label: 'Description', value: 'description' },
140+
{ label: 'References', value: 'references' },
141+
{ label: 'Fields', value: 'fields' },
142+
];
133143

134144
public element: any = {};
135145

@@ -616,6 +626,7 @@ export class SchemaConfigComponent implements OnInit {
616626
category,
617627
topicId: this.currentTopic || '',
618628
search: this.textSearch,
629+
searchOptions: this.textSearchOptionsValue,
619630
pageIndex: this.pageIndex,
620631
pageSize: this.pageSize
621632
});

guardian-service/src/api/schema.service.ts

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
586586
}
587587
const [items, count] = await DatabaseServer.getSchemasAndCount(filter, otherOptions);
588588
const pipeline = [
589-
{$match: filter},
590-
{$group: {_id: '$topicId', count: {$sum: 1}}}
589+
{ $match: filter },
590+
{ $group: { _id: '$topicId', count: { $sum: 1 } } }
591591
] as unknown[];
592592
const countByTopic = await new DataBaseHelper(SchemaCollection).aggregate(pipeline) as unknown[] as { _id: string, count: number }[];
593593
items.forEach((item) => {
@@ -619,6 +619,7 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
619619
toolId?: string,
620620
topicId?: string,
621621
search?: string
622+
searchOptions?: string[]
622623
},
623624
owner: IOwner,
624625
}) => {
@@ -708,36 +709,72 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
708709
//search
709710
if (options.search) {
710711
let search = options.search.toLowerCase();
711-
let global = false;
712-
if (search.startsWith('@')) {
713-
global = true;
712+
if (search.startsWith('@') || search.startsWith('#')) {
714713
search = search.substring(1);
715714
}
715+
const searchOptions = options.searchOptions || ['uuid', 'name', 'description', 'references', 'fields'];
716+
const fields = ['_id'];
717+
if (searchOptions.includes('uuid')) {
718+
fields.push('iri');
719+
}
720+
if (searchOptions.includes('name')) {
721+
fields.push('name');
722+
}
723+
if (searchOptions.includes('description')) {
724+
fields.push('description');
725+
}
726+
if (searchOptions.includes('references') || searchOptions.includes('fields')) {
727+
fields.push('documentFileId');
728+
}
716729
let schemas = await DatabaseServer.getSchemas(filter, {
717730
orderBy: { createDate: 'DESC' },
718731
limit: 10000,
719732
offset: 0,
720-
fields: ['_id', 'documentFileId']
733+
fields
721734
});
722735
schemas = schemas.filter((s) => {
723-
if (s.document) {
724-
if (!global) {
736+
if (searchOptions.includes('uuid')) {
737+
if (s.iri && s.iri.toLowerCase().includes(search)) {
738+
return true;
739+
}
740+
}
741+
if (searchOptions.includes('name')) {
742+
if (s.name && s.name.toLowerCase().includes(search)) {
743+
return true;
744+
}
745+
}
746+
if (searchOptions.includes('description')) {
747+
if (s.description && s.description.toLowerCase().includes(search)) {
748+
return true;
749+
}
750+
}
751+
if (searchOptions.includes('references')) {
752+
if (s.document?.$defs) {
753+
const text = JSON.stringify(s.document.$defs).toLowerCase();
754+
if (text.includes(search)) {
755+
return true;
756+
}
757+
}
758+
}
759+
if (searchOptions.includes('fields')) {
760+
if (s.document) {
725761
delete s.document.$defs;
762+
const text = JSON.stringify(s.document).toLowerCase();
763+
if (text.includes(search)) {
764+
return true;
765+
}
726766
}
727-
const text = JSON.stringify(s.document).toLowerCase();
728-
return text.indexOf(search) > -1;
729-
} else {
730-
return false;
731767
}
768+
return false;
732769
})
733770
const ids = schemas.map((s) => s._id);
734771
filter._id = { $in: ids };
735772
}
736773

737774
const [items, count] = await DatabaseServer.getSchemasAndCount(filter, otherOptions);
738775
const pipeline = [
739-
{$match: filter},
740-
{$group: {_id: '$topicId', count: {$sum: 1}}}
776+
{ $match: filter },
777+
{ $group: { _id: '$topicId', count: { $sum: 1 } } }
741778
] as unknown[];
742779
const countByTopic = await new DataBaseHelper(SchemaCollection).aggregate(pipeline) as unknown[] as { _id: string, count: number }[];
743780
items.forEach((item) => {

swagger.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9325,6 +9325,15 @@ paths:
93259325
schema:
93269326
example: text
93279327
type: string
9328+
- name: searchOptions
9329+
required: false
9330+
in: query
9331+
description: Search Options
9332+
schema:
9333+
example: name
9334+
type: array
9335+
items:
9336+
type: string
93289337
responses:
93299338
'200':
93309339
description: Successful operation.

0 commit comments

Comments
 (0)