Fixing Revert Chaos + Edit Schedule Icon (#2712)
* Fixing Revert Chaos + Edit Schedule Icon Signed-off-by: Sayan Mondal <sayan@chaosnative.com>
This commit is contained in:
parent
5d2600d5ff
commit
70a04b70f1
|
@ -25,6 +25,7 @@ import { RERUN_CHAOS_WORKFLOW } from '../../../graphql/mutations';
|
|||
import { ScheduleWorkflow } from '../../../models/graphql/scheduleData';
|
||||
import useActions from '../../../redux/actions';
|
||||
import * as TabActions from '../../../redux/actions/tabs';
|
||||
import * as WorkflowActions from '../../../redux/actions/workflow';
|
||||
import { history } from '../../../redux/configureStore';
|
||||
import { ReactComponent as CrossMarkIcon } from '../../../svg/crossmark.svg';
|
||||
import timeDifferenceForDate from '../../../utils/datesModifier';
|
||||
|
@ -32,7 +33,6 @@ import { getProjectID, getProjectRole } from '../../../utils/getSearchParams';
|
|||
import ExperimentPoints from './ExperimentPoints';
|
||||
import SaveTemplateModal from './SaveTemplateModal';
|
||||
import useStyles from './styles';
|
||||
import * as WorkflowActions from '../../../redux/actions/workflow';
|
||||
|
||||
interface TableDataProps {
|
||||
data: ScheduleWorkflow;
|
||||
|
@ -366,7 +366,7 @@ const TableData: React.FC<TableDataProps> = ({
|
|||
<MenuItem value="Edit_Schedule" onClick={() => editSchedule()}>
|
||||
<div className={classes.expDiv}>
|
||||
<img
|
||||
src="./icons/Edit.svg"
|
||||
src="/icons/Edit.svg"
|
||||
alt="Edit Schedule"
|
||||
className={classes.btnImg}
|
||||
/>
|
||||
|
|
|
@ -46,7 +46,7 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
|||
const theme = useTheme();
|
||||
const workflow = useActions(WorkflowActions);
|
||||
const [experiments, setExperiments] = useState<ChaosCRDTable[]>([]);
|
||||
const [revertChaos, setRevertChaos] = useState<boolean>(false);
|
||||
const [revertChaos, setRevertChaos] = useState<boolean>(true);
|
||||
const [displayStepper, setDisplayStepper] = useState<boolean>(false);
|
||||
const [engineIndex, setEngineIndex] = useState<number>(0);
|
||||
const manifest = useSelector(
|
||||
|
@ -93,9 +93,16 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
|||
|
||||
// Revert Chaos
|
||||
const toggleRevertChaos = (manifest: string) => {
|
||||
let deleteEngines = 'kubectl delete chaosengine ';
|
||||
const parsedYAML = YAML.parse(manifest);
|
||||
let deleteEngines = 'kubectl delete chaosengine ';
|
||||
|
||||
// Else if Revert Chaos is set to true and it is not already set in the manifest
|
||||
if (
|
||||
revertChaos &&
|
||||
parsedYAML.spec.templates[0].steps[
|
||||
parsedYAML.spec.templates[0].steps.length - 1
|
||||
][0].name !== 'revert-chaos'
|
||||
) {
|
||||
parsedYAML.spec.templates[0].steps.push([
|
||||
{
|
||||
name: 'revert-chaos',
|
||||
|
@ -122,6 +129,19 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
|||
args: [deleteEngines],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Else if Revert Chaos is set to False and revert chaos template is present in the manifest
|
||||
else if (
|
||||
!revertChaos &&
|
||||
parsedYAML.spec.templates[0].steps[
|
||||
parsedYAML.spec.templates[0].steps.length - 1
|
||||
][0].name === 'revert-chaos'
|
||||
) {
|
||||
parsedYAML.spec.templates[0].steps.pop(); // Remove the last step -> Revert Chaos
|
||||
|
||||
parsedYAML.spec.templates.pop(); // Remove the last template -> Revert Chaos Template
|
||||
}
|
||||
|
||||
workflow.setWorkflowManifest({
|
||||
manifest: YAML.stringify(parsedYAML),
|
||||
|
@ -152,7 +172,7 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
|||
if (experiments.length === 0) {
|
||||
return false; // Should show alert
|
||||
}
|
||||
if (revertChaos === true) toggleRevertChaos(manifest);
|
||||
toggleRevertChaos(manifest);
|
||||
return true; // Should not show any alert
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue