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 { ScheduleWorkflow } from '../../../models/graphql/scheduleData';
|
||||||
import useActions from '../../../redux/actions';
|
import useActions from '../../../redux/actions';
|
||||||
import * as TabActions from '../../../redux/actions/tabs';
|
import * as TabActions from '../../../redux/actions/tabs';
|
||||||
|
import * as WorkflowActions from '../../../redux/actions/workflow';
|
||||||
import { history } from '../../../redux/configureStore';
|
import { history } from '../../../redux/configureStore';
|
||||||
import { ReactComponent as CrossMarkIcon } from '../../../svg/crossmark.svg';
|
import { ReactComponent as CrossMarkIcon } from '../../../svg/crossmark.svg';
|
||||||
import timeDifferenceForDate from '../../../utils/datesModifier';
|
import timeDifferenceForDate from '../../../utils/datesModifier';
|
||||||
|
@ -32,7 +33,6 @@ import { getProjectID, getProjectRole } from '../../../utils/getSearchParams';
|
||||||
import ExperimentPoints from './ExperimentPoints';
|
import ExperimentPoints from './ExperimentPoints';
|
||||||
import SaveTemplateModal from './SaveTemplateModal';
|
import SaveTemplateModal from './SaveTemplateModal';
|
||||||
import useStyles from './styles';
|
import useStyles from './styles';
|
||||||
import * as WorkflowActions from '../../../redux/actions/workflow';
|
|
||||||
|
|
||||||
interface TableDataProps {
|
interface TableDataProps {
|
||||||
data: ScheduleWorkflow;
|
data: ScheduleWorkflow;
|
||||||
|
@ -366,7 +366,7 @@ const TableData: React.FC<TableDataProps> = ({
|
||||||
<MenuItem value="Edit_Schedule" onClick={() => editSchedule()}>
|
<MenuItem value="Edit_Schedule" onClick={() => editSchedule()}>
|
||||||
<div className={classes.expDiv}>
|
<div className={classes.expDiv}>
|
||||||
<img
|
<img
|
||||||
src="./icons/Edit.svg"
|
src="/icons/Edit.svg"
|
||||||
alt="Edit Schedule"
|
alt="Edit Schedule"
|
||||||
className={classes.btnImg}
|
className={classes.btnImg}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -46,7 +46,7 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const workflow = useActions(WorkflowActions);
|
const workflow = useActions(WorkflowActions);
|
||||||
const [experiments, setExperiments] = useState<ChaosCRDTable[]>([]);
|
const [experiments, setExperiments] = useState<ChaosCRDTable[]>([]);
|
||||||
const [revertChaos, setRevertChaos] = useState<boolean>(false);
|
const [revertChaos, setRevertChaos] = useState<boolean>(true);
|
||||||
const [displayStepper, setDisplayStepper] = useState<boolean>(false);
|
const [displayStepper, setDisplayStepper] = useState<boolean>(false);
|
||||||
const [engineIndex, setEngineIndex] = useState<number>(0);
|
const [engineIndex, setEngineIndex] = useState<number>(0);
|
||||||
const manifest = useSelector(
|
const manifest = useSelector(
|
||||||
|
@ -93,9 +93,16 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
||||||
|
|
||||||
// Revert Chaos
|
// Revert Chaos
|
||||||
const toggleRevertChaos = (manifest: string) => {
|
const toggleRevertChaos = (manifest: string) => {
|
||||||
let deleteEngines = 'kubectl delete chaosengine ';
|
|
||||||
const parsedYAML = YAML.parse(manifest);
|
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([
|
parsedYAML.spec.templates[0].steps.push([
|
||||||
{
|
{
|
||||||
name: 'revert-chaos',
|
name: 'revert-chaos',
|
||||||
|
@ -122,6 +129,19 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
||||||
args: [deleteEngines],
|
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({
|
workflow.setWorkflowManifest({
|
||||||
manifest: YAML.stringify(parsedYAML),
|
manifest: YAML.stringify(parsedYAML),
|
||||||
|
@ -152,7 +172,7 @@ const WorkflowTable = forwardRef(({ isCustom }: WorkflowTableProps, ref) => {
|
||||||
if (experiments.length === 0) {
|
if (experiments.length === 0) {
|
||||||
return false; // Should show alert
|
return false; // Should show alert
|
||||||
}
|
}
|
||||||
if (revertChaos === true) toggleRevertChaos(manifest);
|
toggleRevertChaos(manifest);
|
||||||
return true; // Should not show any alert
|
return true; // Should not show any alert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue