Skip to content

Commit

Permalink
continue and improve code for Selects
Browse files Browse the repository at this point in the history
Signed-off-by: basseche <[email protected]>
  • Loading branch information
basseche committed Jan 23, 2025
1 parent 2b253f8 commit c7563f3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { CombinatorSelectorProps } from 'react-querybuilder';
import { useCallback, useState } from 'react';
import { MaterialValueSelector } from '@react-querybuilder/material';
import { PopupConfirmationDialog } from '../../dialogs/popupConfirmationDialog/PopupConfirmationDialog';
import { useSelectAppearance } from '../../../hooks/useSelectAppearance';

export function CombinatorSelector(props: CombinatorSelectorProps) {
const { value, handleOnChange } = props;
const { options, value, handleOnChange } = props;
const [tempCombinator, setTempCombinator] = useState(value);
const [openPopup, setOpenPopup] = useState(false);

Expand All @@ -35,6 +36,7 @@ export function CombinatorSelector(props: CombinatorSelectorProps) {
setTempCombinator(newCombinator);
setOpenPopup(true);
}}
{...useSelectAppearance(options.length)}
/>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/reactQueryBuilder/FieldSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ValueSelectorProps } from 'react-querybuilder';
import { MaterialValueSelector } from '@react-querybuilder/material';
import { useSelectAppearance } from './useSelectAppearance';
import { useSelectAppearance } from '../../../hooks/useSelectAppearance';

const ITEM_HEIGHT = 32; // default value from React query builder defaultNativeSelectStyles that can't be accessed
const ITEM_PADDING = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { OPERATOR_OPTIONS } from '../../filter/expert/expertFilterConstants';
import { FieldConstants } from '../../../utils/constants/fieldConstants';
import { usePredefinedProperties } from '../../../hooks/usePredefinedProperties';
import { EquipmentType } from '../../../utils';
import { useSelectAppearance } from './useSelectAppearance';
import { useSelectAppearance } from '../../../hooks/useSelectAppearance';

const PROPERTY_VALUE_OPERATORS = [OPERATOR_OPTIONS.IN];

Expand Down Expand Up @@ -113,11 +113,7 @@ export function PropertyValueEditor(props: ExpertFilterPropertyProps) {
multiple
renderInput={(params) => {
return (
<TextField
{...params}
error={!valid}
placeholder={valid ? '' : intl.formatMessage({ id: 'valuesList' })}
/>
<TextField {...params} error={!valid} label={intl.formatMessage({ id: 'valuesList' })} />
);
}}
freeSolo
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/reactQueryBuilder/ValueSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ValueSelectorProps } from 'react-querybuilder';
import { MaterialValueSelector } from '@react-querybuilder/material';
import { useSelectAppearance } from './useSelectAppearance';
import { useSelectAppearance } from '../../../hooks/useSelectAppearance';

export function ValueSelector(props: ValueSelectorProps) {
const { options } = props;
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './usePredefinedProperties';
export * from './usePrevious';
export * from './useSnackMessage';
export * from './useFormatLabelWithUnit';
export * from './useSelectAppearance';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

// useSelectAppearance
/** Hooks used to modify appearance of Select as a readonly TextField,
by hiding display button and setting readOnly prop to true
if options list is only one element long.
P.S : Not to used on AutoComplete.
*/
export function useSelectAppearance(listLength: number) {
if (listLength === 1) {
return { IconComponent: () => null, readOnly: true };
Expand Down

0 comments on commit c7563f3

Please sign in to comment.