Skip to content

Commit

Permalink
feat: add redirection to scenario view button in scenario node
Browse files Browse the repository at this point in the history
  • Loading branch information
nborde-CSM committed Mar 28, 2022
1 parent a84c7af commit 1fc09a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/cards/ScenarioNode/ScenarioNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Cancel as CancelIcon,
ExpandMore as ExpandMoreIcon,
Help as HelpIcon,
OpenInNew as OpenInNewIcon,
} from '@material-ui/icons';
import { DatasetUtils } from '@cosmotech/core';
import { ConfirmDeleteDialog } from './components';
Expand All @@ -31,6 +32,7 @@ export const ScenarioNode = ({
setIsExpanded,
scenario,
showDeleteIcon,
findScenarioById,
deleteScenario,
labels,
buildScenarioNameToDelete,
Expand Down Expand Up @@ -176,6 +178,11 @@ export const ScenarioNode = ({
);
};

const redirectToScenarioView = (event) => {
event.stopPropagation();
findScenarioById(scenario.id);
};

const getAccordionSummary = () => {
return (
<AccordionSummary className={classes.accordionSummary} expandIcon={<ExpandMoreIcon />}>
Expand All @@ -188,9 +195,22 @@ export const ScenarioNode = ({
size="small"
onClick={openConfirmDialog}
>
<DeleteForeverIcon fontSize="small" />
<Tooltip key="scenario-status-tooltip" title={labels.delete}>
<DeleteForeverIcon fontSize="small" />
</Tooltip>
</IconButton>
)}
<IconButton
className={classes.scenarioDeleteButton}
data-cy="scenario-view-redirect"
aria-label="redirect to scenario view"
size="small"
onClick={redirectToScenarioView}
>
<Tooltip key="scenario-status-tooltip" title={labels.redirect}>
<OpenInNewIcon fontSize="small" color="primary" />
</Tooltip>
</IconButton>
</AccordionSummary>
);
};
Expand Down Expand Up @@ -249,7 +269,11 @@ ScenarioNode.propTypes = {
*/
showDeleteIcon: PropTypes.bool.isRequired,
/**
* Function bound on delete button
* Function bound to redirect to scenario view with matching current scenario
*/
findScenarioById: PropTypes.func.isRequired,
/**
* Function bound on delete button
*/
deleteScenario: PropTypes.func.isRequired,
/**
Expand All @@ -262,6 +286,8 @@ ScenarioNode.propTypes = {
successful: 'string',
failed: 'string',
created: 'string'
delete: 'string'
redirect: 'string'
running: 'string',
dataset: 'string',
deleteDialog : {
Expand All @@ -278,6 +304,8 @@ ScenarioNode.propTypes = {
successful: PropTypes.string.isRequired,
failed: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
delete: PropTypes.string.isRequired,
redirect: PropTypes.string.isRequired,
running: PropTypes.string.isRequired,
dataset: PropTypes.string.isRequired,
deleteDialog: PropTypes.shape({
Expand All @@ -301,6 +329,8 @@ ScenarioNode.defaultProps = {
running: 'Running',
failed: 'Failed',
created: 'Created',
delete: 'Delete this scenario',
redirection: 'Redirect to scenario view',
dataset: 'Datasets',
},
};
6 changes: 6 additions & 0 deletions src/charts/ScenarioManagerTreeList/ScenarioManagerTreeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const ScenarioManagerTreeList = (props) => {
const {
datasets,
scenarios,
findScenarioById,
deleteScenario,
moveScenario,
userId,
Expand Down Expand Up @@ -92,6 +93,7 @@ export const ScenarioManagerTreeList = (props) => {
datasets={datasets}
scenario={scenario}
showDeleteIcon={displayDeleteIcon}
findScenarioById={findScenarioById}
deleteScenario={deleteScenario}
labels={labels}
buildScenarioNameToDelete={buildScenarioNameToDelete}
Expand Down Expand Up @@ -239,6 +241,10 @@ ScenarioManagerTreeList.propTypes = {
* Scenarios list
*/
scenarios: PropTypes.array.isRequired,
/**
* Function bound to redirect to scenario view with matching current scenario
*/
findScenarioById: PropTypes.func.isRequired,
/**
* Function bound to handle a scenario deletion
*/
Expand Down

0 comments on commit 1fc09a0

Please sign in to comment.