Skip to content

Commit

Permalink
feat: Add possibility to show/hide delete scenario button globally
Browse files Browse the repository at this point in the history
  • Loading branch information
jreynard-code committed Nov 18, 2021
1 parent a7ee838 commit 18df909
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/charts/ScenarioManagerTreeList/ScenarioManagerTreeList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Cosmo Tech.
// Licensed under the MIT license.

import React, { useState, useRef, useMemo, useEffect } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { TextField, Typography } from '@material-ui/core';
import '@nosferatu500/react-sortable-tree/style.css';
Expand All @@ -22,6 +22,7 @@ export const ScenarioManagerTreeList = (props) => {
buildDatasetInfo,
labels,
buildScenarioNameToDelete,
showDeleteIcon,
} = props;

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

function formatScenariosToRSTList(treeScenarios) {
const rstScenarios = treeScenarios.map((scenario) => {
const showDeleteIcon = scenario.ownerId === userId;
const displayDeleteIcon = scenario.ownerId === userId && showDeleteIcon;
labels.dataset = buildDatasetInfo(scenario.datasetList);
return {
expanded: expandedNodes.current[scenario.id] || false,
Expand All @@ -51,7 +52,7 @@ export const ScenarioManagerTreeList = (props) => {
<ScenarioNode
datasets={datasets}
scenario={scenario}
showDeleteIcon={showDeleteIcon}
showDeleteIcon={displayDeleteIcon}
deleteScenario={deleteScenario}
labels={labels}
buildScenarioNameToDelete={buildScenarioNameToDelete}
Expand Down Expand Up @@ -162,6 +163,12 @@ ScenarioManagerTreeList.propTypes = {
* Function building scenario dataset label
*/
buildDatasetInfo: PropTypes.func.isRequired,
/**
* Define ScenarioNode's delete buttons state (no matter who created scenario):
* - true : the button is shown
* - false : the button is hidden
*/
showDeleteIcon: PropTypes.bool,
/**
* Structure
* <pre>
Expand All @@ -183,6 +190,7 @@ ScenarioManagerTreeList.propTypes = {
};

ScenarioManagerTreeList.defaultProps = {
showDeleteIcon: true,
labels: {
status: 'Run status',
successful: 'Successful',
Expand Down

0 comments on commit 18df909

Please sign in to comment.