-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[$250] Taxes - "1 selected" dropdown is not dismissed after the selected rate is deleted #54485
Comments
Triggered auto assignment to @robertjchen ( |
💬 A slack conversation has been started in #expensify-open-source |
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
|
Job added to Upwork: https://www.upwork.com/jobs/~021871350917212703788 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mollfpr ( |
Edited by proposal-police: This proposal was edited at 2024-12-24 00:36:36 UTC. ProposalPlease re-state the problem that we are trying to solve in this issue.In Step 7, "1 selected" dropdown remains when there is no more selected rate What is the root cause of that problem?We are not updating App/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx Lines 49 to 54 in a088878
What changes do you think we should make in order to solve the problem?We should clear useEffect(() => {
if(!policy?.taxRates?.taxes){
return;
}
setSelectedTaxesIDs([]);
}, [policy?.taxRates?.taxes]) Notes: this bug also occurs in other pages, we should fix this too in this issue OR: We can check that What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?What alternative solutions did you explore? (Optional)Or we can use the function App/src/components/SelectionListWithModal/index.tsx Lines 94 to 101 in a088878
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
denkoy Your proposal will be dismissed because you did not follow the proposal template. |
ProposalPlease re-state the problem that we are trying to solve in this issue.Taxes - "1 selected" dropdown is not dismissed after the selected rate is deleted What is the root cause of that problem?
What changes do you think we should make in order to solve the problem?
const useCleanupSelectedOptions = (cleanupFunction?: () => void, originalListLength?: number) => {
const navigationContainerRef = useContext(NavigationContainerRefContext);
const state = navigationContainerRef?.getState();
const lastRoute = state?.routes.at(-1);
const isRightModalOpening = lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR;
const prevListLength = usePrevious(originalListLength);
const isFocused = useIsFocused();
useEffect(() => {
if ((isFocused || isRightModalOpening) && prevListLength === originalListLength) {
return;
}
cleanupFunction?.();
}, [isFocused, cleanupFunction, isRightModalOpening, originalListLength, prevListLength]);
};
const cleanupSelectedOption = useCallback(() => setSelectedTaxesIDs([]), []);
useCleanupSelectedOptions(cleanupSelectedOption, Object.keys(policy?.taxRates?.taxes ?? {}).length);
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?What alternative solutions did you explore? (Optional) |
lopezjorge Your proposal will be dismissed because you did not follow the proposal template. |
ProposalPlease re-state the problem that we are trying to solve in this issue"1 selected" dropdown is not dismissed after the selected rate is deleted from RHP. What is the root cause of that problem?In The issue is that when we delete individually selected tax rate by clicking on one rate, this opens RHP What changes do you think we should make in order to solve the problem?PR #53519 introduced a new hook In useCleanupSelectedOptions(cleanupSelectedOption, Object.keys(policy?.taxRates?.taxes ?? {}).length); modify the ...
import usePrevious from '@hooks/usePrevious'; // <- add import
const useCleanupSelectedOptions = (cleanupFunction?: () => void, initialSelectedLength?: number) => { // <- pass 2nd argument / type
// ...
const previousSelectedLength = usePrevious(initialSelectedLength);
const hasDeletedOption = !!initialSelectedLength && previousSelectedLength !== initialSelectedLength;
// ...
useEffect(() => {
if ((isFocused || isRightModalOpening) && !hasDeletedOption) { // <- add the new variable check, wrapping the first two
return;
}
cleanupFunction?.();
}, [isFocused, cleanupFunction, isRightModalOpening, hasDeletedOption]);
}; Explanation Change (1.) passes the argument needed to implement the fix logic. Changes (2.) are using the new passed argument (if existent) and ensures the Result video (before / after)MacOS: Chrome
|
ProposalPlease re-state the problem that we are trying to solve in this issue.The "selected" button doesn't disappear when the selected item is deleted. What is the root cause of that problem?This happens after #53519. Before the PR, when we select a tax (or category, etc.) and then press the item to open the RHP settings, the selection will be removed. But this was changed on the PR to make sure they are persisted. However, currently, the pages (tax, category, etc.) don't have a logic to update the selected item when the item is removed outside from the page list itself, in this case from the individual tax RHP settings. This issue could also happen if we delete the item from another client. So, this isn't a regression but an existing lack of functionality on those pages. What changes do you think we should make in order to solve the problem?We can have a new effect that updates the selected item whenever the list is updated. For example, on the categories page, we can do it like this:
It iterates over the selected item, and checks if the item still exists in the policy categories. If it still exists, then we keep it on the selected items. We need to apply this to tax, tag, and category pages. What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?We can render each of the pages, perform a press event to select one item, and then manually merge the onyx to remove the item from the onyx. Then, verify if the "n selected" button still shows or not. |
This issue is unrelated to my PR. It is a known problem that I previously reported here. I’ve already provided a general solution for it in the same thread here and later shared a more detailed proposal here. @mollfpr, could you please review my proposal? Thanks! You can check the timestamps of my proposal to confirm the chronological order of my proposal. cc @MonilBhavsar Since you are internal of the original issue. |
Reviewing 👀 @truph01 Please post your proposal here and I'll review it like everyone else. |
Re-post the proposal ProposalPlease re-state the problem that we are trying to solve in this issue.
What is the root cause of that problem?
App/src/libs/actions/Policy/Category.ts Line 589 in 8b7096f
This results in a scenario where, when a user selects category A and subsequently updates it to B, the workspace A is no longer marked as selected.
What changes do you think we should make in order to solve the problem?
import {useEffect} from 'react';
import type {PolicyCategories} from '@src/types/onyx';
const useAutoUpdateSelectedOptions = (
listItem: PolicyCategories,
selectedOptions: Record<string, boolean>,
setSelectedOptions: React.Dispatch<React.SetStateAction<Record<string, boolean>>>,
) => {
useEffect(() => {
const availableOptions = Object.values(listItem ?? {})
.filter((o) => o.pendingAction !== 'delete')
.map((o) => o.name);
const originalSelectedOptions = Object.keys(selectedOptions);
const newSelectedOptions = originalSelectedOptions.filter((o) => availableOptions.includes(o));
setSelectedOptions(
newSelectedOptions.reduce((acc, key) => {
acc[key] = true;
return acc;
}, {}),
);
}, [listItem]);
};
export default useAutoUpdateSelectedOptions;
useAutoUpdateSelectedOptions(policyCategories ?? {}, selectedCategories, setSelectedCategories);
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
What alternative solutions did you explore? (Optional) |
Thank you guys for the proposal! @daledah @Krishna2323 @ikevin127 Three of you reset the selected item on every change to the list items, while it should be only to remove the deleted item from the selection and keep the remaining selection. @bernhardoj @truph01 Your solution has the correct result, but thinking the effect is the same for other components and the use case is pretty much the same, I think it's better we create a hook for it. So I will go with the proposal from @truph01. 🎀 👀 🎀 C+ reviewed! |
Current assignee @robertjchen is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new. |
Thanks for the proposals and review- agreed with moving forward with @truph01 's proposal 👍 |
📣 @truph01 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app! Offer link |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.0.78-0
Reproducible in staging?: Y
Reproducible in production?: N
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team
Component Workspace Settings
Action Performed:
Expected Result:
In Step 7, "1 selected" dropdown should be dismissed because there is no more selected rate
Actual Result:
In Step 7, "1 selected" dropdown remains when there is no more selected rate
In Step 9, console error shows up when trying to delete no rate
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
Bug6701530_1734995738401.20241224_064741.mp4
logs (2).txt
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @mollfprThe text was updated successfully, but these errors were encountered: