Skip to content

Commit 18df909

Browse files
committed
feat: Add possibility to show/hide delete scenario button globally
1 parent a7ee838 commit 18df909

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/charts/ScenarioManagerTreeList/ScenarioManagerTreeList.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Cosmo Tech.
22
// Licensed under the MIT license.
33

4-
import React, { useState, useRef, useMemo, useEffect } from 'react';
4+
import React, { useEffect, useMemo, useRef, useState } from 'react';
55
import PropTypes from 'prop-types';
66
import { TextField, Typography } from '@material-ui/core';
77
import '@nosferatu500/react-sortable-tree/style.css';
@@ -22,6 +22,7 @@ export const ScenarioManagerTreeList = (props) => {
2222
buildDatasetInfo,
2323
labels,
2424
buildScenarioNameToDelete,
25+
showDeleteIcon,
2526
} = props;
2627

2728
// Memoize the full scenarios tree in a ReactSortableTree-compatible format
@@ -40,7 +41,7 @@ export const ScenarioManagerTreeList = (props) => {
4041

4142
function formatScenariosToRSTList(treeScenarios) {
4243
const rstScenarios = treeScenarios.map((scenario) => {
43-
const showDeleteIcon = scenario.ownerId === userId;
44+
const displayDeleteIcon = scenario.ownerId === userId && showDeleteIcon;
4445
labels.dataset = buildDatasetInfo(scenario.datasetList);
4546
return {
4647
expanded: expandedNodes.current[scenario.id] || false,
@@ -51,7 +52,7 @@ export const ScenarioManagerTreeList = (props) => {
5152
<ScenarioNode
5253
datasets={datasets}
5354
scenario={scenario}
54-
showDeleteIcon={showDeleteIcon}
55+
showDeleteIcon={displayDeleteIcon}
5556
deleteScenario={deleteScenario}
5657
labels={labels}
5758
buildScenarioNameToDelete={buildScenarioNameToDelete}
@@ -162,6 +163,12 @@ ScenarioManagerTreeList.propTypes = {
162163
* Function building scenario dataset label
163164
*/
164165
buildDatasetInfo: PropTypes.func.isRequired,
166+
/**
167+
* Define ScenarioNode's delete buttons state (no matter who created scenario):
168+
* - true : the button is shown
169+
* - false : the button is hidden
170+
*/
171+
showDeleteIcon: PropTypes.bool,
165172
/**
166173
* Structure
167174
* <pre>
@@ -183,6 +190,7 @@ ScenarioManagerTreeList.propTypes = {
183190
};
184191

185192
ScenarioManagerTreeList.defaultProps = {
193+
showDeleteIcon: true,
186194
labels: {
187195
status: 'Run status',
188196
successful: 'Successful',

0 commit comments

Comments
 (0)