-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathSelectionScreen.tsx
114 lines (95 loc) · 3.64 KB
/
SelectionScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {isEmpty} from 'lodash';
import React from 'react';
import useLocalize from '@hooks/useLocalize';
import * as PolicyUtils from '@libs/PolicyUtils';
import type {AccessVariant} from '@pages/workspace/AccessOrNotFoundWrapper';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import type {TranslationPaths} from '@src/languages/types';
import type {ConnectionName, PolicyFeatureName} from '@src/types/onyx/Policy';
import HeaderWithBackButton from './HeaderWithBackButton';
import ScreenWrapper from './ScreenWrapper';
import SelectionList from './SelectionList';
import type RadioListItem from './SelectionList/RadioListItem';
import type TableListItem from './SelectionList/TableListItem';
import type {ListItem, SectionListDataType} from './SelectionList/types';
import type UserListItem from './SelectionList/UserListItem';
type SelectorType = ListItem & {
value: string;
};
type SelectionScreenProps = {
/** Used to set the testID for tests */
displayName: string;
/** Title of the selection component */
title: TranslationPaths;
/** Custom content to display in the header */
headerContent?: React.ReactNode;
/** Sections for the section list */
sections: Array<SectionListDataType<SelectorType>>;
/** Default renderer for every item in the list */
listItem: typeof RadioListItem | typeof UserListItem | typeof TableListItem;
/** Item `keyForList` to focus initially */
initiallyFocusedOptionKey?: string | null | undefined;
/** Callback to fire when a row is pressed */
onSelectRow: (selection: SelectorType) => void;
/** Callback to fire when back button is pressed */
onBackButtonPress: () => void;
/** The current policyID */
policyID: string;
/** Defines which types of access should be verified */
accessVariants?: AccessVariant[];
/** The current feature name that the user tries to get access to */
featureName?: PolicyFeatureName;
/** Whether or not to block user from accessing the page */
shouldBeBlocked?: boolean;
/** Name of the current connection */
connectionName: ConnectionName;
};
function SelectionScreen({
displayName,
title,
headerContent,
sections,
listItem,
initiallyFocusedOptionKey,
onSelectRow,
onBackButtonPress,
policyID,
accessVariants,
featureName,
shouldBeBlocked,
connectionName,
}: SelectionScreenProps) {
const {translate} = useLocalize();
const policy = PolicyUtils.getPolicy(policyID ?? '');
const isConnectionEmpty = isEmpty(policy.connections?.[connectionName]);
return (
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={accessVariants}
featureName={featureName}
shouldBeBlocked={isConnectionEmpty || shouldBeBlocked}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={displayName}
>
<HeaderWithBackButton
title={translate(title)}
onBackButtonPress={onBackButtonPress}
/>
<SelectionList
onSelectRow={onSelectRow}
headerContent={headerContent}
sections={sections}
ListItem={listItem}
showScrollIndicator
shouldShowTooltips={false}
initiallyFocusedOptionKey={initiallyFocusedOptionKey}
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}
export type {SelectorType};
SelectionScreen.displayName = 'SelectionScreen';
export default SelectionScreen;