Skip to content
Snippets Groups Projects
Unverified Commit b06d87d2 authored by Sean Tsai's avatar Sean Tsai Committed by GitHub
Browse files

Fix the CashFlow report crash because of the new CustomSelect (#1325)

parent fc6eb4be
No related branches found
No related tags found
No related merge requests found
...@@ -12,22 +12,39 @@ import ExpandArrow from '../../icons/v0/ExpandArrow'; ...@@ -12,22 +12,39 @@ import ExpandArrow from '../../icons/v0/ExpandArrow';
type CustomSelectProps = { type CustomSelectProps = {
options: Array<[string, string]>; options: Array<[string, string]>;
value: string; value: string;
defaultLabel?: string;
onChange?: (newValue: string) => void; onChange?: (newValue: string) => void;
style?: CSSProperties; style?: CSSProperties;
wrapperStyle?: CSSProperties; wrapperStyle?: CSSProperties;
disabledKeys?: string[]; disabledKeys?: string[];
}; };
/**
* @param {Array<[string, string]>} options - An array of options value-label pairs.
* @param {string} value - The currently selected option value.
* @param {string} [defaultLabel] - The label to display when the selected value is not in the options.
* @param {function} [onChange] - A callback function invoked when the selected value changes.
* @param {CSSProperties} [style] - Custom styles to apply to the selected button.
* @param {CSSProperties} [wrapperStyle] - Custom style to apply to the select wrapper.
* @param {string[]} [disabledKeys] - An array of option values to disable.
*
* @example
* // Usage:
* // <CustomSelect options={[['1', 'Option 1'], ['2', 'Option 2']]} value="1" onChange={handleOnChange} />
* // <CustomSelect options={[['1', 'Option 1'], ['2', 'Option 2']]} value="3" defaultLabel="Select an option" onChange={handleOnChange} />
*/
export default function CustomSelect({ export default function CustomSelect({
options, options,
value, value,
defaultLabel = '',
onChange, onChange,
style, style,
wrapperStyle, wrapperStyle,
disabledKeys = [], disabledKeys = [],
}: CustomSelectProps) { }: CustomSelectProps) {
const arrowSize = 7; const arrowSize = 7;
const label = options.filter(option => option[0] === value)[0][1]; const targetOption = options.filter(option => option[0] === value);
return ( return (
<ListboxInput <ListboxInput
value={value} value={value}
...@@ -52,7 +69,7 @@ export default function CustomSelect({ ...@@ -52,7 +69,7 @@ export default function CustomSelect({
alignItems: 'center', alignItems: 'center',
}} }}
> >
{label} {targetOption.length !== 0 ? targetOption[0][1] : defaultLabel}
</span> </span>
</ListboxButton> </ListboxButton>
<ListboxPopover style={{ zIndex: 10000, outline: 0, borderRadius: 4 }}> <ListboxPopover style={{ zIndex: 10000, outline: 0, borderRadius: 4 }}>
......
...@@ -96,6 +96,7 @@ function Header({ ...@@ -96,6 +96,7 @@ function Header({
onChangeDates(...validateStart(allMonths, newValue, end)) onChangeDates(...validateStart(allMonths, newValue, end))
} }
value={start} value={start}
defaultLabel={monthUtils.format(start, 'MMMM, yyyy')}
options={allMonths.map(({ name, pretty }) => [name, pretty])} options={allMonths.map(({ name, pretty }) => [name, pretty])}
/> />
<View>to</View> <View>to</View>
......
---
category: Bugfix
authors: [aleetsaiya]
---
Fix the CashFlow report crash because of the new CustomSelect
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment