Skip to content

Commit

Permalink
Fix initial route path to use base url (#69)
Browse files Browse the repository at this point in the history
* Fix initial route path to use base url

* Fix external links

* Update trigger event name
  • Loading branch information
kshmidt-digma authored Dec 16, 2024
1 parent e52370c commit bbc09d0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/digma-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
push: true

update-digma-ui:
name: Update Jaeger dependencies in Digma UI
name: Update dependencies in Digma UI
needs: [build, attach-release-asset, build-push-docker-image]
runs-on: ubuntu-latest
steps:
Expand All @@ -48,7 +48,7 @@ jobs:
with:
token: ${{ secrets.RELEASE_PAT }}
repository: digma-ai/digma-ui
event-type: update-jaeger
event-type: update-dependencies
client-payload: |-
{
"jaegerUIVersion": "${{ needs.build.outputs.version }}",
Expand Down
14 changes: 9 additions & 5 deletions packages/jaeger-ui/src/components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ export default class JaegerUIApp extends Component {
processScripts();
this.zoomManager = new ZoomManager();
this._handleZoomKeyboardShortcuts = this._handleZoomKeyboardShortcuts.bind(this);
this.state = { isRedirected: false };
}

componentDidMount() {
if (isString(window.initialRoutePath) && window.initialRoutePath) {
const urlToNavigate = prefixUrl(window.initialRoutePath);
history.push(urlToNavigate);
}
this.setState({ isRedirected: true });

document.addEventListener('keydown', this._handleZoomKeyboardShortcuts);
}

Expand All @@ -81,11 +88,8 @@ export default class JaegerUIApp extends Component {
}

render() {
// Navigate to URL provided on app start
if (isString(window.initialRoutePath) && window.initialRoutePath) {
const urlToNavigate = window.initialRoutePath;
window.initialRoutePath = '';
history.push(urlToNavigate);
if (!this.state.isRedirected) {
return null;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import * as React from 'react';
import { Dropdown, Icon, Menu, Button } from 'antd';
import './AltViewOptions.css';
import { Link } from 'react-router-dom';
import {
trackGanttView,
trackGraphView,
Expand All @@ -26,6 +25,7 @@ import {
} from './TracePageHeader.track';
import prefixUrl from '../../../utils/prefix-url';
import { ETraceViewType } from '../types';
import isString from '../../../utils/ts/typeGuards/isString';

type Props = {
onTraceViewChange: (viewType: ETraceViewType) => void;
Expand Down Expand Up @@ -72,7 +72,17 @@ export default function AltViewOptions(props: Props) {
onTraceViewChange(item);
};

const getMenuLinkUrl = (url: string) => window.baseUrl ?? window.apiBaseUrl ?? prefixUrl(url);
const getMenuItemUrl = (path: string): string => {
if (isString(window.baseUrl) && window.baseUrl) {
return `${window.baseUrl}${path}`;
}

if (isString(window.apiBaseUrl) && window.apiBaseUrl) {
return `${window.apiBaseUrl}${path}`;
}

return prefixUrl(path);
};

const menu = (
<Menu>
Expand All @@ -84,24 +94,24 @@ export default function AltViewOptions(props: Props) {
</Menu.Item>
))}
<Menu.Item>
<Link
to={getMenuLinkUrl(`/api/traces/${traceID}?prettyPrint=true`)}
<a
href={getMenuItemUrl(`/api/traces/${traceID}?prettyPrint=true`)}
rel="noopener noreferrer"
target="_blank"
onClick={trackJsonView}
>
Trace JSON
</Link>
</a>
</Menu.Item>
<Menu.Item>
<Link
to={getMenuLinkUrl(`/api/traces/${traceID}?raw=true&prettyPrint=true`)}
<a
href={getMenuItemUrl(`/api/traces/${traceID}?raw=true&prettyPrint=true`)}
rel="noopener noreferrer"
target="_blank"
onClick={trackRawJsonView}
>
Trace JSON (unadjusted)
</Link>
</a>
</Menu.Item>
</Menu>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import ExternalLinks from '../../common/ExternalLinks';
import ZoomControls from './ZoomControls';
import { globalActions } from '../../../api/digma/actions';
import { OpenURLInDefaultBrowserPayload } from '../../../api/digma/types';
import isString from '../../../utils/ts/typeGuards/isString';
import prefixUrl from '../../../utils/prefix-url';

type TracePageHeaderEmbedProps = {
canCollapse: boolean;
Expand Down Expand Up @@ -161,12 +163,25 @@ export function TracePageHeaderFn(props: TracePageHeaderEmbedProps & { forwarded
);

const handleStandaloneLinkClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
const baseUrl = window.baseUrl ?? window.apiBaseUrl;
const getBaseUrl = (): string => {
if (isString(window.baseUrl) && window.baseUrl) {
return window.baseUrl;
}

if (isString(window.apiBaseUrl) && window.apiBaseUrl) {
return window.apiBaseUrl;
}

return prefixUrl('/');
};

const baseUrl: string = getBaseUrl();

e.preventDefault();
window.sendMessageToDigma<OpenURLInDefaultBrowserPayload>({
action: globalActions.OPEN_URL_IN_DEFAULT_BROWSER,
payload: {
url: `${baseUrl}${window.location.pathname}${window.location.search}`,
url: `${baseUrl}/trace/${trace.traceID}${window.location.search}`,
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,24 @@ exports[`AltViewOptions renders correctly 1`] = `
</a>
</MenuItem>
<MenuItem>
<Link
<a
href="/api/traces/test trace ID?prettyPrint=true"
onClick={[MockFunction]}
rel="noopener noreferrer"
replace={false}
target="_blank"
to="/api/traces/test trace ID?prettyPrint=true"
>
Trace JSON
</Link>
</a>
</MenuItem>
<MenuItem>
<Link
<a
href="/api/traces/test trace ID?raw=true&prettyPrint=true"
onClick={[MockFunction]}
rel="noopener noreferrer"
replace={false}
target="_blank"
to="/api/traces/test trace ID?raw=true&prettyPrint=true"
>
Trace JSON (unadjusted)
</Link>
</a>
</MenuItem>
</Menu>
}
Expand Down

0 comments on commit bbc09d0

Please sign in to comment.