Skip to content

Commit

Permalink
[ui] Fix base path when opening a new window (#25909)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Preserve the base path when opening a new tab for "Open in Launchpad" on
a schedule/sensor dry run.

I created a hook to wrap extraction of the base path and using `_blank`
as the target. I see a few places where we're using `window.open`
without applying the base path, so in a followup I'll go through and
clean those up too.

## How I Tested These Changes

Open a schedule, click "Test schedule", choose a tick. Click "Open in
Launchpad", verify that the new tab opens with a URL that includes the
base path (deployment) prefix.

## Changelog

[ui] Fix "Open in Playground" link when testing a schedule or sensor by
ensuring that it opens to the correct deployment.
  • Loading branch information
hellendag authored and gibsondan committed Nov 14, 2024
1 parent 77f3859 commit cece8a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {useContext} from 'react';

import {AppContext} from '../app/AppContext';

// Open a path in a new tab. Incorporates the base path to ensure that
// the link opens to the appropriate deployment.
export const useOpenInNewTab = () => {
const {basePath} = useContext(AppContext);
return (path: string) => {
window.open(`${basePath}${path}`, '_blank');
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Box, Button, Colors, Icon, Table, Tag} from '@dagster-io/ui-components';

import {applyCreateSession, useExecutionSessionStorage} from '../app/ExecutionSessionStorage';
import {RunRequestFragment} from './types/RunRequestFragment.types';
import {useOpenInNewTab} from '../hooks/useOpenInNewTab';
import {PipelineReference} from '../pipelines/PipelineReference';
import {testId} from '../testing/testId';
import {useRepository} from '../workspace/WorkspaceContext/util';
Expand Down Expand Up @@ -94,6 +95,7 @@ function OpenInLaunchpadButton({
repoAddress: RepoAddress;
isJob: boolean;
}) {
const openInNewTab = useOpenInNewTab();
const pipelineName = request.jobName ?? jobName;
const [_, onSave] = useExecutionSessionStorage(repoAddress, pipelineName!);

Expand All @@ -111,12 +113,12 @@ function OpenInLaunchpadButton({
})),
}),
);
window.open(

openInNewTab(
workspacePathFromAddress(
repoAddress,
`/${isJob ? 'jobs' : 'pipelines'}/${pipelineName}/playground`,
),
'_blank',
);
}}
>
Expand Down

0 comments on commit cece8a3

Please sign in to comment.