Skip to content

Commit

Permalink
Preserve selection when navigating to item->details page
Browse files Browse the repository at this point in the history
  • Loading branch information
ChavdaSachin committed Sep 26, 2024
1 parent b930641 commit a4ec3c0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson

const [invitedEmailsToAccountIDsDraft] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`);
const {selectionMode} = useMobileSelectionMode();
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);
const [session] = useOnyx(ONYXKEYS.SESSION);
const selectionListRef = useRef<SelectionListHandle>(null);
const isFocused = useIsFocused();
Expand Down Expand Up @@ -144,10 +145,11 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson

// useFocus would make getWorkspaceMembers get called twice on fresh login because policyEmployee is a dependency of getWorkspaceMembers.
useEffect(() => {
if (!isFocused) {
setSelectedEmployees([]);
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedEmployees([]);
getWorkspaceMembers();
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isFocused]);
Expand Down Expand Up @@ -570,6 +572,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
icon: Expensicons.Table,
text: translate('spreadsheet.importSpreadsheet'),
onSelected: () => {
setShouldPreserveSelection(true);
if (isOffline) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
Expand Down Expand Up @@ -674,7 +677,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
disableKeyboardShortcuts={removeMembersConfirmModalVisible}
headerMessage={getHeaderMessage()}
headerContent={!shouldUseNarrowLayout && getHeaderContent()}
onSelectRow={openMemberDetails}
onSelectRow={(item) => {selectionMode?.isEnabled ? (!item.isDisabledCheckbox && toggleUser(item?.accountID)):(setShouldPreserveSelection(true),openMemberDetails(item))}}
shouldSingleExecuteRowSelect={!isPolicyAdmin}
onCheckboxPress={(item) => toggleUser(item.accountID)}
onSelectAll={() => toggleAllUsers(data)}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
const backTo = route.params?.backTo;
const policy = usePolicy(policyId);
const {selectionMode} = useMobileSelectionMode();
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`);
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy);
Expand All @@ -91,7 +92,8 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
);

useEffect(() => {
if (isFocused) {
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedCategories({});
Expand Down Expand Up @@ -308,6 +310,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
icon: Expensicons.Table,
text: translate('spreadsheet.importSpreadsheet'),
onSelected: () => {
setShouldPreserveSelection(true);
if (isOffline) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
Expand Down Expand Up @@ -409,7 +412,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
onTurnOnSelectionMode={(item) => item && toggleCategory(item)}
sections={[{data: categoryList, isDisabled: false}]}
onCheckboxPress={toggleCategory}
onSelectRow={navigateToCategorySettings}
onSelectRow={(item) => {selectionMode?.isEnabled ? toggleCategory(item): (setShouldPreserveSelection(true),navigateToCategorySettings(item))}}
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()}
onSelectAll={toggleAllCategories}
ListItem={TableListItem}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function PolicyDistanceRatesPage({
const isFocused = useIsFocused();
const policy = usePolicy(policyID);
const {selectionMode} = useMobileSelectionMode();
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);

const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true;

Expand Down Expand Up @@ -93,7 +94,8 @@ function PolicyDistanceRatesPage({
);

useEffect(() => {
if (isFocused) {
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedDistanceRates([]);
Expand Down Expand Up @@ -322,7 +324,7 @@ function PolicyDistanceRatesPage({
onTurnOnSelectionMode={(item) => item && toggleRate(item)}
sections={[{data: distanceRatesList, isDisabled: false}]}
onCheckboxPress={toggleRate}
onSelectRow={openRateDetails}
onSelectRow={(item) => {selectionMode?.isEnabled ? toggleRate(item):(setShouldPreserveSelection(true),openRateDetails(item))}}
onSelectAll={toggleAllRates}
onDismissError={dismissError}
ListItem={TableListItem}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function WorkspaceReportFieldsPage({
return Object.fromEntries(Object.entries(policy.fieldList).filter(([_, value]) => value.fieldID !== 'text_title'));
}, [policy]);
const [selectedReportFields, setSelectedReportFields] = useState<PolicyReportField[]>([]);
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);
const [deleteReportFieldsConfirmModalVisible, setDeleteReportFieldsConfirmModalVisible] = useState(false);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
Expand All @@ -92,7 +93,8 @@ function WorkspaceReportFieldsPage({
useFocusEffect(fetchReportFields);

useEffect(() => {
if (isFocused) {
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedReportFields([]);
Expand Down Expand Up @@ -304,7 +306,7 @@ function WorkspaceReportFieldsPage({
onTurnOnSelectionMode={(item) => item && updateSelectedReportFields(item)}
sections={reportFieldsSections}
onCheckboxPress={updateSelectedReportFields}
onSelectRow={navigateToReportFieldsSettings}
onSelectRow={(item) => {selectionMode?.isEnabled ? updateSelectedReportFields(item):(setShouldPreserveSelection(true),navigateToReportFieldsSettings(item))}}
onSelectAll={toggleAllReportFields}
ListItem={TableListItem}
customListHeader={getCustomListHeader()}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const policy = usePolicy(policyID);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
const {selectionMode} = useMobileSelectionMode();
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);
const {environmentURL} = useEnvironment();
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy);
Expand All @@ -80,7 +81,8 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
useFocusEffect(fetchTags);

useEffect(() => {
if (isFocused) {
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedTags({});
Expand Down Expand Up @@ -300,6 +302,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
icon: Expensicons.Table,
text: translate('spreadsheet.importSpreadsheet'),
onSelected: () => {
setShouldPreserveSelection(true);
if (isOffline) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
Expand Down Expand Up @@ -420,7 +423,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
onTurnOnSelectionMode={(item) => item && toggleTag(item)}
sections={[{data: tagList, isDisabled: false}]}
onCheckboxPress={toggleTag}
onSelectRow={navigateToTagSettings}
onSelectRow={(item) => {selectionMode?.isEnabled ? toggleTag(item): (setShouldPreserveSelection(true),navigateToTagSettings(item))}}
shouldSingleExecuteRowSelect={!canSelectMultiple}
onSelectAll={toggleAllTags}
ListItem={TableListItem}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/taxes/WorkspaceTaxesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function WorkspaceTaxesPage({
const [selectedTaxesIDs, setSelectedTaxesIDs] = useState<string[]>([]);
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const {selectionMode} = useMobileSelectionMode();
const [shouldPreserveSelection, setShouldPreserveSelection] = useState(false);
const defaultExternalID = policy?.taxRates?.defaultExternalID;
const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
const isFocused = useIsFocused();
Expand All @@ -77,7 +78,8 @@ function WorkspaceTaxesPage({
);

useEffect(() => {
if (isFocused) {
if (isFocused || shouldPreserveSelection) {
setShouldPreserveSelection(false);
return;
}
setSelectedTaxesIDs([]);
Expand Down Expand Up @@ -313,7 +315,7 @@ function WorkspaceTaxesPage({
onTurnOnSelectionMode={(item) => item && toggleTax(item)}
sections={[{data: taxesList, isDisabled: false}]}
onCheckboxPress={toggleTax}
onSelectRow={navigateToEditTaxRate}
onSelectRow={(item) => {selectionMode?.isEnabled ? toggleTax(item):(setShouldPreserveSelection(true),navigateToEditTaxRate(item))}}
onSelectAll={toggleAllTaxes}
ListItem={TableListItem}
customListHeader={getCustomListHeader()}
Expand Down

0 comments on commit a4ec3c0

Please sign in to comment.