Skip to content

Commit

Permalink
UIPQB-124 Switching array operators disables the "Test" button
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Aug 11, 2024
1 parent 9f19831 commit c1c0a32
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useIntl } from 'react-intl';
import { useParamsDataSource } from '../../../../hooks/useParamsDataSource';
import { COLUMN_KEYS } from '../../../../constants/columnKeys';

export const SelectionContainer = ({
component: Component,
Expand All @@ -24,12 +25,6 @@ export const SelectionContainer = ({
];
};

const getFormattedValue = (val) => {
if (isMulti) return val || [];

return val || '';
};

const getOptions = (staticValues, sourceValues) => {
if (staticValues) return getSelectOptionsWithPlaceholder(staticValues);
if (sourceValues) return getSelectOptionsWithPlaceholder(sourceValues);
Expand All @@ -55,12 +50,25 @@ export const SelectionContainer = ({
};

const dataOptions = getOptions(availableValues, data?.content);
const val = getFormattedValue(value);

useEffect(() => {
const getFormattedValue = (val) => {
if (isMulti) return val || [];

return val || '';
};

const val = getFormattedValue(value);

if (!val) {
onChange(isMulti ? [] : '', rest.index, COLUMN_KEYS.VALUE);
}
}, [value, isMulti, onChange, rest.index]);

return (
<Component
{...rest}
value={val}
value={value}
data-testid={testId}
onChange={onChange}
filter={filterOptions}
Expand Down

0 comments on commit c1c0a32

Please sign in to comment.