Skip to content

Commit 8442cfb

Browse files
authored
incoming share to kbfs tweaks (keybase#23415)
* incoming share to kbfs tweaks * 🔥
1 parent 8296c3e commit 8442cfb

11 files changed

Lines changed: 596 additions & 36 deletions

File tree

‎shared/constants/fs.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,14 @@ export const hasSpecialFileElement = (path: Types.Path): boolean =>
971971

972972
export const sfmiInfoLoaded = (settings: Types.Settings, driverStatus: Types.DriverStatus): boolean =>
973973
settings.loaded && driverStatus !== driverStatusUnknown
974+
975+
// This isn't perfect since it doesn't cover the case of multi-writer public
976+
// TLFs or where a team TLF is readonly to the user. But to do that we'd need
977+
// some new caching in KBFS to plumb it into the Tlfs structure without
978+
// awful overhead.
979+
export const hideOrDisableInDestinationPicker = (
980+
tlfType: Types.TlfType,
981+
name: string,
982+
username: string,
983+
destinationPickerIndex?: number
984+
) => typeof destinationPickerIndex === 'number' && tlfType === Types.TlfType.Public && name !== username

‎shared/fs/browser/destination-picker/container.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,29 @@ const ConnectedDestinationPicker = (ownProps: OwnProps) => {
8686
},
8787
_onNewFolder: destinationParentPath =>
8888
dispatch(FsGen.createNewFolderRow({parentPath: destinationParentPath})),
89+
onBack: () => {
90+
dispatch(RouteTreeGen.createNavigateUp())
91+
},
8992
onCancel: () => {
9093
dispatch(RouteTreeGen.createClearModals())
9194
},
9295
}
9396

