Skip to content

Commit

Permalink
issue #138 Remove redundant "updateSearchParams" calls
Browse files Browse the repository at this point in the history
  • Loading branch information
wajda committed Sep 22, 2021
1 parent 5c62fb0 commit ad06fc9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import {
DynamicTableOptions,
getDefaultDtOptions
} from 'spline-common/dynamic-table'
import { BaseLocalStateComponent, QuerySorter, RouterNavigation, SearchDataSource, SearchQuery, SplineRecord } from 'spline-utils'
import { BaseLocalStateComponent, QuerySorter, RouterNavigation, SearchDataSource, SplineRecord } from 'spline-utils'

import { SplineSearchDynamicTable } from './spline-search-dynamic-table.models'
import SearchParams = SearchQuery.SearchParams


@Component({
Expand Down Expand Up @@ -81,6 +80,7 @@ export class SplineSearchDynamicTableComponent<TRowData = undefined, TFilter ext
takeUntil(this.destroyed$),
filter((event: RouterEvent) => event instanceof NavigationEnd)
).subscribe(() => {
// console.log("ROUTE END: URL search params", this.searchParamsFromUrl())
if (this.searchParamsFromUrl() === null) {
const freshDefaultParams = {
...this.dataSource.defaultSearchParams,
Expand All @@ -105,6 +105,7 @@ export class SplineSearchDynamicTableComponent<TRowData = undefined, TFilter ext
}

// load data
// console.log("NgInit: URL search params", this.searchParamsFromUrl())
this.dataSource.updateSearchParams(this.searchParamsFromUrl() || {})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export class EventsDataSource extends SearchDataSource<ExecutionEvent,
}
]
})

this.updateSearchParams(this.defaultSearchParams)
}

protected getDataObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import { SplineRecord } from '../heplers'
import { PageResponse, QuerySorter } from '../query'

import { SearchQuery } from './search-query.models'
import DataState = SearchQuery.DataState
import DEFAULT_RENDER_DATA = SearchQuery.DEFAULT_RENDER_DATA
import DEFAULT_SEARCH_PARAMS = SearchQuery.DEFAULT_SEARCH_PARAMS
import DEFAULT_SERVER_POLLING_INTERVAL = SearchQuery.DEFAULT_SERVER_POLL_INTERVAL
import SearchParams = SearchQuery.SearchParams
import DataState = SearchQuery.DataState;
import DEFAULT_RENDER_DATA = SearchQuery.DEFAULT_RENDER_DATA;
import DEFAULT_SEARCH_PARAMS = SearchQuery.DEFAULT_SEARCH_PARAMS;
import DEFAULT_SERVER_POLLING_INTERVAL = SearchQuery.DEFAULT_SERVER_POLL_INTERVAL;
import SearchParams = SearchQuery.SearchParams;


export abstract class SearchDataSource<TDataRecord = unknown,
Expand Down Expand Up @@ -105,8 +105,11 @@ export abstract class SearchDataSource<TDataRecord = unknown,
}

setAlwaysOnFilter(filterValue: TFilter): void {
const searchParams = this.withResetPagination({ alwaysOnFilter: filterValue })
this.updateSearchParams(searchParams)
// todo: This filter isn't supposed to be modified. Replace it with the default params preset.
this._searchParams$.next({
...this.searchParams,
...({ alwaysOnFilter: filterValue }),
} as SearchParams<TFilter, TSortableFields>)
}

goToPage(pageIndex: number): void {
Expand Down Expand Up @@ -149,15 +152,15 @@ export abstract class SearchDataSource<TDataRecord = unknown,
}

updateSearchParams(searchParams: Partial<SearchParams<TFilter, TSortableFields>>): void {
// console.log("UPDATE SEARCH PARAMS", searchParams)

const newSearchParams = {
...this.searchParams,
...searchParams,
} as SearchParams<TFilter, TSortableFields>

if (!isEqual(newSearchParams, this.searchParams)) {
this._searchParams$.next(newSearchParams)
this.fetchData(newSearchParams)
}
this._searchParams$.next(newSearchParams)
this.fetchData(newSearchParams)
}

connect(collectionViewer: CollectionViewer): Observable<TDataRecord[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class SplineDataSourcesDataSource extends EventsDataSource {
}
]
})

this.updateSearchParams(this.defaultSearchParams)
}

protected getDataObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class EventLineageListDataSource extends SearchDataSource<ExecutionEventL
}
]
})

this.updateSearchParams(this.defaultSearchParams)
}

protected getDataObserver(
Expand Down

0 comments on commit ad06fc9

Please sign in to comment.