Skip to content

Conversation

alok-traceable
Copy link
Contributor

Description

  • Creating component Open In a new tab which basically wraps link component and icon component.
  • Adding support of query params in External URL navigator.
  • Adding utility to convert string dictionary to URL query param string and vice versa.

Testing

  • Unit test cases

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented May 18, 2021

Codecov Report

Merging #856 (b856073) into main (cadf4b6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #856   +/-   ##
=======================================
  Coverage   85.36%   85.36%           
=======================================
  Files         799      799           
  Lines       16428    16434    +6     
  Branches     2062     2064    +2     
=======================================
+ Hits        14023    14029    +6     
  Misses       2373     2373           
  Partials       32       32           
Impacted Files Coverage Δ
...ojects/common/src/navigation/navigation.service.ts 93.10% <100.00%> (+0.72%) ⬆️
...s/src/open-in-new-tab/open-in-new-tab.component.ts 100.00% <100.00%> (ø)
...ents/src/open-in-new-tab/open-in-new-tab.module.ts 100.00% <100.00%> (ø)

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 cadf4b6...b856073. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

const timeRange = this.getCurrentTimeRange();
const fixedTimeRange: FixedTimeRange = TimeRangeService.toFixedTimeRange(timeRange.startTime, timeRange.endTime);
const newTimeRangeParam = `${TimeRangeService.TIME_RANGE_QUERY_PARAM}=${fixedTimeRange.toUrlString()}`;

return this.navigationService.getAbsoluteCurrentUrl().replace(timeRangeParam, newTimeRangeParam);
}

public getTimeRangeParams(): Dictionary<string> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the time range param to generate the new tab URL

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

</div>
`
})
export class OpenInNewTabComponent {
@Input()
public size?: ButtonSize = ButtonSize.Small;
public paramsOrUrl?: ExternalNavigationParamsNew | string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still have the same default behavior of the current url?

@@ -80,11 +82,16 @@ export class NavigationService {

if (params.navType === NavigationParamsType.External) {
// External
const queryParamString = getQueryParamStringFromObject(params.queryParams ?? {});
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to let angular do any url building for us (such as url tree). This would break if we passed it a a url that contained query params, since it wouldn't merge. Say http://website.com?param1=value and a second param via query params { param2=value }, we'd get http://website.com?param1=value?param2=value instead of http://website.com?param1=value&param2=value.

I think you can combine router.parseUrl, router.serializeUrl and maybe router.createUrlTree to get all the right behavior here.

const timeRange = this.getCurrentTimeRange();
const fixedTimeRange: FixedTimeRange = TimeRangeService.toFixedTimeRange(timeRange.startTime, timeRange.endTime);
const newTimeRangeParam = `${TimeRangeService.TIME_RANGE_QUERY_PARAM}=${fixedTimeRange.toUrlString()}`;

return this.navigationService.getAbsoluteCurrentUrl().replace(timeRangeParam, newTimeRangeParam);
}

public getTimeRangeParams(): Params {
Copy link
Contributor

Choose a reason for hiding this comment

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

So the fuller picture is coming together here for me - I'm guessing this was left public to later use as query params in an open in new tab case that should maintain the time range, and that's also why queryParams handling was added in nav service. The problem here is we do not want callers to be concerned about this. Time range is not the only global param that needs to be preserved, and we don't want callers to even have to be aware of global params by design.

My suggestion would be to

  • revert the changes here (or at least make this method private)
  • update NavigationService.buildNavigationParams to use buildQueryParam for relative external urls, similar to what we do in navigateWithinApp
  • remove queryParams from ExternalNavigationParamsNew - it's never used today and shouldn't be for this use case, so no reason to build logic for it

</div>
`
})
export class OpenInNewTabComponent {
@Input()
public size?: ButtonSize = ButtonSize.Small;
public paramsOrUrl?: ExternalNavigationParamsNew | string;
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Because this component is named as OpenInNewTab, i feel it should be able to take bothInApp and External params or a url and build a local External Param object. This would mean that no matter what url or params you pass, this component would always open it in a new tab. I think we can build the local param inside ngOnchanges with reasonable defaults for missing properties.
  • Could we please rename ExternalNavigationParamsNew to ExternalNavigationParams ?

Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts? cc @aaron-steinfeld

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with the rename - how did that even get in?!

Also, yes - I think ideally the open in new tab component should be able to support and convert inApp params to external ones, but I personally don't feel it needs to hold up this PR, since we can add it later with fully backwards compatible support as it's a union type already.

Copy link
Contributor

Choose a reason for hiding this comment

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

I missed it when i was migrating to the new interface. But you approved the PR, so....

Copy link
Contributor

@anandtiwary anandtiwary May 19, 2021

Choose a reason for hiding this comment

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

Sure we can make #1 change separately

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld left a comment

Choose a reason for hiding this comment

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

lgtm other than those two leftovers

@@ -73,6 +73,22 @@ export class NavigationService {
return this.currentParamMap.getAll(parameterName);
}

public constructExternalUrl(urlString: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks! looks good - with these changes, do we still need the changes in time range service or the new url util?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, I already reverted those changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, the TR ones are gone - one of the url utils looks like it's still there being unused though

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

import { HttpParams } from '@angular/common/http';
import { Params } from '@angular/router';

export const getQueryParamStringFromObject = (params: Params): string =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed or should we use the below function directly?

Copy link
Contributor Author

@alok-traceable alok-traceable May 24, 2021

Choose a reason for hiding this comment

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

Okay I will remove this function as it is not being used anywhere, but It is better to have a separate function like this, firstly consumers didn't have to write a new instance of HttpParams every time, and secondly if later we want to standardize queryParams key-value pair we need to change this function only.

@github-actions

This comment has been minimized.

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld left a comment

Choose a reason for hiding this comment

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

@github-actions

This comment has been minimized.

@alok-traceable alok-traceable merged commit 682e80c into main May 25, 2021
@alok-traceable alok-traceable deleted the open_in_new_tab branch May 25, 2021 02:23
@github-actions
Copy link

Unit Test Results

    4 files  ±0  254 suites  ±0   15m 28s ⏱️ +17s
916 tests +2  916 ✔️ +2  0 💤 ±0  0 ❌ ±0 
922 runs  +2  922 ✔️ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 682e80c. ± Comparison against base commit cadf4b6.

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.

4 participants