Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/38198: "Delayed Submissions" toggle does not toggle off unless backed out for Collect Policy #38215

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,15 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
}

function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency: ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>) {
const policy = ReportUtils.getPolicy(policyID);
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReporting: enabled,
harvesting: {
enabled: true,
enabled,
},
autoReportingFrequency: frequency,
pendingFields: {isAutoApprovalEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
Expand All @@ -456,7 +457,9 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReporting: !enabled,
autoReporting: policy.autoReporting,
harvesting: policy.harvesting,
autoReportingFrequency: policy.autoReportingFrequency,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
autoReporting: policy.autoReporting,
harvesting: policy.harvesting,
autoReportingFrequency: policy.autoReportingFrequency,
autoReporting: policy.autoReporting ?? null,
harvesting: {enabled: policy.harvesting?.enabled ?? null},
autoReportingFrequency: policy.autoReportingFrequency ?? null,
  • When merging we need to be sure we are not merging a undefined value because it's a NOOP. Merging {autoReporting: undefined} is same as not merging at all and the value won't get reverted.
  • For objects we should merge only the values that we did actually change and not the whole object

(Same goes for other fields)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Updating

pendingFields: {isAutoApprovalEnabled: null, harvesting: null},
},
},
Expand All @@ -478,6 +481,8 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
}

function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>) {
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -494,6 +499,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReportingFrequency: policy.autoReportingFrequency,
pendingFields: {autoReportingFrequency: null},
},
},
Expand All @@ -515,6 +521,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf

function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingOffset: number | ValueOf<typeof CONST.POLICY.AUTO_REPORTING_OFFSET>) {
const value = JSON.stringify({autoReportingOffset: autoReportingOffset.toString()});
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -532,6 +539,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReportingOffset: policy.autoReportingOffset,
pendingFields: {autoReportingOffset: null},
},
},
Expand All @@ -553,6 +561,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO

function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMode: ValueOf<typeof CONST.POLICY.APPROVAL_MODE>) {
const isAutoApprovalEnabled = approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC;
const policy = ReportUtils.getPolicy(policyID);

const value = {
approver,
Expand All @@ -576,6 +585,9 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
approver: policy.approver,
approvalMode: policy.approvalMode,
isAutoApprovalEnabled: policy.isAutoApprovalEnabled,
pendingFields: {approvalMode: null},
},
},
Expand Down
Loading