Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer - Fix Retaining of filters on switching between Trace and Span view #1486

Closed
wants to merge 7 commits into from

Conversation

jaywalker21
Copy link
Contributor

Description

Fixes #1250

  • Made the filter-bar component controlled in nature by providing a mechanism for two-way binding.
  • Added logic in explorer component to update the filter values on toggling between span and trace views.

Testing

  • Carried out local testing and seems to be working well so far.

@jaywalker21 jaywalker21 requested a review from a team as a code owner March 15, 2022 19:01
@jaywalker21 jaywalker21 changed the title Fix/explorer tab switch Explorer - Fix Retaining of filters on switching between Trace and Span view Mar 15, 2022
public onContextUpdated(contextWrapper: ExplorerContextScope): void {
this.attributes$ = this.metadataService.getFilterAttributes(contextWrapper.dashboardContext);
const listener = this.attributes$.subscribe(attributes => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try to move this block outside of this method in an independent structure.

@codecov
Copy link

codecov bot commented Mar 15, 2022

Codecov Report

Merging #1486 (b91643d) into main (00b913a) will decrease coverage by 24.94%.
The diff coverage is 33.33%.

@@             Coverage Diff             @@
##             main    #1486       +/-   ##
===========================================
- Coverage   84.04%   59.10%   -24.95%     
===========================================
  Files         858      858               
  Lines       18296    18328       +32     
  Branches     2481     2493       +12     
===========================================
- Hits        15377    10832     -4545     
- Misses       2802     7163     +4361     
- Partials      117      333      +216     
Impacted Files Coverage Δ
...rvability/src/pages/explorer/explorer.component.ts 13.33% <18.18%> (-76.67%) ⬇️
...s/src/filtering/filter-bar/filter-bar.component.ts 57.74% <29.41%> (-8.93%) ⬇️
...nents/src/filtering/filter/parser/parsed-filter.ts 43.58% <100.00%> (-45.30%) ⬇️
projects/components/src/public-api.ts 100.00% <100.00%> (ø)
...ed/components/topology/utils/topology-converter.ts 2.56% <0.00%> (-97.44%) ⬇️
...ponents/radar/layout/radar-chart-layout.service.ts 6.89% <0.00%> (-93.11%) ⬇️
...rtesian/d3/scale/state/cartesian-stacking-state.ts 5.00% <0.00%> (-92.50%) ⬇️
...logy/renderers/tooltip/topology-tooltip-popover.ts 7.50% <0.00%> (-92.50%) ⬇️
.../utils/builders/request/graphql-request-builder.ts 3.48% <0.00%> (-91.87%) ⬇️
.../edge/curved/entity-edge-curve-renderer.service.ts 8.49% <0.00%> (-91.51%) ⬇️
... and 194 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00b913a...b91643d. Read the comment docs.

@@ -327,6 +371,12 @@ interface ExplorerContextScope {
scopeQueryParam: ScopeQueryParam;
}

type contextMap = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PascalCase for type names (also, we generally use interfaces if constructing a brand new type that's not projected from another.

Naming here is also an issue. I think context is an overloaded term, and even knowing the goal of this PR it took me reading the object using this to understand what this was. Maybe something like

type AttributeTranslationDictionary = { [key: string]: string; }

const spanToApiTraceAttributeTranslationDictionary = {...};
const apiTraceToSpanAttributeTranslationDictionary = {...};

public onContextUpdated(contextWrapper: ExplorerContextScope): void {
this.attributes$ = this.metadataService.getFilterAttributes(contextWrapper.dashboardContext);
const listener = this.attributes$.subscribe(attributes => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use a subscription here. Make the filters an observable, and subscribe via async pipe in the template.

const newFilters = this.filters.map(eachFilter => {
// If the given filter has a different name for the selected tab, update the filter value
if (eachFilter.field in contextMapObject[lastTab]) {
const newFilter = this.filterChipService.autocompleteFilters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to do this without the chip service, that's an impl detail from the filter bar. Can we use the filter builder service (I hate how complex we made this!) instead just read the details out of the old one and write them into the new one. May need to lookup the new attribute, too - but we shouldn't have to create it, it's already one of the ones in the array coming in.

this.onFiltersChanged(this.filterBarService.addFilter(this.internalFiltersSubject$.value, filter));
this.onFiltersChanged(
this.filterBarService.addFilter(
isEmpty(this.internalFiltersSubject$.value) ? [] : this.internalFiltersSubject$.value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should never be undefined, so we're just checking if empty and if so assigning empty? did some logic change that forced this? Either this isn't required or we've broken the assigned type.

@@ -175,10 +193,10 @@ export class FilterBarComponent implements OnChanges, OnInit, OnDestroy {
}

private updateFilter(oldFilter: Filter, newFilter: Filter): void {
this.onFiltersChanged(this.filterBarService.updateFilter(this.internalFiltersSubject$.value, oldFilter, newFilter));
this.onFiltersChanged(this.filterBarService.updateFilter(this.filters || [], oldFilter, newFilter));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we use the subject's value and when do we use this.filters? We seem to use different ways in different places which makes it very confusion to understand as a reader.

@anandtiwary anandtiwary closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attribute based drill down should automatically come to Trace or Span tab on explorer as per attribute scope
3 participants