Skip to content

Commit

Permalink
[Files app] Ducks: reducer migration: ui entries
Browse files Browse the repository at this point in the history
Bug: b:295777015
Test: CQ passes
Change-Id: I9e063f9dd71e46d5baba950f54f62bc2baf9eba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4801163
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Marcello Salomao <msalomao@google.com>
Cr-Commit-Position: refs/heads/main@{#1186941}
  • Loading branch information
Marcello Salomao authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent 0913f9b commit 3f448ca
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 94 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/ash/file_manager/file_manager_jstest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ReducerSearch) {
}

IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ReducerUiEntries) {
RunTestURL("state/reducers/ui_entries_unittest.js");
RunTestURL("state/ducks/ui_entries_unittest.js");
}

IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ReducerVolumes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {FakeEntryImpl} from '../../common/js/files_app_entry_types.js';
import {str, strf, util} from '../../common/js/util.js';
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js';
import {Crostini} from '../../externs/background/crostini.js';
import {addUiEntry, removeUiEntry} from '../../state/actions/ui_entries.js';
import {addUiEntry, removeUiEntry} from '../../state/ducks/ui_entries.js';
import {crostiniPlaceHolderKey} from '../../state/ducks/volumes.js';
import {getStore} from '../../state/store.js';

Expand Down
2 changes: 1 addition & 1 deletion ui/file_manager/file_manager/foreground/js/file_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {ForegroundWindow} from '../../externs/foreground_window.js';
import {PropStatus} from '../../externs/ts/state.js';
import {Store} from '../../externs/ts/store.js';
import {updatePreferences} from '../../state/actions/preferences.js';
import {addUiEntry, removeUiEntry} from '../../state/actions/ui_entries.js';
import {updateBulkPinProgress} from '../../state/ducks/bulk_pinning.js';
import {updateSearch} from '../../state/ducks/search.js';
import {addUiEntry, removeUiEntry} from '../../state/ducks/ui_entries.js';
import {trashRootKey} from '../../state/ducks/volumes.js';
import {getMyFiles} from '../../state/reducers/all_entries.js';
import {getEmptyState, getStore} from '../../state/store.js';
Expand Down
31 changes: 14 additions & 17 deletions ui/file_manager/file_manager/foreground/js/guest_os_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {GuestOsPlaceholder} from '../../common/js/files_app_entry_types.js';
import {util} from '../../common/js/util.js';
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js';
import {VolumeManager} from '../../externs/volume_manager.js';
import {addUiEntry, removeUiEntry} from '../../state/actions/ui_entries.js';
import {addUiEntry, removeUiEntry} from '../../state/ducks/ui_entries.js';
import {getEntry, getStore} from '../../state/store.js';

import {DirectoryModel} from './directory_model.js';
Expand Down Expand Up @@ -69,23 +69,20 @@ export class GuestOsController {
}
}

const newGuestOsPlaceholders =
guests.map(guest => {
const guestOsEntry =
new GuestOsPlaceholder(guest.displayName, guest.id, guest.vmType);
const navigationModelItem = new NavigationModelFakeItem(
guest.displayName, NavigationModelItemType.GUEST_OS,
guestOsEntry);
const volumeType =
guest.vmType == chrome.fileManagerPrivate.VmType.ARCVM ?
VolumeManagerCommon.VolumeType.ANDROID_FILES :
VolumeManagerCommon.VolumeType.GUEST_OS;
const newGuestOsPlaceholders = guests.map(guest => {
const guestOsEntry =
new GuestOsPlaceholder(guest.displayName, guest.id, guest.vmType);
const navigationModelItem = new NavigationModelFakeItem(
guest.displayName, NavigationModelItemType.GUEST_OS, guestOsEntry);
const volumeType =
guest.vmType == chrome.fileManagerPrivate.VmType.ARCVM ?
VolumeManagerCommon.VolumeType.ANDROID_FILES :
VolumeManagerCommon.VolumeType.GUEST_OS;

navigationModelItem.disabled =
this.volumeManager_.isDisabled(volumeType);
store.dispatch(addUiEntry({entry: guestOsEntry}));
return navigationModelItem;
});
navigationModelItem.disabled = this.volumeManager_.isDisabled(volumeType);
store.dispatch(addUiEntry({entry: guestOsEntry}));
return navigationModelItem;
});

