Skip to content

Commit

Permalink
Don't persist empty form data when leaving a form step
Browse files Browse the repository at this point in the history
If the active step form is invalid we will receive no data, so we must
not persist that lest the form blows up on absent values when we later
navigate back.
  • Loading branch information
rylnd committed Sep 1, 2020
1 parent 15c38bb commit 4995e81
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';
import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import isEmpty from 'lodash/isEmpty';

import { useRule, usePersistRule } from '../../../../containers/detection_engine/rules';
import { useListsConfig } from '../../../../containers/detection_engine/lists/use_lists_config';
Expand Down Expand Up @@ -263,7 +264,7 @@ const EditRulePageComponent: FC = () => {
async (tab: EuiTabbedContentTab) => {
const activeStepData = await stepsForm.current[activeStep]?.submit();

if (activeStepData != null) {
if (activeStepData != null && !isEmpty(activeStepData.data)) {
setStepData(activeStep, activeStepData.data, activeStepData.isValid);
}
setInitForm(true);
Expand Down

0 comments on commit 4995e81

Please sign in to comment.