1
+ import { isEmpty } from 'lodash' ;
1
2
import React , { useMemo } from 'react' ;
2
3
import type { StyleProp , TextStyle , ViewStyle } from 'react-native' ;
3
4
import { View } from 'react-native' ;
4
5
import useLocalize from '@hooks/useLocalize' ;
5
6
import useThemeStyles from '@hooks/useThemeStyles' ;
6
7
import Navigation from '@libs/Navigation/Navigation' ;
8
+ import * as PolicyUtils from '@libs/PolicyUtils' ;
7
9
import type { AccessVariant } from '@pages/workspace/AccessOrNotFoundWrapper' ;
8
10
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper' ;
9
11
import type { TranslationPaths } from '@src/languages/types' ;
10
- import type { PolicyFeatureName } from '@src/types/onyx/Policy' ;
12
+ import type { ConnectionName , PolicyFeatureName } from '@src/types/onyx/Policy' ;
11
13
import HeaderWithBackButton from './HeaderWithBackButton' ;
12
14
import ScreenWrapper from './ScreenWrapper' ;
13
15
import ScrollView from './ScrollView' ;
@@ -17,16 +19,16 @@ type ConnectionLayoutProps = {
17
19
/** Used to set the testID for tests */
18
20
displayName : string ;
19
21
20
- /** Header title for the connection */
21
- headerTitle : TranslationPaths ;
22
+ /** Header title to be translated for the connection component */
23
+ headerTitle ? : TranslationPaths ;
22
24
23
25
/** The subtitle to show in the header */
24
26
headerSubtitle ?: string ;
25
27
26
28
/** React nodes that will be shown */
27
29
children ?: React . ReactNode ;
28
30
29
- /** Title of the connection component */
31
+ /** Title to be translated for the connection component */
30
32
title ?: TranslationPaths ;
31
33
32
34
/** The current policyID */
@@ -44,18 +46,30 @@ type ConnectionLayoutProps = {
44
46
/** Style of the title text */
45
47
titleStyle ?: StyleProp < TextStyle > | undefined ;
46
48
49
+ /** Whether to include safe area padding bottom or not */
50
+ shouldIncludeSafeAreaPaddingBottom ?: boolean ;
51
+
47
52
/** Whether to use ScrollView or not */
48
53
shouldUseScrollView ?: boolean ;
54
+
55
+ /** Used for dynamic header title translation with parameters */
56
+ headerTitleAlreadyTranslated ?: string ;
57
+
58
+ /** Used for dynamic title translation with parameters */
59
+ titleAlreadyTranslated ?: string ;
60
+
61
+ /** Name of the current connection */
62
+ connectionName : ConnectionName ;
49
63
} ;
50
64
51
- type ConnectionLayoutContentProps = Pick < ConnectionLayoutProps , 'title' | 'titleStyle' | 'children' > ;
65
+ type ConnectionLayoutContentProps = Pick < ConnectionLayoutProps , 'title' | 'titleStyle' | 'children' | 'titleAlreadyTranslated' > ;
52
66
53
- function ConnectionLayoutContent ( { title, titleStyle, children} : ConnectionLayoutContentProps ) {
67
+ function ConnectionLayoutContent ( { title, titleStyle, children, titleAlreadyTranslated } : ConnectionLayoutContentProps ) {
54
68
const { translate} = useLocalize ( ) ;
55
69
const styles = useThemeStyles ( ) ;
56
70
return (
57
71
< >
58
- { title && < Text style = { [ styles . pb5 , titleStyle ] } > { translate ( title ) } </ Text > }
72
+ { title && < Text style = { [ styles . pb5 , titleStyle ] } > { titleAlreadyTranslated ?? translate ( title ) } </ Text > }
59
73
{ children }
60
74
</ >
61
75
) ;
@@ -72,35 +86,44 @@ function ConnectionLayout({
72
86
featureName,
73
87
contentContainerStyle,
74
88
titleStyle,
89
+ shouldIncludeSafeAreaPaddingBottom,
90
+ connectionName,
75
91
shouldUseScrollView = true ,
92
+ headerTitleAlreadyTranslated,
93
+ titleAlreadyTranslated,
76
94
} : ConnectionLayoutProps ) {
77
95
const { translate} = useLocalize ( ) ;
78
96
97
+ const policy = PolicyUtils . getPolicy ( policyID ?? '' ) ;
98
+ const isConnectionEmpty = isEmpty ( policy . connections ?. [ connectionName ] ) ;
99
+
79
100
const renderSelectionContent = useMemo (
80
101
( ) => (
81
102
< ConnectionLayoutContent
82
103
title = { title }
83
104
titleStyle = { titleStyle }
105
+ titleAlreadyTranslated = { titleAlreadyTranslated }
84
106
>
85
107
{ children }
86
108
</ ConnectionLayoutContent >
87
109
) ,
88
- [ title , titleStyle , children ] ,
110
+ [ title , titleStyle , children , titleAlreadyTranslated ] ,
89
111
) ;
90
112
91
113
return (
92
114
< AccessOrNotFoundWrapper
93
115
policyID = { policyID }
94
116
accessVariants = { accessVariants }
95
117
featureName = { featureName }
118
+ shouldBeBlocked = { isConnectionEmpty }
96
119
>
97
120
< ScreenWrapper
98
- includeSafeAreaPaddingBottom = { false }
121
+ includeSafeAreaPaddingBottom = { ! ! shouldIncludeSafeAreaPaddingBottom }
99
122
shouldEnableMaxHeight
100
123
testID = { displayName }
101
124
>
102
125
< HeaderWithBackButton
103
- title = { translate ( headerTitle ) }
126
+ title = { headerTitleAlreadyTranslated ?? ( headerTitle ? translate ( headerTitle as TranslationPaths ) : '' ) }
104
127
subtitle = { headerSubtitle }
105
128
onBackButtonPress = { ( ) => Navigation . goBack ( ) }
106
129
/>
0 commit comments