97+
const index = getIndex(ownProps)
98+
const showHeaderBackInsteadOfCancel = isShare && index > 0
9499
const targetName = Constants.getDestinationPickerPathName(destPicker)
95100
const props = {
96-
index: getIndex(ownProps),
101+
index,
97102
isShare,
98-
onBackUp: canBackUp(destPicker, ownProps)
99-
? () => dispatchProps._onBackUp(getDestinationParentPath(destPicker, ownProps))
100-
: undefined,
101-
onCancel: dispatchProps.onCancel,
103+
// If we are are dealing with incoming share, the first view is root,
104+
// so rely on the header back burtton instead of showing a separate row
105+
// for going to parent directory.
106+
onBack: showHeaderBackInsteadOfCancel ? dispatchProps.onBack : undefined,
107+
onBackUp:
108+
isShare || !canBackUp(destPicker, ownProps)
109+
? undefined
110+
: () => dispatchProps._onBackUp(getDestinationParentPath(destPicker, ownProps)),
111+
onCancel: showHeaderBackInsteadOfCancel ? undefined : dispatchProps.onCancel,
102112
onCopyHere: canCopy(destPicker, pathItems, ownProps)
103113
? () => dispatchProps._onCopyHere(getDestinationParentPath(destPicker, ownProps))
104114
: undefined,

‎shared/fs/browser/destination-picker/index.tsx‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Props = {
1414
isShare: boolean
1515
parentPath: Types.Path
1616
targetName: string
17+
onBack?: () => void
1718
onCancel?: () => void
1819
onCopyHere?: () => void
1920
onMoveHere?: () => void
@@ -57,6 +58,7 @@ const DestinationPicker = (props: Props) => {
5758
FsCommon.useFsOnlineStatus()
5859
return (
5960
<Kb.PopupWrapper
61+
onBack={props.onBack}
6062
onCancel={props.onCancel}
6163
customComponent={props.customComponent}
6264
headerStyle={props.headerStyle}
@@ -128,11 +130,18 @@ const DestinationPicker = (props: Props) => {
128130
const HighOrderDestinationPickerMobile = (props: Props) => {
129131
const otherProps = {
130132
customComponent: (
131-
<Kb.Box2 direction="horizontal" fullWidth={true}>
132-
<Kb.ClickableBox style={styles.mobileHeaderButton} onClick={props.onCancel || undefined}>
133-
<Kb.Text type="BodyBigLink">Cancel</Kb.Text>
134-
</Kb.ClickableBox>
135-
<Kb.Box2 direction="vertical" centerChildren={true} style={styles.mobileHeaderContent}>
133+
<Kb.Box2 direction="horizontal" fullWidth={true} style={{position: 'relative'}} centerChildren={true}>
134+
{!!props.onCancel && (
135+
<Kb.ClickableBox style={styles.mobileHeaderButton} onClick={props.onCancel}>
136+
<Kb.Text type="BodyBigLink">Cancel</Kb.Text>
137+
</Kb.ClickableBox>
138+
)}
139+
{!!props.onBack && (
140+
<Kb.ClickableBox style={styles.mobileHeaderButton} onClick={props.onBack}>
141+
<Kb.Text type="BodyBigLink">Back</Kb.Text>
142+
</Kb.ClickableBox>
143+
)}
144+
<Kb.Box2 direction="vertical" centerChildren={true}>
136145
<Kb.Box2 direction="horizontal" centerChildren={true} gap="xtiny">
137146
<FsCommon.ItemIcon size={16} path={Types.pathConcat(props.parentPath, props.targetName)} />
138147
<FsCommon.Filename type="BodySmallSemibold" filename={props.targetName} />
@@ -194,13 +203,9 @@ const styles = Styles.styleSheetCreate(
194203
},
195204
}),
196205
mobileHeaderButton: {
197-
paddingBottom: 8,
198-
paddingLeft: Styles.globalMargins.small,
199-
paddingRight: Styles.globalMargins.small,
200-
paddingTop: 8,
201-
},
202-
mobileHeaderContent: {
203-
paddingRight: 90, // width of the "Cancel" button
206+
left: 0,
207+
padding: Styles.globalMargins.small,
208+
position: 'absolute',
204209
},
205210
newFolderBox: {
206211
...Styles.globalStyles.flexBoxRow,

‎shared/fs/browser/root.tsx‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
22
import * as Types from '../../constants/types/fs'
3+
import * as Constants from '../../constants/fs'
34
import * as Kb from '../../common-adapters'
45
import * as Container from '../../util/container'
56
import TlfType from './rows/tlf-type-container'
@@ -39,6 +40,7 @@ const getRenderItem = destinationPickerIndex => ({item, section}) =>
3940
) : (
4041
<WrapRow>
4142
<Tlf
43+
disabled={false}
4244
name={item.name}
4345
tlfType={item.tlfType}
4446
mixedMode={true}
@@ -74,23 +76,32 @@ const useTopNTlfs = (
7476
[tlfs, n, tlfType]
7577
)
7678

77-
const useRecentTlfs = (n: number): Array<SectionListItem> => {
79+
const useRecentTlfs = (n: number, destinationPickerIndex?: number): Array<SectionListItem> => {
7880
const tlfs = Container.useSelector(state => state.fs.tlfs)
81+
const username = Container.useSelector(state => state.config.username)
7982
const privateTopN = useTopNTlfs(Types.TlfType.Private, tlfs.private, n)
8083
const publicTopN = useTopNTlfs(Types.TlfType.Public, tlfs.public, n)
8184
const teamTopN = useTopNTlfs(Types.TlfType.Team, tlfs.team, n)
82-
return React.useMemo(
83-
() =>
84-
[...privateTopN, ...publicTopN, ...teamTopN]
85-
.sort(({tlfMtime: t1}, {tlfMtime: t2}) => t2 - t1)
86-
.slice(0, n)
87-
.map(({name, tlfType}) => ({name, tlfType})),
88-
[privateTopN, publicTopN, teamTopN, n]
89-
)
85+
return React.useMemo(() => {
86+
const recent = [...privateTopN, ...publicTopN, ...teamTopN]
87+
.sort(({tlfMtime: t1}, {tlfMtime: t2}) => t2 - t1)
88+
.map(({name, tlfType}) => ({name, tlfType}))
89+
const afterFilter =
90+
// This isn't perfect since it doesn't cover the case where a team TLF
91+
// could be readonly. But to do that we'd need some new caching in KBFS
92+
// to plumb it into the Tlfs structure without awful overhead.
93+
typeof destinationPickerIndex === 'number'
94+
? recent.filter(
95+
({name, tlfType}) =>
96+
!Constants.hideOrDisableInDestinationPicker(tlfType, name, username, destinationPickerIndex)
97+
)
98+
: recent
99+
return afterFilter.slice(0, n)
100+
}, [destinationPickerIndex, privateTopN, publicTopN, teamTopN, n, username])
90101
}
91102

92103
const Root = ({destinationPickerIndex}: Props) => {
93-
const top10 = useRecentTlfs(10)
104+
const top10 = useRecentTlfs(10, destinationPickerIndex)
94105
const sections = [
95106
...(destinationPickerIndex
96107
? [] // don't show sfmi banner in destination picker

‎shared/fs/browser/rows/index.stories.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ const load = () => {
342342
</WrapRow>
343343
<WrapRow key="19">
344344
<TlfRow
345+
disabled={false}
345346
path={Types.stringToPath('/keybase/private/alice,bob,charlie')}
346347
isIgnored={false}
347348
onOpen={Sb.action('onOpen')}
@@ -350,6 +351,7 @@ const load = () => {
350351
</WrapRow>
351352
<WrapRow key="20">
352353
<TlfRow
354+
disabled={false}
353355
path={Types.stringToPath('/keybase/private/alice,bob,charlie')}
354356
isIgnored={false}
355357
onOpen={Sb.action('onOpen')}
@@ -358,6 +360,16 @@ const load = () => {
358360
</WrapRow>
359361
<WrapRow key="21">
360362
<TlfRow
363+
disabled={false}
364+
path={Types.stringToPath('/keybase/private/alice,bob,charlie,david,eve,felicity,george')}
365+
isIgnored={false}
366+
onOpen={Sb.action('onOpen')}
367+
usernames={['bob', 'charlie', 'david', 'eve', 'felicity', 'george']}
368+
/>
369+
</WrapRow>
370+
<WrapRow key="22">
371+
<TlfRow
372+
disabled={true}
361373
path={Types.stringToPath('/keybase/private/alice,bob,charlie,david,eve,felicity,george')}
362374
isIgnored={false}
363375
onOpen={Sb.action('onOpen')}

‎shared/fs/browser/rows/rows-container.tsx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ const getInTlfItemsFromStateProps = (stateProps, path: Types.Path): Array<RowTyp
9494
}
9595

9696
const getTlfRowsFromTlfs = memoize(
97-
(tlfs: Map<string, Types.Tlf>, tlfType: Types.TlfType): Array<SortableRowItem> =>
97+
(
98+
tlfs: Map<string, Types.Tlf>,
99+
tlfType: Types.TlfType,
100+
username: string,
101+
destinationPickerIndex?: number
102+
): Array<SortableRowItem> =>
98103
[...tlfs]
99104
.filter(([_, {isIgnored}]) => !isIgnored)
100105
.map(([name, {isNew, tlfMtime}]) => ({
106+
disabled: Constants.hideOrDisableInDestinationPicker(tlfType, name, username, destinationPickerIndex),
101107
isNew,
102108
key: `tlf:${name}`,
103109
name,
@@ -108,29 +114,38 @@ const getTlfRowsFromTlfs = memoize(
108114
}))
109115
)
110116

111-
const getTlfItemsFromStateProps = (stateProps, path): Array<RowTypes.NamedRowItem> => {
117+
const getTlfItemsFromStateProps = (
118+
stateProps,
119+
path,
120+
destinationPickerIndex
121+
): Array<RowTypes.NamedRowItem> => {
112122
if (stateProps._tlfs.private.size === 0) {
113123
// /keybase/private/<me> is always favorited. If it's not there it must be
114124
// unintialized.
115125
return folderPlaceholderRows
116126
}
117127

118128
const {tlfList, tlfType} = Constants.getTlfListAndTypeFromPath(stateProps._tlfs, path)
129+
119130
return sortRowItems(
120-
getTlfRowsFromTlfs(tlfList, tlfType),
131+
getTlfRowsFromTlfs(tlfList, tlfType, stateProps._username, destinationPickerIndex),
121132
stateProps._sortSetting,
122133
(Types.pathIsNonTeamTLFList(path) && stateProps._username) || ''
123134
)
124135
}
125136

126-
const getNormalRowItemsFromStateProps = (stateProps, path): Array<RowTypes.NamedRowItem> => {
137+
const getNormalRowItemsFromStateProps = (
138+
stateProps,
139+
path,
140+
destinationPickerIndex
141+
): Array<RowTypes.NamedRowItem> => {
127142
const level = Types.getPathLevel(path)
128143
switch (level) {
129144
case 0:
130145
case 1:
131146
return [] // should never happen
132147
case 2:
133-
return getTlfItemsFromStateProps(stateProps, path)
148+
return getTlfItemsFromStateProps(stateProps, path, destinationPickerIndex)
134149
default:
135150
return getInTlfItemsFromStateProps(stateProps, path)
136151
}
@@ -155,7 +170,7 @@ export default namedConnect(
155170
}),
156171
() => ({}),
157172
(s, _, o: OwnProps) => {
158-
const normalRowItems = getNormalRowItemsFromStateProps(s, o.path)
173+
const normalRowItems = getNormalRowItemsFromStateProps(s, o.path, o.destinationPickerIndex)
159174
const filteredRowItems = filterRowItems(normalRowItems, s._filter)
160175
return {
161176
destinationPickerIndex: o.destinationPickerIndex,

‎shared/fs/browser/rows/rows.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Rows extends React.PureComponent<Props> {
4848
return (
4949
<WrapRow>
5050
<Tlf
51+
disabled={item.disabled}
5152
name={item.name}
5253
tlfType={item.tlfType}
5354
destinationPickerIndex={this.props.destinationPickerIndex}

‎shared/fs/browser/rows/tlf-container.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Tlf from './tlf'
77

88
export type OwnProps = {
99
destinationPickerIndex?: number
10+
disabled: boolean
1011
mixedMode?: boolean
1112
name: string
1213
tlfType: Types.TlfType
@@ -17,11 +18,16 @@ const mapStateToProps = (state, {tlfType, name}: OwnProps) => ({
1718
_username: state.config.username,
1819
})
1920

20-
const mergeProps = (stateProps, _, {tlfType, name, mixedMode, destinationPickerIndex}: OwnProps) => {
21+
const mergeProps = (
22+
stateProps,
23+
_,
24+
{tlfType, name, mixedMode, destinationPickerIndex, disabled}: OwnProps
25+
) => {
2126
const path = Constants.tlfTypeAndNameToPath(tlfType, name)
2227
const usernames = Constants.getUsernamesFromTlfName(name).filter(name => name !== stateProps._username)
2328
return {
2429
destinationPickerIndex,
30+
disabled,
2531
isIgnored: stateProps._tlf.isIgnored,
2632
loadPathMetadata:
2733
stateProps._tlf.syncConfig && stateProps._tlf.syncConfig.mode !== Types.TlfSyncMode.Disabled,

‎shared/fs/browser/rows/tlf.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ type TlfProps = StillCommonProps & {
1313
isIgnored: boolean
1414
mixedMode?: boolean
1515
usernames: Array<string>
16+
disabled: boolean
1617
}
1718

1819
const Content = (props: TlfProps) => (
1920
<Kb.BoxGrow>
20-
<Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true} style={styles.leftBox}>
21+
<Kb.Box2
22+
direction="vertical"
23+
fullWidth={true}
24+
fullHeight={true}
25+
style={Styles.collapseStyles([styles.leftBox, props.disabled && rowStyles.opacity30])}
26+
>
2127
<Kb.Box2 direction="horizontal" fullWidth={true} style={styles.minWidth}>
2228
<Filename
2329
type={Constants.pathTypeToTextType(Types.PathType.Folder)}
@@ -49,7 +55,7 @@ const Tlf = (props: TlfProps) => (
4955
{!!props.loadPathMetadata && <FsPathMetadataLoader path={props.path} />}
5056
<StillCommon
5157
path={props.path}
52-
onOpen={props.onOpen}
58+
onOpen={props.disabled ? undefined : props.onOpen}
5359
inDestinationPicker={props.inDestinationPicker}
5460
mixedMode={props.mixedMode}
5561
writingToJournal={false}

‎shared/fs/browser/rows/types.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type TlfTypeRowItem = {
1919
}
2020

2121
export type TlfRowItem = {
22+
disabled: boolean
2223
isNew: boolean
2324
key: string
2425
name: string

0 commit comments

Comments
 (0)