Skip to content

Commit acda098

Browse files
committed
Fix onboarding/editing bug
1 parent 6b77416 commit acda098

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

UI/web-app/src/components/RunConfiguration/RunConfiguration.base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const RunConfigurationBase: React.FunctionComponent<IRunConfigurationProp
151151
className={classNames.controlWidth}
152152
label={strings.ManageMembership.labels.frequency}
153153
options={frequencyOptions}
154-
defaultSelectedKey={period ? period.toString() : undefined}
154+
defaultSelectedKey={period ? period.toString() : predefinedFrequencyOptions[0].key}
155155
onChange={(event, option) => {
156156
if (option) {
157157
dispatch(setNewJobPeriod(Number(option.key)));

UI/web-app/src/pages/ManageMembership/ManageMembership.base.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import React, { useEffect, useState } from 'react';
4+
import React, { useEffect, useRef, useState } from 'react';
55
import { useDispatch, useSelector } from 'react-redux';
66
import {
77
IProcessedStyleSet,
@@ -85,7 +85,6 @@ export const ManageMembershipBase: React.FunctionComponent<IManageMembershipProp
8585

8686
const dispatch = useDispatch<AppDispatch>();
8787
useEffect(() => {
88-
dispatch(resetManageMembership());
8988
dispatch(setPagingBarVisible(false));
9089
}, [dispatch]);
9190

@@ -99,38 +98,35 @@ export const ManageMembershipBase: React.FunctionComponent<IManageMembershipProp
9998
const isJobWriter = useSelector(selectIsJobWriter)
10099

101100
// Existing job
102-
const jobDetails = useSelector(selectSelectedJobDetails);
101+
const jobDetailsRef = useRef(useSelector(selectSelectedJobDetails));
103102
const isLoading = useSelector(selectSelectedJobLoading);
104103

105104
useEffect(() => {
106-
let editingExistingJob = !!locationState.jobId;
107-
if (editingExistingJob && isJobWriter) {
108-
editingExistingJob = true;
109-
dispatch(setIsEditingExistingJob(editingExistingJob));
110-
}
111-
else {
112-
editingExistingJob = false;
113-
dispatch(setIsEditingExistingJob(editingExistingJob));
105+
let editingExistingJob = !!locationState?.jobId && isJobWriter;
106+
dispatch(setIsEditingExistingJob(editingExistingJob));
107+
108+
if (!editingExistingJob) {
109+
jobDetailsRef.current = undefined;
114110
}
115111

116-
if (locationState.currentStep) {
112+
if (locationState?.currentStep) {
117113
dispatch(setCurrentStep(locationState.currentStep));
118114
}
119115

120-
if (locationState.jobId) {
116+
if (locationState?.jobId) {
121117
dispatch(fetchJobDetails({
122118
syncJobId: locationState.jobId
123119
}));
124120
} else {
125121
dispatch(resetManageMembership());
126122
}
127-
}, [dispatch, locationState]);
123+
}, [dispatch, locationState, isJobWriter]);
128124

129125
useEffect(() => {
130-
if (jobDetails) {
131-
dispatch(setJobDetailsForExistingJob(jobDetails));
126+
if (jobDetailsRef.current) {
127+
dispatch(setJobDetailsForExistingJob(jobDetailsRef.current));
132128
}
133-
}, [dispatch, jobDetails]);
129+
}, [dispatch, jobDetailsRef.current]);
134130

135131
const isAdvancedQueryValid = useSelector(manageMembershipisAdvancedQueryValid);
136132
const allSourcePartsValid = useSelector(areAllSourcePartsValid);

UI/web-app/src/store/manageMembership.slice.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const manageMembershipSlice = createSlice({
239239
state.sourceParts = [];
240240
},
241241
setJobDetailsForExistingJob: (state, action: PayloadAction<JobDetails>) => {
242-
const { source } = action.payload;
242+
const { source, requestor, startDate, period, thresholdPercentageForAdditions, thresholdPercentageForRemovals } = action.payload;
243243
state.advancedViewQuery = JSON.stringify(source);
244244
state.compositeQuery = buildCompositeQuery(JSON.parse(source));
245245
state.sourceParts = JSON.parse(source).map((query: SourcePartQuery, index: number) => ({
@@ -248,11 +248,11 @@ const manageMembershipSlice = createSlice({
248248
query: query,
249249
isValid: true
250250
}));
251-
state.newJob.requestor = action.payload.requestor;
252-
state.newJob.startDate = action.payload.startDate;
253-
state.newJob.period = action.payload.period;
254-
state.newJob.thresholdPercentageForAdditions = action.payload.thresholdPercentageForAdditions;
255-
state.newJob.thresholdPercentageForRemovals = action.payload.thresholdPercentageForRemovals;
251+
state.newJob.requestor = requestor || state.newJob.requestor;
252+
state.newJob.startDate = startDate || state.newJob.startDate;
253+
state.newJob.period = period || state.newJob.period;
254+
state.newJob.thresholdPercentageForAdditions = thresholdPercentageForAdditions || state.newJob.thresholdPercentageForAdditions;
255+
state.newJob.thresholdPercentageForRemovals = thresholdPercentageForRemovals || state.newJob.thresholdPercentageForRemovals;
256256
},
257257
setIsEditingExistingJob: (state, action: PayloadAction<boolean>) => {
258258
state.isEditingExistingJob = action.payload;

0 commit comments

Comments
 (0)