-
Notifications
You must be signed in to change notification settings - Fork 40
feat(openchoreo): show Events and Spec tabs for rendered releases #665
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
Open
UdaraWickramarathne
wants to merge
3
commits into
openchoreo:main
Choose a base branch
from
UdaraWickramarathne:feat/3443-rendered-release-events-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b0b680a
feat(openchoreo): show Events and Spec tabs for rendered releases
UdaraWickramarathne 9369c8a
docs(openchoreo): add changeset for rendered release events and spec …
UdaraWickramarathne c0c9cca
feat(openchoreo): surface target plane on rendered release detail tabs
UdaraWickramarathne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@openchoreo/backstage-plugin': minor | ||
| --- | ||
|
|
||
| Show **Events** and **Spec** tabs on the release details page when a rendered release is selected in the resource tree. The Events tab surfaces release-level Kubernetes events (reusing the existing events table and API endpoint), and the Spec tab renders the full rendered release spec as YAML. |
122 changes: 122 additions & 0 deletions
122
...c/components/Environments/ReleaseDataRenderer/ResourceTreeView/ReleaseDetailTabs.test.tsx
This file contains hidden or 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,122 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { ReleaseDetailTabs } from './ReleaseDetailTabs'; | ||
| import type { LayoutNode } from './treeTypes'; | ||
|
|
||
| // Mock design-system YamlViewer | ||
| jest.mock('@openchoreo/backstage-design-system', () => ({ | ||
| YamlViewer: ({ value }: { value: string }) => ( | ||
| <pre data-testid="yaml-viewer">{value}</pre> | ||
| ), | ||
| })); | ||
|
|
||
| // Mock the events table to isolate the tab container logic | ||
| jest.mock('./ResourceEventsTable', () => ({ | ||
| ResourceEventsTable: ({ | ||
| node, | ||
| refreshKey, | ||
| }: { | ||
| node: { name: string }; | ||
| refreshKey?: number; | ||
| }) => ( | ||
| <div data-testid="resource-events-table"> | ||
| {node.name}:{refreshKey ?? 0} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| function makeReleaseNode(overrides: Partial<LayoutNode> = {}): LayoutNode { | ||
| return { | ||
| id: '__release__my-release', | ||
| kind: 'RenderedRelease', | ||
| name: 'my-release', | ||
| group: 'openchoreo.dev', | ||
| version: 'v1alpha1', | ||
| targetPlane: 'dataplane', | ||
| parentIds: ['__release_binding__'], | ||
| specObject: { | ||
| apiVersion: 'openchoreo.dev/v1alpha1', | ||
| kind: 'RenderedRelease', | ||
| }, | ||
| x: 0, | ||
| y: 0, | ||
| width: 200, | ||
| height: 50, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('ReleaseDetailTabs', () => { | ||
| const defaultProps = { | ||
| namespaceName: 'default-ns', | ||
| releaseBindingName: 'rb-name', | ||
| }; | ||
|
|
||
| it('shows the events table on the default (Events) tab', () => { | ||
| render(<ReleaseDetailTabs {...defaultProps} node={makeReleaseNode()} />); | ||
|
|
||
| expect(screen.getByTestId('resource-events-table')).toHaveTextContent( | ||
| 'my-release:0', | ||
| ); | ||
| expect(screen.queryByTestId('yaml-viewer')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the release spec as YAML on the Spec tab', async () => { | ||
| render(<ReleaseDetailTabs {...defaultProps} node={makeReleaseNode()} />); | ||
|
|
||
| await userEvent.click(screen.getByRole('tab', { name: 'Spec' })); | ||
|
|
||
| const viewer = screen.getByTestId('yaml-viewer'); | ||
| expect(viewer).toHaveTextContent('kind: RenderedRelease'); | ||
| expect( | ||
| screen.queryByTestId('resource-events-table'), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows an empty state on the Spec tab when no spec is available', async () => { | ||
| render( | ||
| <ReleaseDetailTabs | ||
| {...defaultProps} | ||
| node={makeReleaseNode({ specObject: undefined })} | ||
| />, | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('tab', { name: 'Spec' })); | ||
|
|
||
| expect(screen.getByText('No release spec available')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('yaml-viewer')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('surfaces the target plane as a chip when present', () => { | ||
| render(<ReleaseDetailTabs {...defaultProps} node={makeReleaseNode()} />); | ||
|
|
||
| expect(screen.getByText('Target: dataplane')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('omits the target plane chip when the node has none', () => { | ||
| render( | ||
| <ReleaseDetailTabs | ||
| {...defaultProps} | ||
| node={makeReleaseNode({ targetPlane: undefined })} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.queryByText(/^Target:/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('bumps the events refresh key when the refresh button is clicked', async () => { | ||
| render(<ReleaseDetailTabs {...defaultProps} node={makeReleaseNode()} />); | ||
|
|
||
| expect(screen.getByTestId('resource-events-table')).toHaveTextContent( | ||
| 'my-release:0', | ||
| ); | ||
|
|
||
| // The only role="button" in the Events tab is the refresh icon button | ||
| // (tabs use role="tab"). | ||
| await userEvent.click(screen.getByRole('button')); | ||
|
|
||
| expect(screen.getByTestId('resource-events-table')).toHaveTextContent( | ||
| 'my-release:1', | ||
| ); | ||
| }); | ||
| }); |
115 changes: 115 additions & 0 deletions
115
...eo/src/components/Environments/ReleaseDataRenderer/ResourceTreeView/ReleaseDetailTabs.tsx
This file contains hidden or 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,115 @@ | ||
| import { useState, useEffect, useCallback, type FC } from 'react'; | ||
| import { | ||
| Box, | ||
| Tabs, | ||
| Tab, | ||
| Typography, | ||
| IconButton, | ||
| Tooltip, | ||
| Chip, | ||
| } from '@material-ui/core'; | ||
| import RefreshIcon from '@material-ui/icons/Refresh'; | ||
| import YAML from 'yaml'; | ||
| import { YamlViewer } from '@openchoreo/backstage-design-system'; | ||
| import { useTreeStyles } from './treeStyles'; | ||
| import { ResourceEventsTable } from './ResourceEventsTable'; | ||
| import type { LayoutNode } from './treeTypes'; | ||
|
|
||
| const TABS = [ | ||
| { id: 'events', label: 'Events' }, | ||
| { id: 'spec', label: 'Spec' }, | ||
| ] as const; | ||
|
|
||
| interface ReleaseDetailTabsProps { | ||
| node: LayoutNode; | ||
| namespaceName: string; | ||
| releaseBindingName: string; | ||
| } | ||
|
|
||
| /** | ||
| * Detail tabs shown when a rendered release node is selected in the resource | ||
| * tree. Surfaces the release's own Kubernetes events and full spec (YAML), | ||
| * reusing the same components used for individual resources. | ||
| */ | ||
| export const ReleaseDetailTabs: FC<ReleaseDetailTabsProps> = ({ | ||
| node, | ||
| namespaceName, | ||
| releaseBindingName, | ||
| }) => { | ||
| const classes = useTreeStyles(); | ||
| const [activeTab, setActiveTab] = useState(0); | ||
| const [refreshKey, setRefreshKey] = useState(0); | ||
|
|
||
| // Reset tab when switching to a different node | ||
| useEffect(() => { | ||
| setActiveTab(0); | ||
| }, [node.id]); | ||
|
|
||
| const currentTab = TABS[activeTab]?.id; | ||
|
|
||
| const handleRefresh = useCallback(() => { | ||
| setRefreshKey(prev => prev + 1); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| <Box display="flex" alignItems="center"> | ||
| <Tabs | ||
| value={activeTab} | ||
| onChange={(_, newValue) => setActiveTab(newValue)} | ||
| indicatorColor="primary" | ||
| textColor="primary" | ||
| className={classes.drawerTabs} | ||
| style={{ flex: 1 }} | ||
| > | ||
| {TABS.map(tab => ( | ||
| <Tab key={tab.id} label={tab.label} /> | ||
| ))} | ||
| </Tabs> | ||
| {node.targetPlane && ( | ||
| <Chip | ||
| label={`Target: ${node.targetPlane}`} | ||
| size="small" | ||
| variant="outlined" | ||
| style={{ marginRight: 8 }} | ||
| /> | ||
| )} | ||
| {currentTab === 'events' && ( | ||
| <Tooltip title="Refresh"> | ||
| <IconButton size="small" onClick={handleRefresh}> | ||
| <RefreshIcon fontSize="small" /> | ||
| </IconButton> | ||
| </Tooltip> | ||
| )} | ||
| </Box> | ||
|
|
||
| <Box className={classes.drawerTabContent}> | ||
| {currentTab === 'events' && ( | ||
| <ResourceEventsTable | ||
| node={node} | ||
| namespaceName={namespaceName} | ||
| releaseBindingName={releaseBindingName} | ||
| refreshKey={refreshKey} | ||
| /> | ||
| )} | ||
|
|
||
| {currentTab === 'spec' && ( | ||
| <> | ||
| {node.specObject ? ( | ||
| <YamlViewer | ||
| value={YAML.stringify(node.specObject)} | ||
| maxHeight="auto" | ||
| /> | ||
| ) : ( | ||
| <Box className={classes.drawerEmptyState}> | ||
| <Typography variant="body2" color="textSecondary"> | ||
| No release spec available | ||
| </Typography> | ||
| </Box> | ||
| )} | ||
| </> | ||
| )} | ||
| </Box> | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
...rc/components/Environments/ReleaseDataRenderer/ResourceTreeView/ResourceTreeNode.test.tsx
This file contains hidden or 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,53 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ResourceTreeNode } from './ResourceTreeNode'; | ||
| import type { LayoutNode } from './treeTypes'; | ||
|
|
||
| function makeNode(overrides: Partial<LayoutNode> = {}): LayoutNode { | ||
| return { | ||
| id: 'node-1', | ||
| kind: 'RenderedRelease', | ||
| name: 'my-release', | ||
| targetPlane: 'dataplane', | ||
| parentIds: [], | ||
| x: 0, | ||
| y: 0, | ||
| width: 200, | ||
| height: 50, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('ResourceTreeNode', () => { | ||
| const defaultProps = { | ||
| isSelected: false, | ||
| onClick: jest.fn(), | ||
| }; | ||
|
|
||
| it('shows the target plane subtitle for a RenderedRelease node', () => { | ||
| render(<ResourceTreeNode {...defaultProps} node={makeNode()} />); | ||
|
|
||
| expect(screen.getByText('Target plane: dataplane')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('omits the target plane subtitle when targetPlane is absent', () => { | ||
| render( | ||
| <ResourceTreeNode | ||
| {...defaultProps} | ||
| node={makeNode({ targetPlane: undefined })} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.queryByText(/^Target plane:/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not show the target plane subtitle for non-release kinds', () => { | ||
| render( | ||
| <ResourceTreeNode | ||
| {...defaultProps} | ||
| node={makeNode({ kind: 'Deployment' })} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.queryByText(/^Target plane:/)).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.