Skip to content

Commit

Permalink
feat: broker can initialize connector endpoint filters from query par…
Browse files Browse the repository at this point in the history
…ams (#683)
  • Loading branch information
kulgg authored Feb 28, 2024
1 parent 47c6382 commit 3a6e6f3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ the detailed section referring to by linking pull requests or issues.

#### Minor

- Broker UI: Added query params for the connector endpoints filter

#### Patch

#### Deployment Migration Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ export const getCatalogPage = (query: CatalogPageQuery): CatalogPageResult => {
{id: '', title: ''},
],
},
{
id: 'connectorEndpoint',
title: 'Connector',
values: [
{
id: 'https://example-connector/api/dsp',
title: 'https://example-connector/api/dsp',
},
{
id: 'https://example-connector2/api/dsp',
title: 'https://example-connector2/api/dsp',
},
],
},
],
},
paginationMetadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, HostBinding, OnDestroy, OnInit} from '@angular/core';
import {FormControl} from '@angular/forms';
import {PageEvent} from '@angular/material/paginator';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {BehaviorSubject, Subject} from 'rxjs';
import {filter, map, takeUntil} from 'rxjs/operators';
import {Store} from '@ngxs/store';
Expand All @@ -14,6 +15,7 @@ import {
} from '../../../../component-library/catalog/view-selection/view-mode-enum';
import {BrokerServerApiService} from '../../../../core/services/api/broker-server-api.service';
import {FilterBoxItem} from '../filter-box/filter-box-item';
import {FilterBoxModel} from '../filter-box/filter-box-model';
import {FilterBoxVisibleState} from '../filter-box/filter-box-visible-state';
import {CatalogActiveFilterPill} from '../state/catalog-active-filter-pill';
import {CatalogPage} from '../state/catalog-page-actions';
Expand Down Expand Up @@ -50,10 +52,13 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
private assetDetailDialogService: AssetDetailDialogService,
private brokerServerApiService: BrokerServerApiService,
private store: Store,
private route: ActivatedRoute,
private router: Router,
) {}

ngOnInit(): void {
this.store.dispatch(CatalogPage.Reset);
this.setConnectorEndpointFiltersFromQueryParamsOnce();
this.startListeningToStore();
this.startEmittingSearchText();
this.startEmittingSortBy();
Expand Down Expand Up @@ -98,6 +103,49 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
});
}

private setConnectorEndpointFiltersFromQueryParamsOnce() {
const connectorEndpoints = this.parseConnectorEndpoints(
this.route.snapshot.queryParams,
);
if (!connectorEndpoints?.length) {
return;
}

this.store.dispatch(
new CatalogPage.AddFilterBox(
this.buildConnectorEndpointFilterBoxModel(connectorEndpoints),
),
);
this.expandedFilterId = 'connectorEndpoint';
// remove query params from url
this.router.navigate([]);
}

private parseConnectorEndpoints(params: Params): string[] {
if (!('connectorEndpoint' in params)) {
return [];
}
const endpoints = params.connectorEndpoint;
return Array.isArray(endpoints) ? [...new Set(endpoints)] : [endpoints];
}

private buildConnectorEndpointFilterBoxModel(
endpoints: string[],
): FilterBoxModel {
const items: FilterBoxItem[] = endpoints.map((x) => ({
type: 'ITEM',
id: x,
label: x,
}));
return {
id: 'connectorEndpoint',
title: 'Connector',
selectedItems: items,
availableItems: items,
searchText: '',
};
}

onDataOfferClick(dataOffer: CatalogDataOfferMapped) {
const data =
this.assetDetailDialogDataService.brokerDataOfferDetails(dataOffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {CatalogPageSortingItem} from '@sovity.de/broker-server-client';
import {FilterBoxItem} from '../filter-box/filter-box-item';
import {FilterBoxModel} from '../filter-box/filter-box-model';
import {CatalogActiveFilterPill} from './catalog-active-filter-pill';

export namespace CatalogPage {
Expand Down Expand Up @@ -35,6 +36,12 @@ export namespace CatalogPage {
constructor(public sorting: CatalogPageSortingItem | null) {}
}

export class AddFilterBox {
static readonly type = `[${tag}] Add Filter Box`;

constructor(public filterBox: FilterBoxModel) {}
}

export class UpdateFilterSelectedItems {
static readonly type = `[${tag}] Update a Filter's selected Items`;

Expand Down
19 changes: 19 additions & 0 deletions src/app/routes/broker-ui/catalog-page/state/catalog-page-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ export class CatalogPageState implements OnDestroy {
ctx.dispatch(CatalogPage.NeedFetch);
}

@Action(CatalogPage.AddFilterBox)
onAddFilterBox(ctx: Ctx, action: CatalogPage.AddFilterBox) {
const state = ctx.getState();
if (action.filterBox.id in state.filters) {
return;
}
ctx.setState(
this._recalculateActiveFilterItems({
...state,
filters: {
...state.filters,
[action.filterBox.id]: FilterBoxVisibleState.buildVisibleState(
action.filterBox,
),
},
}),
);
}

@Action(CatalogPage.UpdateFilterSelectedItems)
onUpdateFilterSelectedItems(
ctx: Ctx,
Expand Down

0 comments on commit 3a6e6f3

Please sign in to comment.