-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add report field picker components #34157
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fff6941
merge with main
allroundexperts 299df1e
feat: add policy report picker fields
allroundexperts 03c23a5
fix: prettier
allroundexperts 74ea0d7
fix: key errors
allroundexperts 1341d40
fix: revert canUseReportField beta
allroundexperts ca9ab3a
fix: lint issues
allroundexperts ae92f62
add comment for getReportFieldTitle function
allroundexperts 1a2dc38
fix: ts errors
allroundexperts 33ee5bd
prettier
allroundexperts b671b76
Merge branch 'feat-32762' into feat-32763
allroundexperts 399502d
fix console error on dropdown field
allroundexperts 2bd360f
Merge branch 'main' into feat-32763
allroundexperts 048d69f
fix: show checkmark on the selected option in the dropdown
allroundexperts cfa4cea
Update src/pages/EditReportFieldDropdownPage.tsx
allroundexperts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, {useCallback, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import DatePicker from '@components/DatePicker'; | ||
import FormProvider from '@components/Form/FormProvider'; | ||
import InputWrapper from '@components/Form/InputWrapper'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type EditReportFieldDatePageProps = { | ||
/** Value of the policy report field */ | ||
fieldValue: string; | ||
|
||
/** Name of the policy report field */ | ||
fieldName: string; | ||
|
||
/** ID of the policy report field */ | ||
fieldID: string; | ||
|
||
/** Callback to fire when the Save button is pressed */ | ||
onSubmit: () => void; | ||
}; | ||
|
||
function EditReportFieldDatePage({fieldName, onSubmit, fieldValue, fieldID}: EditReportFieldDatePageProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const validate = useCallback( | ||
(value: Record<string, string>) => { | ||
const errors: Record<string, string> = {}; | ||
if (value[fieldID].trim() === '') { | ||
errors[fieldID] = 'common.error.fieldRequired'; | ||
} | ||
return errors; | ||
}, | ||
[fieldID], | ||
); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
onEntryTransitionEnd={() => inputRef.current?.focus()} | ||
testID={EditReportFieldDatePage.displayName} | ||
> | ||
<HeaderWithBackButton title={fieldName} /> | ||
{/* @ts-expect-error TODO: TS migration */} | ||
<FormProvider | ||
style={[styles.flexGrow1, styles.ph5]} | ||
formID={ONYXKEYS.FORMS.POLICY_REPORT_FIELD_EDIT_FORM} | ||
onSubmit={onSubmit} | ||
validate={validate} | ||
submitButtonText={translate('common.save')} | ||
enabledWhenOffline | ||
> | ||
<View style={styles.mb4}> | ||
<InputWrapper | ||
// @ts-expect-error TODO: TS migration | ||
InputComponent={DatePicker} | ||
inputID={fieldID} | ||
name={fieldID} | ||
defaultValue={fieldValue} | ||
label={fieldName} | ||
accessibilityLabel={fieldName} | ||
role={CONST.ROLE.PRESENTATION} | ||
maxDate={CONST.CALENDAR_PICKER.MAX_DATE} | ||
minDate={CONST.CALENDAR_PICKER.MIN_DATE} | ||
ref={inputRef} | ||
/> | ||
</View> | ||
</FormProvider> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldDatePage.displayName = 'EditReportFieldDatePage'; | ||
|
||
export default EditReportFieldDatePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import OptionsSelector from '@components/OptionsSelector'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
||
type EditReportFieldDropdownPageProps = { | ||
/** Value of the policy report field */ | ||
fieldValue: string; | ||
|
||
/** Name of the policy report field */ | ||
fieldName: string; | ||
|
||
/** Options of the policy report field */ | ||
fieldOptions: string[]; | ||
|
||
/** Callback to fire when the Save button is pressed */ | ||
onSubmit: () => void; | ||
}; | ||
|
||
function EditReportFieldDropdownPage({fieldName, onSubmit, fieldValue, fieldOptions}: EditReportFieldDropdownPageProps) { | ||
const [searchValue, setSearchValue] = useState(''); | ||
const styles = useThemeStyles(); | ||
const {getSafeAreaMargins} = useStyleUtils(); | ||
const {translate} = useLocalize(); | ||
|
||
const sections = useMemo(() => { | ||
const filteredOptions = fieldOptions.filter((option) => option.toLowerCase().includes(searchValue.toLowerCase())); | ||
return [ | ||
{ | ||
title: translate('common.recents'), | ||
shouldShow: true, | ||
data: [], | ||
}, | ||
{ | ||
title: translate('common.all'), | ||
shouldShow: true, | ||
data: filteredOptions.map((option) => ({ | ||
text: option, | ||
keyForList: option, | ||
searchText: option, | ||
tooltipText: option, | ||
})), | ||
}, | ||
]; | ||
}, [fieldOptions, searchValue, translate]); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
testID={EditReportFieldDropdownPage.displayName} | ||
> | ||
{({insets}) => ( | ||
<> | ||
<HeaderWithBackButton title={fieldName} /> | ||
<OptionsSelector | ||
// @ts-expect-error TODO: TS migration | ||
contentContainerStyles={[{paddingBottom: getSafeAreaMargins(insets).marginBottom}]} | ||
optionHoveredStyle={styles.hoveredComponentBG} | ||
sectionHeaderStyle={styles.mt5} | ||
selectedOptions={[{name: fieldValue}]} | ||
textInputLabel={translate('common.search')} | ||
boldStyle | ||
sections={sections} | ||
value={searchValue} | ||
onSelectRow={onSubmit} | ||
onChangeText={setSearchValue} | ||
highlightSelectedOptions | ||
isRowMultilineSupported | ||
/> | ||
</> | ||
)} | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldDropdownPage.displayName = 'EditReportFieldDropdownPage'; | ||
|
||
export default EditReportFieldDropdownPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, {useEffect} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {PolicyReportFields, Report} from '@src/types/onyx'; | ||
import EditReportFieldDatePage from './EditReportFieldDatePage'; | ||
import EditReportFieldDropdownPage from './EditReportFieldDropdownPage'; | ||
import EditReportFieldTextPage from './EditReportFieldTextPage'; | ||
|
||
type EditReportFieldPageOnyxProps = { | ||
/** The report object for the expense report */ | ||
report: OnyxEntry<Report>; | ||
|
||
/** Policy report fields */ | ||
policyReportFields: OnyxEntry<PolicyReportFields>; | ||
}; | ||
|
||
type EditReportFieldPageProps = EditReportFieldPageOnyxProps & { | ||
/** Route from navigation */ | ||
route: { | ||
/** Params from the route */ | ||
params: { | ||
/** Which field we are editing */ | ||
fieldID: string; | ||
|
||
/** reportID for the expense report */ | ||
reportID: string; | ||
|
||
/** policyID for the expense report */ | ||
policyID: string; | ||
}; | ||
}; | ||
}; | ||
|
||
function EditReportFieldPage({route, report, policyReportFields}: EditReportFieldPageProps) { | ||
const policyReportField = policyReportFields?.[route.params.fieldID]; | ||
const reportFieldValue = report?.reportFields?.[policyReportField?.fieldID ?? '']; | ||
|
||
// Decides whether to allow or disallow editing a money request | ||
useEffect(() => {}, []); | ||
|
||
if (policyReportField) { | ||
if (policyReportField.type === 'text' || policyReportField.type === 'formula') { | ||
return ( | ||
<EditReportFieldTextPage | ||
fieldName={policyReportField.name} | ||
fieldID={policyReportField.fieldID} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
|
||
if (policyReportField.type === 'date') { | ||
return ( | ||
<EditReportFieldDatePage | ||
fieldName={policyReportField.name} | ||
fieldID={policyReportField.fieldID} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
|
||
if (policyReportField.type === 'dropdown') { | ||
return ( | ||
<EditReportFieldDropdownPage | ||
fieldName={policyReportField.name} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
fieldOptions={policyReportField.values} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
testID={EditReportFieldPage.displayName} | ||
> | ||
<FullPageNotFoundView | ||
shouldShow | ||
onBackButtonPress={() => {}} | ||
onLinkPress={() => {}} | ||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldPage.displayName = 'EditReportFieldPage'; | ||
|
||
export default withOnyx<EditReportFieldPageProps, EditReportFieldPageOnyxProps>({ | ||
report: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, | ||
}, | ||
policyReportFields: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS}${route.params.policyID}`, | ||
}, | ||
})(EditReportFieldPage); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have shown this only if recent options were greater than 0. This later caused #35832