Skip to content

Commit

Permalink
feature #177 Create component search with custom filter tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
korel-san committed Feb 16, 2023
1 parent e0a727e commit b3c06d6
Show file tree
Hide file tree
Showing 41 changed files with 1,078 additions and 334 deletions.
2 changes: 2 additions & 0 deletions ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
]
},
"localhost": {
"sourceMap": true,
"optimization": false,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
*/

import { HttpParams } from '@angular/common/http'
import { DEFAULT_PAGE_LIMIT, PageQueryParams, QueryPager, QuerySorter, SearchQuery } from 'spline-utils'
import {
DEFAULT_PAGE_LIMIT,
LabelPageQueryParams,
LabelValuesPageQueryParams,
PageQueryParams,
QueryPager,
QuerySorter,
SearchQuery
} from 'spline-utils'

import { DataSourceWriteMode } from '../data-source'

Expand All @@ -28,6 +36,7 @@ export namespace ExecutionEventsQuery {
executedAtFrom?: Date
executedAtTo?: Date
searchTerm?: string
label?: string[]
dataSourceUri?: string
asAtTime?: number
applicationId?: string
Expand All @@ -42,6 +51,7 @@ export namespace ExecutionEventsQuery {
sortOrder?: string
sortField?: string
searchTerm?: string
label?: string[]
pageSize?: number
pageNum?: number
dataSourceUri?: string
Expand All @@ -58,7 +68,8 @@ export namespace ExecutionEventsQuery {
}
}

export function queryParamsDtoToHttpParams(queryParamsDto: QueryParamsDto): HttpParams {
// eslint-disable-next-line max-len
export function queryParamsDtoToHttpParams(queryParamsDto: QueryParamsDto | LabelPageQueryParams | LabelValuesPageQueryParams): HttpParams {
let httpParams = new HttpParams()
Object.keys(queryParamsDto)
.filter(key => queryParamsDto[key] !== undefined)
Expand All @@ -68,6 +79,10 @@ export namespace ExecutionEventsQuery {
return httpParams
}

export function labelQueryParamsToHttpParams(queryParams: LabelPageQueryParams | LabelValuesPageQueryParams): HttpParams {
return queryParamsDtoToHttpParams(queryParams)
}

export function queryParamsToHttpParams(queryParams: QueryParams): HttpParams {
const queryParamsDto = toQueryParamsDto(queryParams)
return queryParamsDtoToHttpParams(queryParamsDto)
Expand All @@ -88,6 +103,17 @@ export namespace ExecutionEventsQuery {
}
}

export function toLabelQueryParams(
searchString: string, labelName?: string
): LabelPageQueryParams | LabelValuesPageQueryParams {
return {
length: -1,
offset: 0,
search: searchString,
labelName
}
}

function parseDate(value = undefined) {
if (typeof value === 'number') {
return value
Expand All @@ -108,6 +134,7 @@ export namespace ExecutionEventsQuery {
timestampStart: parseDate(queryFilter.executedAtFrom),
timestampEnd: parseDate(queryFilter.executedAtTo),
searchTerm: queryFilter?.searchTerm?.length ? queryFilter?.searchTerm : undefined,
label: queryFilter?.label?.length ? queryFilter?.label : undefined,
dataSourceUri: queryFilter?.dataSourceUri,
asAtTime: queryFilter?.asAtTime,
applicationId: queryFilter?.applicationId,
Expand Down
16 changes: 10 additions & 6 deletions ui/projects/spline-api/src/lib/execution-event/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
* limitations under the License.
*/

import { AttributeApiService } from './attribute-api.service'
import { ExecutionEventApiService } from './execution-event-api.service'
import { ExecutionPlanApiService } from './execution-plan-api.service'
import { SplineDataSourceApiService } from './spline-data-source-api.service'
import {
AttributeApiService,
ExecutionEventApiService,
ExecutionPlanApiService,
LabelApiService,
SplineDataSourceApiService
} from 'spline-api'


export const executionEventServices: any[] = [
export const commonServiceProvider: any[] = [
ExecutionEventApiService,
ExecutionPlanApiService,
AttributeApiService,
SplineDataSourceApiService
SplineDataSourceApiService,
LabelApiService
]

export * from './public-api'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2023 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { HttpClient, HttpErrorResponse } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { Observable, throwError } from 'rxjs'
import { catchError } from 'rxjs/operators'
import { LabelPageQueryParams, LabelValuesPageQueryParams } from 'spline-utils'

import { ExecutionEventsQuery } from '../models'

import { BaseApiService } from './base-api.service'


@Injectable()
export class LabelApiService extends BaseApiService {

constructor(protected readonly http: HttpClient) {
super(http)
}

fetchList(queryParams: LabelPageQueryParams | LabelValuesPageQueryParams): Observable<string[]> {
// Adapter LabelQuery to LabelHttpParams
const params = ExecutionEventsQuery.labelQueryParamsToHttpParams(queryParams)
const url = this.getConsumerApiResourceURL(`labels/names${ ('labelName' in queryParams) && queryParams.labelName
? `/${ queryParams.labelName }/values`
: '' }`)
return this.http.get<string[]>(url, { params: params })
.pipe(
catchError((error: HttpErrorResponse) => {
console.error(error)
return throwError(error)
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './base-api.service'
export * from './execution-event-api.service'
export * from './spline-data-source-api.service'
export * from './execution-plan-api.service'
export * from './label-api.service'
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { SplineApiCoreModule } from '../core'

import * as fromServices from './services'


// TODO: Rename this module, due to not correspondent content to name convention
@NgModule({
providers: [
...fromServices.executionEventServices,
...fromServices.commonServiceProvider
],
imports: [
SplineApiCoreModule,
SplineApiCoreModule
],
exports: [],
exports: []
})
export class SplineApiExecutionEventModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DfControlSelect } from '../../models'


@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'df-control-select',
templateUrl: './df-control-select.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
Expand All @@ -44,18 +45,19 @@ export class DfControlSelectComponent<TId extends keyof any = any>

this.stringValues$ = this.model.value$
.pipe(
takeUntil(this.destroyed$),
map(value => {
map((value: string[]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value?.length
? (value as any[])
.map(
item => this.model.options.dataMap?.valueToString
? this.model.options.dataMap.valueToString(item)
: item
)
? value.map(
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
(item: any) => this.model.options.dataMap?.valueToString
? this.model.options.dataMap.valueToString(item)
: item
)
: [this.model.options?.valueLabelAllSelected ?? this.defaultValueLabelAllSelected]

}),
takeUntil(this.destroyed$)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ export * from './date-range-filter/public-api'
export * from './inline-fitler/public-api'
export * from './virtual-scroll/public-api'
export * from './list-box/public-api'
export * from './search-box-with-filter/spline-search-box-with-filter.module'
export * from './search-box-with-filter/spline-search-box-with-filter.component'
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2023 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const labelNames = [
'Alabama',
'Alaska',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
'Delaware',
'Florida',
'Georgia',
'Hawaii',
'Idaho',
'Illinois',
'Indiana',
'Iowa',
'Kansas',
'Kentucky',
'Louisiana',
'Maine',
'Maryland',
'Massachusetts',
'Michigan',
'Minnesota',
'Mississippi',
'Missouri',
'Montana',
'Nebraska',
'Nevada',
'New Hampshire',
'New Jersey',
'New Mexico',
'New York',
'North Dakota',
'North Carolina',
'Ohio',
'Oklahoma',
'Oregon',
'Pennsylvania',
'Rhode Island',
'South Carolina',
'South Dakota',
'Tennessee',
'Texas',
'Utah',
'Vermont',
'Virginia',
'Washington',
'West Virginia',
'Wisconsin',
'Wyoming'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
~ Copyright 2023 ABSA Group Limited
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<mat-autocomplete showPanel="true">
<!-- If we're loading -->
<mat-option disabled class="loading" *ngIf="loading$ | async">
<mat-spinner diameter="35"></mat-spinner>
</mat-option>
<!-- If we're not loading AND the array length is 0, show this -->
<mat-option disabled *ngIf="(loading$ | async) === false && (results$ | async)?.length === 0">
No labels found
</mat-option>
<!-- Actual payload -->
<ng-container *ngIf="(loading$ | async) === false">
<mat-option *ngFor="let labelItem of (results$ | async)">
{{ labelItem }}
</mat-option>
</ng-container>
</mat-autocomplete>
Loading

0 comments on commit b3c06d6

Please sign in to comment.