Skip to content

Commit

Permalink
Fixed Transform job create flow where indices won't reset after chang…
Browse files Browse the repository at this point in the history
…e of datasource (#1053)

Signed-off-by: Prabhat Sharma <[email protected]>
Co-authored-by: Prabhat Sharma <[email protected]>
  • Loading branch information
CaptainDredge and Prabhat Sharma authored May 1, 2024
1 parent 43b9e1e commit 9d64b46
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import CreateRollupSteps from "../../components/CreateRollupSteps";
import IndexService from "../../../../services/IndexService";
import { IndexItem } from "../../../../../models/interfaces";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface CreateRollupProps extends RouteComponentProps, DataSourceMenuProperties {
rollupService: RollupService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,52 +89,54 @@ export class CreateTransformForm extends Component<CreateTransformFormProps, Cre
static contextType = CoreServicesContext;
_isMount: boolean;

static baseState = {
currentStep: 1,
transformSeqNo: null,
transformPrimaryTerm: null,
transformId: "",
transformIdError: "",
submitError: "",
isSubmitting: false,
hasSubmitted: false,
loadingIndices: true,
indices: [],
totalIndices: 0,
previewTransform: [],

mappings: "",
allMappings: [],
fields: [],
fieldSelectedOption: "",
selectedFields: [],
selectedGroupField: [],
selectedAggregations: {},
aggList: [],
description: "",

sourceIndex: [],
sourceIndexError: "",
sourceIndexFilter: "",
sourceIndexFilterError: "",
targetIndex: [],
targetIndexError: "",

intervalError: "",

jobEnabledByDefault: true,
continuousJob: "no",
interval: 1,
intervalTimeunit: "MINUTES",
pageSize: 1000,
transformJSON: JSON.parse(EMPTY_TRANSFORM),

beenWarned: false,
isLoading: false,
};

constructor(props: CreateTransformFormProps) {
super(props);

this.state = {
currentStep: 1,
transformSeqNo: null,
transformPrimaryTerm: null,
transformId: "",
transformIdError: "",
submitError: "",
isSubmitting: false,
hasSubmitted: false,
loadingIndices: true,
indices: [],
totalIndices: 0,
previewTransform: [],

mappings: "",
allMappings: [],
fields: [],
fieldSelectedOption: "",
selectedFields: [],
selectedGroupField: [],
selectedAggregations: {},
aggList: [],
description: "",

sourceIndex: [],
sourceIndexError: "",
sourceIndexFilter: "",
sourceIndexFilterError: "",
targetIndex: [],
targetIndexError: "",

intervalError: "",

jobEnabledByDefault: true,
continuousJob: "no",
interval: 1,
intervalTimeunit: "MINUTES",
pageSize: 1000,
transformJSON: JSON.parse(EMPTY_TRANSFORM),

beenWarned: false,
isLoading: false,
};
this.state = CreateTransformForm.baseState;
this._next = this._next.bind(this);
this._prev = this._prev.bind(this);
this._isMount = true;
Expand All @@ -144,6 +146,17 @@ export class CreateTransformForm extends Component<CreateTransformFormProps, Cre
this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.TRANSFORMS, BREADCRUMBS.CREATE_TRANSFORM]);
};

componentDidUpdate(prevProps: CreateTransformFormProps, prevState: Readonly<CreateTransformFormState>) {
if (prevProps.dataSourceId !== this.props.dataSourceId) {
// reset the state, if dataSourceId changes, i.e., clear state
this.setState({
...CreateTransformForm.baseState,
transformId: this.state.transformId,
description: this.state.description,
});
}
}

componentWillUnmount() {
this._isMount = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import TransformIndices from "../../components/TransformIndices";
import CreateTransformSteps from "../../components/CreateTransformSteps";
import IndexService from "../../../../services/IndexService";
import { FieldItem, IndexItem } from "../../../../../models/interfaces";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";

interface SetUpIndicesStepProps extends RouteComponentProps {
interface SetUpIndicesStepProps extends RouteComponentProps, DataSourceMenuProperties {
transformService: TransformService;
indexService: IndexService;
transformId: string;
Expand Down Expand Up @@ -59,7 +60,7 @@ export default class SetUpIndicesStep extends Component<SetUpIndicesStepProps> {
<EuiSpacer />
<ConfigureTransform isEdit={false} {...this.props} />
<EuiSpacer />
<TransformIndices {...this.props} />
<TransformIndices key={this.props.dataSourceId} {...this.props} />
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
Expand Down

0 comments on commit 9d64b46

Please sign in to comment.