if (!util.isFilesAppExperimental()) {
this.directoryTree_.dataModel.guestOsPlaceholders =
Expand Down
2 changes: 1 addition & 1 deletion ui/file_manager/file_manager/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {ChangeDirectoryAction, ChangeFileTasksAction, ChangeSelectionAction, Upd
import {AddFolderShortcutAction, RefreshFolderShortcutAction, RemoveFolderShortcutAction} from './actions/folder_shortcuts.js';
import {RefreshNavigationRootsAction, UpdateNavigationEntryAction} from './actions/navigation.js';
import {UpdatePreferencesAction} from './actions/preferences.js';
import {AddUiEntryAction, RemoveUiEntryAction} from './actions/ui_entries.js';
import {UpdateBulkPinProgressAction} from './ducks/bulk_pinning.js';
import {SearchAction} from './ducks/search.js';
import {AddUiEntryAction, RemoveUiEntryAction} from './ducks/ui_entries.js';
import {AddVolumeAction, RemoveVolumeAction, UpdateIsInteractiveVolumeAction} from './ducks/volumes.js';

/**
Expand Down
51 changes: 0 additions & 51 deletions ui/file_manager/file_manager/state/actions/ui_entries.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,42 @@ import {isVolumeEntry, sortEntries} from '../../common/js/entry_utils.js';
import {FakeEntryImpl} from '../../common/js/files_app_entry_types.js';
import {util} from '../../common/js/util.js';
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js';
import {State} from '../../externs/ts/state.js';
import {AddUiEntryAction, RemoveUiEntryAction} from '../actions/ui_entries.js';
import {FileKey, State} from '../../externs/ts/state.js';
import {addReducer, BaseAction, Reducer, ReducersMap} from '../../lib/base_store.js';
import {Action, ActionType} from '../actions.js';
import {getMyFiles} from '../reducers/all_entries.js';
import {getEntry, getFileData} from '../store.js';

import {getMyFiles} from './all_entries.js';
/**
* Actions and reducers for UI entries.
*
* UI entries represents entries shown on UI only (aka FakeEntry, e.g.
* Recents/Trash/Google Drive wrapper), they don't have a real entry backup in
* the file system.
*/


/** Map of actions to reducers for the UI entries slice. */
export const uiEntriesReducersMap: ReducersMap<State, Action> = new Map();

const uiEntryRootTypesInMyFiles = new Set([
VolumeManagerCommon.RootType.ANDROID_FILES,
VolumeManagerCommon.RootType.CROSTINI,
VolumeManagerCommon.RootType.GUEST_OS,
]);

export function addUiEntry(
currentState: State, action: AddUiEntryAction): State {
const {entry} = action.payload;

/** Action add single UI entry into the store. */
export interface AddUiEntryAction extends BaseAction {
type: ActionType.ADD_UI_ENTRY;
payload: {
entry: FakeEntryImpl,
};
}

export function addUiEntryReducer(
currentState: State, payload: AddUiEntryAction['payload']): State {
const {entry} = payload;
const key = entry.toURL();

let isVolumeEntryExistedInMyFiles = false;
Expand Down Expand Up @@ -70,9 +91,22 @@ export function addUiEntry(
};
}

export function removeUiEntry(
currentState: State, action: RemoveUiEntryAction): State {
const key = action.payload.key;
/** Action factory to add single UI entry into the store. */
export const addUiEntry = addReducer(
ActionType.ADD_UI_ENTRY, addUiEntryReducer as Reducer<State, Action>,
uiEntriesReducersMap);

/** Action remove single UI entry from the store. */
export interface RemoveUiEntryAction extends BaseAction {
type: ActionType.REMOVE_UI_ENTRY;
payload: {
key: FileKey,
};
}

export function removeUiEntryReducer(
currentState: State, payload: RemoveUiEntryAction['payload']): State {
const {key} = payload;
const entry = getEntry(currentState, key) as FakeEntryImpl | null;
if (currentState.uiEntries.find(k => k === key)) {
// Shallow copy.
Expand Down Expand Up @@ -102,3 +136,8 @@ export function removeUiEntry(
...currentState,
};
}

/** Action factory to remove single UI entry from the store. */
export const removeUiEntry = addReducer(
ActionType.REMOVE_UI_ENTRY, removeUiEntryReducer as Reducer<State, Action>,
uiEntriesReducersMap);
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {waitUntil} from '../../common/js/test_error_reporting.js';
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js';
import {FileData, State} from '../../externs/ts/state.js';
import {VolumeInfo} from '../../externs/volume_info.js';
import {addUiEntry, removeUiEntry} from '../actions/ui_entries.js';
import {createFakeVolumeMetadata, setUpFileManagerOnWindow, setupStore, waitDeepEquals} from '../for_tests.js';
import {convertEntryToFileData} from '../reducers/all_entries.js';
import {getEmptyState} from '../store.js';

import {convertEntryToFileData} from './all_entries.js';
import {convertVolumeInfoAndMetadataToVolume} from '../ducks/volumes.js';
import {addUiEntry, removeUiEntry} from './ui_entries.js';
import {convertVolumeInfoAndMetadataToVolume} from './volumes.js';

export function setUp() {
// sortEntries() from addUiEntry() reducer requires volumeManager and
Expand Down
14 changes: 7 additions & 7 deletions ui/file_manager/file_manager/state/reducers/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {State} from '../../externs/ts/state.js';
import {Action, ActionType} from '../actions.js';
import {bulkPinningReducersMap} from '../ducks/bulk_pinning.js';
import {searchReducersMap} from '../ducks/search.js';
import {uiEntriesReducersMap} from '../ducks/ui_entries.js';
import {volumesReducersMap} from '../ducks/volumes.js';

import {addChildEntries, cacheEntries, clearCachedEntries, updateMetadata} from './all_entries.js';
Expand All @@ -14,11 +15,14 @@ import {changeDirectory, updateDirectoryContent, updateFileTasks, updateSelectio
import {addFolderShortcut, refreshFolderShortcut, removeFolderShortcut} from './folder_shortcuts.js';
import {refreshNavigationRoots, updateNavigationEntry} from './navigation.js';
import {updatePreferences} from './preferences.js';
import {addUiEntry, removeUiEntry} from './ui_entries.js';

// Reducers map created from merging together each slice's exported reducersMap.
const rootReducersMap = new Map(
[...searchReducersMap, ...volumesReducersMap, ...bulkPinningReducersMap]);
const rootReducersMap = new Map([
...searchReducersMap,
...volumesReducersMap,
...bulkPinningReducersMap,
...uiEntriesReducersMap,
]);

/**
* Root reducer for the State for Files app.
Expand Down Expand Up @@ -56,10 +60,6 @@ export function rootReducer(currentState: State, action: Action): State {
return refreshNavigationRoots(currentState, action);
case ActionType.UPDATE_NAVIGATION_ENTRY:
return updateNavigationEntry(currentState, action);
case ActionType.ADD_UI_ENTRY:
return addUiEntry(currentState, action);
case ActionType.REMOVE_UI_ENTRY:
return removeUiEntry(currentState, action);
case ActionType.REFRESH_FOLDER_SHORTCUT:
return refreshFolderShortcut(currentState, action);
case ActionType.ADD_FOLDER_SHORTCUT:
Expand Down
5 changes: 2 additions & 3 deletions ui/file_manager/file_names.gni
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ ts_files = [
"file_manager/state/actions/folder_shortcuts.ts",
"file_manager/state/actions/navigation.ts",
"file_manager/state/actions/preferences.ts",
"file_manager/state/actions/ui_entries.ts",

# ActionsProducers.
"file_manager/state/actions_producers/all_entries.ts",
Expand All @@ -272,11 +271,11 @@ ts_files = [
"file_manager/state/reducers/folder_shortcuts.ts",
"file_manager/state/reducers/navigation.ts",
"file_manager/state/reducers/preferences.ts",
"file_manager/state/reducers/ui_entries.ts",

# Ducks.
"file_manager/state/ducks/bulk_pinning.ts",
"file_manager/state/ducks/search.ts",
"file_manager/state/ducks/ui_entries.ts",
"file_manager/state/ducks/volumes.ts",

# Containers.
Expand Down Expand Up @@ -406,12 +405,12 @@ ts_test_files = [
"file_manager/state/reducers/folder_shortcuts_unittest.ts",
"file_manager/state/reducers/navigation_unittest.ts",
"file_manager/state/reducers/preferences_unittest.ts",
"file_manager/state/reducers/ui_entries_unittest.ts",

# Ducks:
"file_manager/state/ducks/bulk_pinning_unittest.ts",
"file_manager/state/ducks/search_unittest.ts",
"file_manager/state/ducks/volumes_unittest.ts",
"file_manager/state/ducks/ui_entries_unittest.ts",

# Widgets:
"file_manager/widgets/xf_breadcrumb_unittest.ts",
Expand Down

0 comments on commit 3f448ca

Please sign in to comment.