Skip to content

Commit 4b18447

Browse files
authored
immer fs (keybase#20737)
* immer fs: kbfsDaemonStatus/overallSyncStatus/pathItemActionMenu * pathItems wip * pathItems and other cleanups * review feedback from jakob * get rid of fs reducer tests now that we don't try to reuse
1 parent 4938c8d commit 4b18447

37 files changed

Lines changed: 200 additions & 543 deletions

‎shared/actions/fs-gen.tsx‎

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/actions/fs/index.tsx‎

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as Constants from '../../constants/fs'
22
import * as EngineGen from '../engine-gen-gen'
33
import * as FsGen from '../fs-gen'
44
import * as ConfigGen from '../config-gen'
5-
import * as I from 'immutable'
65
import * as RPCTypes from '../../constants/types/rpc-gen'
76
import * as Saga from '../../util/saga'
87
import * as Flow from '../../util/flow'
@@ -248,12 +247,13 @@ const getPrefetchStatusFromRPC = (
248247
case RPCTypes.PrefetchStatus.notStarted:
249248
return Constants.prefetchNotStarted
250249
case RPCTypes.PrefetchStatus.inProgress:
251-
return Constants.makePrefetchInProgress({
250+
return {
251+
...Constants.emptyPrefetchInProgress,
252252
bytesFetched: prefetchProgress.bytesFetched,
253253
bytesTotal: prefetchProgress.bytesTotal,
254254
endEstimate: prefetchProgress.endEstimate,
255255
startTime: prefetchProgress.start,
256-
})
256+
}
257257
case RPCTypes.PrefetchStatus.complete:
258258
return Constants.prefetchComplete
259259
default:
@@ -271,24 +271,27 @@ const direntToMetadata = (d: RPCTypes.Dirent) => ({
271271
writable: d.writable,
272272
})
273273

274-
const makeEntry = (d: RPCTypes.Dirent, children?: Set<string>) => {
274+
const makeEntry = (d: RPCTypes.Dirent, children?: Set<string>): Types.PathItem => {
275275
switch (d.direntType) {
276276
case RPCTypes.DirentType.dir:
277-
return Constants.makeFolder({
277+
return {
278+
...Constants.emptyFolder,
278279
...direntToMetadata(d),
279-
children: I.Set(children || []) || I.Set(),
280-
progress: children ? Types.ProgressType.Loaded : undefined,
281-
})
280+
children: new Set(children || []),
281+
progress: children ? Types.ProgressType.Loaded : Types.ProgressType.Pending,
282+
} as Types.PathItem
282283
case RPCTypes.DirentType.sym:
283-
return Constants.makeSymlink({
284+
return {
285+
...Constants.emptySymlink,
284286
...direntToMetadata(d),
285287
// TODO: plumb link target
286-
})
288+
} as Types.PathItem
287289
case RPCTypes.DirentType.file:
288290
case RPCTypes.DirentType.exec:
289-
return Constants.makeFile(direntToMetadata(d))
290-
default:
291-
return Constants.makeUnknownPathItem(direntToMetadata(d))
291+
return {
292+
...Constants.emptyFile,
293+
...direntToMetadata(d),
294+
} as Types.PathItem
292295
}
293296
}
294297

@@ -348,28 +351,30 @@ function* folderList(_: TypedState, action: FsGen.FolderListLoadPayload) {
348351
if (entry.type === Types.PathType.Folder && isRecursive && d.name.indexOf('/') < 0) {
349352
// Since we are loading with a depth of 2, first level directories are
350353
// considered "loaded".
351-
return [path, entry.set('progress', Types.ProgressType.Loaded)]
354+
entry.progress = Types.ProgressType.Loaded
355+
return [path, entry]
352356
}
353357
return [path, entry]
354358
}
355359

356360
// Get metadata fields of the directory that we just loaded from state to
357361
// avoid overriding them.
358362
const state: TypedState = yield* Saga.selectState()
359-
const rootPathItem = state.fs.pathItems.get(rootPath, Constants.unknownPathItem)
360-
const rootFolder: Types.FolderPathItem = (rootPathItem.type === Types.PathType.Folder
361-
? rootPathItem
362-
: Constants.makeFolder({name: Types.getPathName(rootPath)})
363-
).withMutations(f =>
364-
f.set('children', I.Set(childMap.get(rootPath))).set('progress', Types.ProgressType.Loaded)
365-
)
363+
const rootPathItem = Constants.getPathItem(state.fs.pathItems, rootPath)
364+
const rootFolder: Types.FolderPathItem = {
365+
...(rootPathItem.type === Types.PathType.Folder
366+
? rootPathItem
367+
: {...Constants.emptyFolder, name: Types.getPathName(rootPath)}),
368+
children: new Set(childMap.get(rootPath)),
369+
progress: Types.ProgressType.Loaded,
370+
}
366371

367372
// @ts-ignore TODO fix this
368373
const pathItems: Array<[Types.Path, Types.FolderPathItem]> = [
369374
...(Types.getPathLevel(rootPath) > 2 ? [[rootPath, rootFolder]] : []),
370375
...entries.map(direntToPathAndPathItem),
371376
]
372-
yield Saga.put(FsGen.createFolderListLoaded({path: rootPath, pathItems: I.Map(pathItems)}))
377+
yield Saga.put(FsGen.createFolderListLoaded({path: rootPath, pathItems: new Map(pathItems)}))
373378
} catch (error) {
374379
yield makeRetriableErrorHandler(action, rootPath)(error).map(action => Saga.put(action))
375380
}
@@ -535,11 +540,10 @@ function* loadPathMetadata(_: TypedState, action: FsGen.LoadPathMetadataPayload)
535540
},
536541
Constants.statWaitingKey
537542
)
538-
let pathItem = makeEntry(dirent)
539543
yield Saga.put(
540544
FsGen.createPathItemLoaded({
541545
path,
542-
pathItem,
546+
pathItem: makeEntry(dirent),
543547
})
544548
)
545549
} catch (err) {
@@ -613,19 +617,6 @@ const moveOrCopy = async (state: TypedState, action: FsGen.MovePayload | FsGen.C
613617
const showMoveOrCopy = () =>
614618
RouteTreeGen.createNavigateAppend({path: [{props: {index: 0}, selected: 'destinationPicker'}]})
615619

616-
const closeDestinationPicker = () => {
617-
const currentRoutes = I.List()
618-
// const currentRoutes = getPathProps(state.routeTree.routeState)
619-
const firstDestinationPickerIndex = currentRoutes.findIndex(({node}) => node === 'destinationPicker')
620-
const newRoute = currentRoutes.reduce<Array<any>>(
621-
(routes, {node, props}, i) =>
622-
// node is never null
623-
i < firstDestinationPickerIndex ? [...routes, {props, selected: node || ''}] : routes,
624-
[]
625-
)
626-
return [RouteTreeGen.createNavigateAppend({path: newRoute})]
627-
}
628-
629620
// Can't rely on kbfsDaemonStatus.rpcStatus === 'waiting' as that's set by
630621
// reducer and happens before this.
631622
let waitForKbfsDaemonOnFly = false
@@ -724,7 +715,7 @@ const onNotifyFSOverallSyncSyncStatusChanged = (
724715
> = [
725716
FsGen.createOverallSyncStatusChanged({
726717
diskSpaceStatus,
727-
progress: Constants.makeSyncingFoldersProgress(action.payload.params.status.prefetchProgress),
718+
progress: action.payload.params.status.prefetchProgress,
728719
}),
729720
]
730721
// Only notify about the disk space status if it has changed.
@@ -927,7 +918,6 @@ function* fsSaga() {
927918
)
928919
yield* Saga.chainAction2([FsGen.move, FsGen.copy], moveOrCopy)
929920
yield* Saga.chainAction2([FsGen.showMoveOrCopy, FsGen.showIncomingShare], showMoveOrCopy)
930-
yield* Saga.chainAction2(FsGen.closeDestinationPicker, closeDestinationPicker)
931921
yield* Saga.chainAction2(
932922
[ConfigGen.installerRan, ConfigGen.loggedIn, FsGen.waitForKbfsDaemon],
933923
waitForKbfsDaemon

‎shared/actions/fs/platform-specific.desktop.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ const openPathInSystemFileManager = (state: TypedState, action: FsGen.OpenPathIn
128128
_rebaseKbfsPathToMountLocation(action.payload.path, state.fs.sfmi.directMountDir),
129129
![Types.PathKind.InGroupTlf, Types.PathKind.InTeamTlf].includes(
130130
Constants.parsePath(action.payload.path).kind
131-
) ||
132-
state.fs.pathItems.get(action.payload.path, Constants.unknownPathItem).type ===
133-
Types.PathType.Folder
131+
) || Constants.getPathItem(state.fs.pathItems, action.payload.path).type === Types.PathType.Folder
134132
).catch(makeRetriableErrorHandler(action, action.payload.path))
135133
: (new Promise((resolve, reject) => {
136134
if (state.fs.sfmi.driverStatus.type !== Types.DriverStatusType.Enabled) {

‎shared/actions/json/fs.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"folderListLoaded": {
2626
"path": "Types.Path",
27-
"pathItems": "I.Map<Types.Path, Types.PathItem>"
27+
"pathItems": "Map<Types.Path, Types.PathItem>"
2828
},
2929
"favoritesLoad": {},
3030
"favoritesLoaded": {
@@ -178,7 +178,6 @@
178178
"localPath": "Types.LocalPath"
179179
},
180180
"showIncomingShare": {"initialDestinationParentPath": "Types.Path"},
181-
"closeDestinationPicker": {},
182181
"move": {"destinationParentPath": "Types.Path"},
183182
"copy": {"destinationParentPath": "Types.Path"},
184183

‎shared/actions/typed-actions-gen.tsx‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/constants/fs.tsx‎

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,21 @@ export const emptyNewFolder = {
3434
type: Types.EditType.NewFolder,
3535
}
3636

37-
const makePrefetchNotStarted = I.Record<Types._PrefetchNotStarted>({
37+
export const prefetchNotStarted = {
3838
state: Types.PrefetchState.NotStarted,
39-
})
40-
export const prefetchNotStarted: Types.PrefetchNotStarted = makePrefetchNotStarted()
39+
}
4140

42-
const makePrefetchComplete = I.Record<Types._PrefetchComplete>({
41+
export const prefetchComplete = {
4342
state: Types.PrefetchState.Complete,
44-
})
45-
export const prefetchComplete: Types.PrefetchComplete = makePrefetchComplete()
43+
}
4644

47-
export const makePrefetchInProgress = I.Record<Types._PrefetchInProgress>({
45+
export const emptyPrefetchInProgress = {
4846
bytesFetched: 0,
4947
bytesTotal: 0,
5048
endEstimate: 0,
5149
startTime: 0,
5250
state: Types.PrefetchState.InProgress,
53-
})
51+
}
5452

5553
const pathItemMetadataDefault = {
5654
lastModifiedTimestamp: 0,
@@ -61,30 +59,28 @@ const pathItemMetadataDefault = {
6159
writable: false,
6260
}
6361

64-
export const makeFolder = I.Record<Types._FolderPathItem>({
62+
export const emptyFolder = {
6563
...pathItemMetadataDefault,
66-
children: I.Set(),
64+
children: new Set(),
6765
progress: Types.ProgressType.Pending,
6866
type: Types.PathType.Folder,
69-
})
67+
} as Types.FolderPathItem
7068

71-
export const makeFile = I.Record<Types._FilePathItem>({
69+
export const emptyFile = {
7270
...pathItemMetadataDefault,
7371
type: Types.PathType.File,
74-
})
72+
} as Types.FilePathItem
7573

76-
export const makeSymlink = I.Record<Types._SymlinkPathItem>({
74+
export const emptySymlink = {
7775
...pathItemMetadataDefault,
7876
linkTarget: '',
7977
type: Types.PathType.Symlink,
80-
})
78+
} as Types.SymlinkPathItem
8179

82-
export const makeUnknownPathItem = I.Record<Types._UnknownPathItem>({
80+
export const unknownPathItem = {
8381
...pathItemMetadataDefault,
8482
type: Types.PathType.Unknown,
85-
})
86-
87-
export const unknownPathItem = makeUnknownPathItem()
83+
} as Types.UnknownPathItem
8884

8985
export const tlfSyncEnabled: Types.TlfSyncEnabled = {
9086
mode: Types.TlfSyncMode.Enabled,
@@ -146,18 +142,18 @@ export const makeTlf = ({
146142
*/
147143
})
148144

149-
export const makeSyncingFoldersProgress = I.Record<Types._SyncingFoldersProgress>({
145+
export const emptySyncingFoldersProgress = {
150146
bytesFetched: 0,
151147
bytesTotal: 0,
152148
endEstimate: 0,
153149
start: 0,
154-
})
150+
}
155151

156-
export const makeOverallSyncStatus = I.Record<Types._OverallSyncStatus>({
152+
export const emptyOverallSyncStatus = {
157153
diskSpaceStatus: Types.DiskSpaceStatus.Ok,
158154
showingBanner: false,
159-
syncingFoldersProgress: makeSyncingFoldersProgress(),
160-
})
155+
syncingFoldersProgress: emptySyncingFoldersProgress,
156+
}
161157

162158
export const makePathUserSetting = I.Record<Types._PathUserSetting>({
163159
sort: Types.SortSetting.NameAsc,
@@ -215,12 +211,12 @@ export const makeSendAttachmentToChat = I.Record<Types._SendAttachmentToChat>({
215211
title: '',
216212
})
217213

218-
export const makePathItemActionMenu = I.Record<Types._PathItemActionMenu>({
214+
export const emptyPathItemActionMenu = {
219215
downloadID: null,
220216
downloadIntent: null,
221217
previousView: Types.PathItemActionMenuView.Root,
222218
view: Types.PathItemActionMenuView.Root,
223-
})
219+
}
224220

225221
export const makeDriverStatusUnknown = I.Record<Types._DriverStatusUnknown>({
226222
type: Types.DriverStatusType.Unknown,
@@ -250,10 +246,10 @@ export const makeSystemFileManagerIntegration = I.Record<Types._SystemFileManage
250246
showingBanner: false,
251247
})
252248

253-
export const makeKbfsDaemonStatus = I.Record<Types._KbfsDaemonStatus>({
249+
export const unknownKbfsDaemonStatus = {
254250
onlineStatus: Types.KbfsDaemonOnlineStatus.Unknown,
255251
rpcStatus: Types.KbfsDaemonRpcStatus.Unknown,
256-
})
252+
}
257253

258254
export const makeSoftErrors = I.Record<Types._SoftErrors>({
259255
pathErrors: I.Map(),
@@ -278,6 +274,9 @@ export const emptyFileContext = {
278274
viewType: RPCTypes.GUIViewType.default,
279275
}
280276

277+
export const getPathItem = (pathItems: Map<Types.Path, Types.PathItem>, path: Types.Path): Types.PathItem =>
278+
pathItems.get(path) || (unknownPathItem as Types.PathItem)
279+
281280
// RPC expects a string that's interpreted as [16]byte on Go side and it has to
282281
// be unique among all ongoing ops at any given time. uuidv1 may exceed 16
283282
// bytes, so just roll something simple that's seeded with time.

0 commit comments

Comments
 (0)