-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat: disable categories/tags/distance rates when feature is disabled #43637
Changes from 5 commits
9dec198
e851a7d
c44cbc3
970bf98
3383933
d92bbdb
0bbe021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,48 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { | |
], | ||
}; | ||
|
||
if (!enabled) { | ||
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
const customUnitID = Object.keys(policy?.customUnits ?? {})[0]; | ||
const customUnit = customUnitID ? policy?.customUnits?.[customUnitID] : undefined; | ||
|
||
const rateEntries = Object.entries(customUnit?.rates ?? {}); | ||
// find the rate to be enabled after disabling the distance rate feature | ||
// first check the default rate | ||
let rateEntryToBeEnabled = rateEntries.find((rate) => rate[1]?.name === 'Default Rate'); | ||
// if the default rate is not enabled/doesn't exist, we'll switch to the first enabled rate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dominictb noticed one case,
I think we need to make sure that we re-enable the first distance rate, even if it was previously disabled. Screen.Recording.2024-06-18.at.1.35.24.in.the.afternoon.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @getusha lemme check and update. Give me some time, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. web-8MB.mp4Fixed |
||
if (!rateEntryToBeEnabled?.[1] || !rateEntryToBeEnabled[1].enabled) { | ||
rateEntryToBeEnabled = rateEntries.find((rate) => !!rate[1]?.enabled); | ||
} | ||
// if no rate is enabled, we'll switch to the first rate | ||
if (!rateEntryToBeEnabled?.[1]) { | ||
rateEntryToBeEnabled = rateEntries[0]; | ||
} | ||
|
||
onyxData.optimisticData?.push({ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
customUnits: { | ||
[customUnitID]: { | ||
rates: Object.fromEntries( | ||
rateEntries.map((rateEntry) => { | ||
const [rateID, rate] = rateEntry; | ||
return [ | ||
rateID, | ||
{ | ||
...rate, | ||
enabled: rateID === rateEntryToBeEnabled[0], | ||
}, | ||
]; | ||
}), | ||
), | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
const parameters: EnablePolicyDistanceRatesParams = {policyID, enabled}; | ||
|
||
API.write(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB