Skip to content

deprecate children, migrate picker props #3078

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

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/components/picker/helpers/usePickerMigrationWarnings.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import {useEffect} from 'react';
import _ from 'lodash';
import {LogService} from '../../../services';
import {PickerProps, PickerModes} from '../types';
import {PickerProps} from '../types';

// @ts-expect-error TODO: Remove this whole file when migration is completed
type UsePickerMigrationWarnings = Pick<PickerProps, 'value' | 'mode' | 'useNativePicker'>;
// TODO: Remove this whole file when migration is completed
type UsePickerMigrationWarnings = Pick<
PickerProps,
'children' | 'migrate' | 'getItemLabel' | 'getItemValue' | 'onShow'
>;

const usePickerMigrationWarnings = (props: UsePickerMigrationWarnings) => {
const {value, mode, useNativePicker} = props;
const {children, migrate, getItemLabel, getItemValue, onShow} = props;
useEffect(() => {
if (mode === PickerModes.SINGLE && Array.isArray(value)) {
LogService.warn('Picker in SINGLE mode cannot accept an array for value');
if (children) {
LogService.warn(`UILib Picker will stop supporting the 'children' prop in the next major version, please pass 'items' prop instead`);
}
if (mode === PickerModes.MULTI && !Array.isArray(value)) {
LogService.warn('Picker in MULTI mode must accept an array for value');

if (migrate) {
LogService.warn(`UILib Picker will stop supporting the 'migrate' prop in the next major version, please stop using it. The picker uses the new implementation by default.`);
}

if (getItemLabel) {
LogService.warn(`UILib Picker will stop supporting the 'getItemLabel' prop in the next major version, please pass the 'getItemLabel' prop to the specific item instead`);
}

if (_.isPlainObject(value)) {
LogService.warn('UILib Picker will stop supporting passing object as value in the next major version. Please use either string or a number as value');
if (getItemValue) {
LogService.warn(`UILib Picker will stop supporting the 'getItemValue' prop in the next major version, please stop using it. The value will be extract from 'items' prop instead`);
}

if (useNativePicker) {
LogService.warn(`UILib Picker will stop supporting the 'useNativePicker' prop soon, please pass instead the 'useWheelPicker' prop and handle relevant TextField migration if required to`);
if (onShow) {
LogService.warn(`UILib Picker will stop supporting the 'onShow' prop in the next major version, please pass the 'onShow' prop from the 'pickerModalProps' instead`);
}
}, []);
};
Expand Down
7 changes: 3 additions & 4 deletions src/components/picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// TODO: deprecate getItemLabel prop
// TODO: Add initialValue prop
// TODO: consider deprecating renderCustomModal prop
// TODO: deprecate onShow cause it's already supported by passing it in pickerModalProps
import _ from 'lodash';
import React, {useMemo, useState, useRef, useCallback, useEffect} from 'react';
import {LayoutChangeEvent} from 'react-native';
Expand All @@ -23,7 +22,7 @@ import usePickerSelection from './helpers/usePickerSelection';
import usePickerLabel from './helpers/usePickerLabel';
import usePickerSearch from './helpers/usePickerSearch';
import useImperativePickerHandle from './helpers/useImperativePickerHandle';
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
import {extractPickerItems} from './PickerPresenter';
import {
PickerProps,
Expand Down Expand Up @@ -107,8 +106,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {

const pickerExpandable = useRef<ExpandableOverlayMethods>(null);

// TODO: Remove
// usePickerMigrationWarnings({value, mode});
// TODO: Remove this when migration is completed, starting of v8
usePickerMigrationWarnings({children, migrate, getItemLabel, getItemValue});

const pickerRef = useImperativePickerHandle(ref, pickerExpandable);
const {
Expand Down
5 changes: 5 additions & 0 deletions src/components/picker/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
*/
useDialog?: boolean;
/**
* @deprecated
* Temporary prop required for migration to Picker's new API
*/
migrate?: boolean;
Expand Down Expand Up @@ -172,6 +173,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
*/
containerStyle?: StyleProp<ViewStyle>;
/**
* @deprecated
* Callback for modal onShow event
*/
onShow?: () => void;
Expand All @@ -187,6 +189,9 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
* Component test id
*/
testID?: string;
/**
* @deprecated
*/
children?: ReactNode | undefined;
};

Expand Down