-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow cloning of running executions (#93)
* feat: add clone functionality for running executions * fix: updating deprecated method in test
- Loading branch information
Showing
8 changed files
with
298 additions
and
20 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
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
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 |
---|---|---|
|
@@ -16,3 +16,7 @@ export const tabs = { | |
label: 'Graph' | ||
} | ||
}; | ||
|
||
export const executionActionStrings = { | ||
clone: 'Clone Execution' | ||
}; |
98 changes: 98 additions & 0 deletions
98
src/components/Executions/ExecutionDetails/test/ExecutionDetailsAppBarContent.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,98 @@ | ||
import { | ||
fireEvent, | ||
render, | ||
RenderResult, | ||
waitFor | ||
} from '@testing-library/react'; | ||
import { labels as commonLabels } from 'components/common/constants'; | ||
import { | ||
ExecutionContext, | ||
ExecutionContextData | ||
} from 'components/Executions/contexts'; | ||
import { Execution } from 'models'; | ||
import { createMockExecution } from 'models/__mocks__/executionsData'; | ||
import { WorkflowExecutionPhase } from 'models/Execution/enums'; | ||
import * as React from 'react'; | ||
import { MemoryRouter } from 'react-router'; | ||
import { delayedPromise, DelayedPromiseResult } from 'test/utils'; | ||
import { executionActionStrings } from '../constants'; | ||
import { ExecutionDetailsAppBarContent } from '../ExecutionDetailsAppBarContent'; | ||
|
||
jest.mock('components/Navigation/NavBarContent', () => ({ | ||
NavBarContent: ({ children }: React.Props<any>) => children | ||
})); | ||
|
||
describe('ExecutionDetailsAppBarContent', () => { | ||
let execution: Execution; | ||
let executionContext: ExecutionContextData; | ||
let mockTerminateExecution: jest.Mock<Promise<void>>; | ||
let terminatePromise: DelayedPromiseResult<void>; | ||
|
||
beforeEach(() => { | ||
execution = createMockExecution(); | ||
mockTerminateExecution = jest.fn().mockImplementation(() => { | ||
terminatePromise = delayedPromise(); | ||
return terminatePromise; | ||
}); | ||
executionContext = { | ||
execution, | ||
terminateExecution: mockTerminateExecution | ||
}; | ||
}); | ||
|
||
const renderContent = () => | ||
render( | ||
<MemoryRouter> | ||
<ExecutionContext.Provider value={executionContext}> | ||
<ExecutionDetailsAppBarContent execution={execution} /> | ||
</ExecutionContext.Provider> | ||
</MemoryRouter> | ||
); | ||
|
||
describe('for running executions', () => { | ||
beforeEach(() => { | ||
execution.closure.phase = WorkflowExecutionPhase.RUNNING; | ||
}); | ||
|
||
it('renders an overflow menu', async () => { | ||
const { getByLabelText } = renderContent(); | ||
await waitFor(() => getByLabelText(commonLabels.moreOptionsButton)); | ||
}); | ||
|
||
describe('in overflow menu', () => { | ||
let renderResult: RenderResult; | ||
let buttonEl: HTMLElement; | ||
let menuEl: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
renderResult = renderContent(); | ||
const { getByLabelText } = renderResult; | ||
buttonEl = await waitFor(() => | ||
getByLabelText(commonLabels.moreOptionsButton) | ||
); | ||
fireEvent.click(buttonEl); | ||
menuEl = await waitFor(() => | ||
getByLabelText(commonLabels.moreOptionsMenu) | ||
); | ||
}); | ||
|
||
it('renders a clone option', () => { | ||
const { getByText } = renderResult; | ||
expect( | ||
getByText(executionActionStrings.clone) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('for terminal executions', () => { | ||
beforeEach(() => { | ||
execution.closure.phase = WorkflowExecutionPhase.SUCCEEDED; | ||
}); | ||
|
||
it('does not render an overflow menu', async () => { | ||
const { queryByLabelText } = renderContent(); | ||
expect(queryByLabelText(commonLabels.moreOptionsButton)).toBeNull(); | ||
}); | ||
}); | ||
}); |
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,79 @@ | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Menu from '@material-ui/core/Menu'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import MoreVert from '@material-ui/icons/MoreVert'; | ||
import * as React from 'react'; | ||
import { labels } from './constants'; | ||
|
||
export interface MoreOptionsMenuItem { | ||
label: string; | ||
onClick: () => void; | ||
} | ||
|
||
export interface MoreOptionsMenuProps { | ||
className?: string; | ||
options: MoreOptionsMenuItem[]; | ||
} | ||
/** Renders a vertical three-dots menu button with the provided options. | ||
* Each option should have a label and corresponding onClick handler, which will | ||
* be invoked when the item is clicked. | ||
*/ | ||
export const MoreOptionsMenu: React.FC<MoreOptionsMenuProps> = ({ | ||
className, | ||
options | ||
}) => { | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
const { | ||
handleClose, | ||
handleClickMenuButton, | ||
listItems | ||
} = React.useMemo(() => { | ||
const handleClickMenuButton = ( | ||
event: React.MouseEvent<HTMLButtonElement> | ||
) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const listItems = options.map(({ label, onClick: handleItemClick }) => { | ||
const onClick = () => { | ||
setAnchorEl(null); | ||
handleItemClick(); | ||
}; | ||
|
||
return ( | ||
<MenuItem key={label} onClick={onClick}> | ||
{label} | ||
</MenuItem> | ||
); | ||
}); | ||
|
||
return { handleClickMenuButton, handleClose, listItems }; | ||
}, [options, setAnchorEl]); | ||
|
||
return ( | ||
<div className={className}> | ||
<IconButton | ||
aria-controls="more-options-menu" | ||
aria-haspopup="true" | ||
aria-label={labels.moreOptionsButton} | ||
color="inherit" | ||
onClick={handleClickMenuButton} | ||
> | ||
<MoreVert /> | ||
</IconButton> | ||
<Menu | ||
aria-label={labels.moreOptionsMenu} | ||
id="more-options-menu" | ||
anchorEl={anchorEl} | ||
open={!!anchorEl} | ||
onClose={handleClose} | ||
> | ||
{listItems} | ||
</Menu> | ||
</div> | ||
); | ||
}; |
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 +1,6 @@ | ||
export const detailsPanelWidth = 432; | ||
|
||
export const labels = { | ||
moreOptionsButton: 'Display more options', | ||
moreOptionsMenu: 'More options menu' | ||
}; |
Oops, something went wrong.