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

Add boolean property to config #1521

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { FetchedState, TNil } from '../../../types';
import { ApiError } from '../../../types/api-error';

import './ResultItemTitle.css';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';

type Props = {
duration?: number;
Expand Down Expand Up @@ -80,7 +81,7 @@ export default class ResultItemTitle extends React.PureComponent<Props> {
wrapperProps.to = linkTo;
WrapperComponent = Link;
if (targetBlank) {
wrapperProps.target = '_blank';
wrapperProps.target = getTargetEmptyOrBlank();
wrapperProps.rel = 'noopener noreferrer';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { SearchQuery } from '../../../types/search';
import { KeyValuePair, Trace, TraceData } from '../../../types/trace';

import './index.css';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';

type SearchResultsProps = {
cohortAddTrace: (traceId: string) => void;
Expand Down Expand Up @@ -200,7 +201,7 @@ export class UnconnectedSearchResults extends React.PureComponent<SearchResultsP
<Link
className="u-tx-inherit ub-nowrap ub-ml3"
to={searchUrl}
target="_blank"
target={getTargetEmptyOrBlank()}
rel="noopener noreferrer"
>
<NewWindowIcon isLarge />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as React from 'react';

import { getUrl } from '../../TracePage/url';
import NewWindowIcon from '../../common/NewWindowIcon';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';

type PropsType = {
traceID: string;
Expand All @@ -27,7 +28,12 @@ function stopPropagation(event: React.MouseEvent<HTMLAnchorElement>) {

export default function TraceTimelineLink({ traceID }: PropsType) {
return (
<a href={getUrl(traceID)} onClick={stopPropagation} rel="noopener noreferrer" target="_blank">
<a
href={getUrl(traceID)}
onClick={stopPropagation}
rel="noopener noreferrer"
target={getTargetEmptyOrBlank()}
>
<NewWindowIcon />
</a>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from './TracePageHeader.track';
import prefixUrl from '../../../utils/prefix-url';
import { ETraceViewType } from '../types';
import { getTargetBlankOrTop } from '../../../utils/config/get-target';

type Props = {
onTraceViewChange: (viewType: ETraceViewType) => void;
Expand Down Expand Up @@ -88,7 +89,7 @@ export default function AltViewOptions(props: Props) {
<Link
to={prefixUrl(`/api/traces/${traceID}?prettyPrint=true`)}
rel="noopener noreferrer"
target="_blank"
target={getTargetBlankOrTop()}
Copy link
Member

Choose a reason for hiding this comment

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

why did you not think EmptyOrBlank would work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that when the target is empty, the json will be shown in the same window and the user cannot return to the page before (at least on the instrument because it has no keyboard or possibility to reach a return button from the browser). This is why I decided to use top: when the target is top the user can still access the navigation bar and go back.

onClick={trackJsonView}
>
Trace JSON
Expand All @@ -100,7 +101,7 @@ export default function AltViewOptions(props: Props) {
<Link
to={prefixUrl(`/api/traces/${traceID}?raw=true&prettyPrint=true`)}
rel="noopener noreferrer"
target="_blank"
target={getTargetBlankOrTop()}
onClick={trackRawJsonView}
>
Trace JSON (unadjusted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { getTraceLinks } from '../../../model/link-patterns';

import './TracePageHeader.css';
import ExternalLinks from '../../common/ExternalLinks';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';

type TracePageHeaderEmbedProps = {
canCollapse: boolean;
Expand Down Expand Up @@ -210,7 +211,7 @@ export function TracePageHeaderFn(props: TracePageHeaderEmbedProps & { forwarded
<Link
className="u-tx-inherit ub-nowrap ub-mx2"
to={linkToStandalone}
target="_blank"
target={getTargetEmptyOrBlank()}
rel="noopener noreferrer"
>
<NewWindowIcon isLarge />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TNil } from '../../../types';
import { Trace, Span } from '../../../types/trace';
import { timeConversion } from '../../../utils/date';
import prefixUrl from '../../../utils/prefix-url';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';

const Option = Select.Option;

Expand Down Expand Up @@ -149,7 +150,7 @@ export default class TraceSpanView extends Component<Props, State> {
return (
<a
href={prefixUrl(`/trace/${record.traceID}?uiFind=${text}`)}
target="_blank"
target={getTargetEmptyOrBlank()}
rel="noopener noreferrer"
>
{text}
Expand Down
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/constants/default-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const defaultConfig: Config = {
},
disableFileUploadControl: false,
disableJsonView: false,
forbidNewPage: false,
traceGraph: {
layoutManagerMemory: undefined,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/jaeger-ui/src/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export type Config = {
// Disables the json view.
disableJsonView: boolean;

// Alters all targets of links to empty or top to
// prevent the creation of a new page.
forbidNewPage: boolean;

// The following features are experimental / undocumented.

deepDependencies?: {
Expand Down
45 changes: 45 additions & 0 deletions packages/jaeger-ui/src/utils/config/get-target.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023 The Jaeger Authors
//
// 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 * as getConfig from './get-config';
import { getTargetBlankOrTop, getTargetEmptyOrBlank } from './get-target';

let getConfigValueSpy;

beforeAll(() => {
getConfigValueSpy = jest.spyOn(getConfig, 'getConfigValue');
});

describe('getTarget', () => {
it('getTargetEmptyOrBlank returns empty because forbidNewPage is true', () => {
getConfigValueSpy.mockReturnValue(true);
const target = getTargetEmptyOrBlank();
expect(target).toBe('');
});
it('getTargetEmptyOrBlank returns _blank because forbidNewPage is true', () => {
getConfigValueSpy.mockReturnValue(false);
const target = getTargetEmptyOrBlank();
expect(target).toBe('_blank');
});
it('getTargetBlankOrTop returns _top because forbidNewPage is true', () => {
getConfigValueSpy.mockReturnValue(true);
const target = getTargetBlankOrTop();
expect(target).toBe('_top');
});
it('getTargetBlankOrTop returns _blank because forbidNewPage is true', () => {
getConfigValueSpy.mockReturnValue(false);
const target = getTargetBlankOrTop();
expect(target).toBe('_blank');
});
});
23 changes: 23 additions & 0 deletions packages/jaeger-ui/src/utils/config/get-target.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2023 The Jaeger Authors
//
// 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 { getConfigValue } from './get-config';

export function getTargetEmptyOrBlank() {
return getConfigValue('forbidNewPage') ? '' : '_blank';
}

export function getTargetBlankOrTop() {
return getConfigValue('forbidNewPage') ? '_top' : '_blank';
}