-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui] Hide Jobs item from nav if there are no jobs
[INTERNAL_BRANCH=dish/hide-jobs-nav-cloud]
- Loading branch information
Showing
6 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
js_modules/dagster-ui/packages/ui-core/src/app/AppTopNav/AppTopNavRightOfLogo.oss.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import {memo} from 'react'; | ||
|
||
import {AppTopNavLinks, navLinks} from './AppTopNavLinks'; | ||
import {useJobStateForNav} from './useJobStateForNav'; | ||
|
||
export const AppTopNavRightOfLogo = memo(() => { | ||
return <AppTopNavLinks links={navLinks()} />; | ||
const jobState = useJobStateForNav(); | ||
return <AppTopNavLinks links={navLinks({jobState})} />; | ||
}); |
26 changes: 26 additions & 0 deletions
26
js_modules/dagster-ui/packages/ui-core/src/app/AppTopNav/useJobStateForNav.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {useMemo} from 'react'; | ||
|
||
import {isHiddenAssetGroupJob} from '../../asset-graph/Utils'; | ||
import {useRepositoryOptions} from '../../workspace/WorkspaceContext'; | ||
|
||
export type JobStateForNav = 'unknown' | 'has-jobs' | 'no-jobs'; | ||
|
||
/** | ||
* Determine whether the viewer has any jobs in any of their code locations. We use | ||
* this information to determine whether to show the "Jobs" item in the top navigation | ||
* at all. If there are no jobs, we won't show it. | ||
*/ | ||
export const useJobStateForNav = () => { | ||
const {options, loading} = useRepositoryOptions(); | ||
return useMemo(() => { | ||
if (loading) { | ||
return 'unknown'; | ||
} | ||
|
||
const hasJobs = options.some((option) => | ||
option.repository.pipelines.some((job) => !isHiddenAssetGroupJob(job.name)), | ||
); | ||
|
||
return hasJobs ? 'has-jobs' : 'no-jobs'; | ||
}, [options, loading]); | ||
}; |
58 changes: 58 additions & 0 deletions
58
js_modules/dagster-ui/packages/ui-core/src/app/__fixtures__/useJobStateForNav.fixtures.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {__ANONYMOUS_ASSET_JOB_PREFIX} from '../../asset-graph/Utils'; | ||
import { | ||
buildPipeline, | ||
buildRepository, | ||
buildRepositoryLocation, | ||
buildWorkspaceLocationEntry, | ||
} from '../../graphql/types'; | ||
import {buildWorkspaceMocks} from '../../workspace/__fixtures__/Workspace.fixtures'; | ||
|
||
export const workspaceWithJob = buildWorkspaceMocks([ | ||
buildWorkspaceLocationEntry({ | ||
name: 'some_workspace', | ||
locationOrLoadError: buildRepositoryLocation({ | ||
name: 'location_with_job', | ||
repositories: [ | ||
buildRepository({ | ||
name: 'repo_with_job', | ||
pipelines: [ | ||
buildPipeline({ | ||
name: 'some_job', | ||
isJob: true, | ||
}), | ||
], | ||
}), | ||
], | ||
}), | ||
}), | ||
]); | ||
|
||
export const workspaceWithNoJobs = buildWorkspaceMocks([ | ||
buildWorkspaceLocationEntry({ | ||
name: 'some_workspace', | ||
locationOrLoadError: buildRepositoryLocation({ | ||
name: 'location_without_job', | ||
repositories: [ | ||
buildRepository({ | ||
name: 'repo_without_job', | ||
pipelines: [], | ||
}), | ||
], | ||
}), | ||
}), | ||
]); | ||
|
||
export const workspaceWithDunderJob = buildWorkspaceMocks([ | ||
buildWorkspaceLocationEntry({ | ||
name: 'some_workspace', | ||
locationOrLoadError: buildRepositoryLocation({ | ||
name: 'location_without_job', | ||
repositories: [ | ||
buildRepository({ | ||
name: `${__ANONYMOUS_ASSET_JOB_PREFIX}_pseudo_job`, | ||
pipelines: [], | ||
}), | ||
], | ||
}), | ||
}), | ||
]); |
62 changes: 62 additions & 0 deletions
62
js_modules/dagster-ui/packages/ui-core/src/app/__tests__/useJobStateForNav.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {MockedProvider} from '@apollo/client/testing'; | ||
import {render, screen} from '@testing-library/react'; | ||
|
||
import {WorkspaceProvider} from '../../workspace/WorkspaceContext'; | ||
import {useJobStateForNav} from '../AppTopNav/useJobStateForNav'; | ||
import { | ||
workspaceWithDunderJob, | ||
workspaceWithJob, | ||
workspaceWithNoJobs, | ||
} from '../__fixtures__/useJobStateForNav.fixtures'; | ||
|
||
describe('useJobStateForNav', () => { | ||
const Test = () => { | ||
const value = useJobStateForNav(); | ||
return <div>{value}</div>; | ||
}; | ||
|
||
it('returns `unknown` if still loading, then finds jobs and returns `has-jobs`', async () => { | ||
render( | ||
<MockedProvider mocks={workspaceWithJob}> | ||
<WorkspaceProvider> | ||
<Test /> | ||
</WorkspaceProvider> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(screen.getByText(/unknown/i)).toBeVisible(); | ||
|
||
const found = await screen.findByText(/has-jobs/i); | ||
expect(found).toBeVisible(); | ||
}); | ||
|
||
it('returns `no-jobs` if no jobs found after loading', async () => { | ||
render( | ||
<MockedProvider mocks={workspaceWithNoJobs}> | ||
<WorkspaceProvider> | ||
<Test /> | ||
</WorkspaceProvider> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(screen.getByText(/unknown/i)).toBeVisible(); | ||
|
||
const found = await screen.findByText(/no-jobs/i); | ||
expect(found).toBeVisible(); | ||
}); | ||
|
||
it('returns `no-jobs` if only dunder job found', async () => { | ||
render( | ||
<MockedProvider mocks={workspaceWithDunderJob}> | ||
<WorkspaceProvider> | ||
<Test /> | ||
</WorkspaceProvider> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(screen.getByText(/unknown/i)).toBeVisible(); | ||
|
||
const found = await screen.findByText(/no-jobs/i); | ||
expect(found).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters