2024-09-19 19:23:12 +05:30
|
|
|
/* eslint-disable sonarjs/cognitive-complexity */
|
2024-06-18 13:02:15 +05:30
|
|
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
|
|
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
|
|
|
/* eslint-disable no-nested-ternary */
|
2023-11-30 13:56:49 +05:30
|
|
|
import './DashboardVariableSelection.styles.scss';
|
|
|
|
|
|
2022-09-09 17:43:25 +05:30
|
|
|
import { orange } from '@ant-design/colors';
|
2025-05-16 16:46:19 +05:30
|
|
|
import { InfoCircleOutlined, WarningOutlined } from '@ant-design/icons';
|
2025-05-15 00:31:13 +05:30
|
|
|
import { Input, Popover, Tooltip, Typography } from 'antd';
|
2023-11-30 13:56:49 +05:30
|
|
|
import dashboardVariablesQuery from 'api/dashboard/variables/dashboardVariablesQuery';
|
2025-05-15 00:31:13 +05:30
|
|
|
import { CustomMultiSelect, CustomSelect } from 'components/NewSelect';
|
2023-11-30 13:56:49 +05:30
|
|
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
2022-09-09 17:43:25 +05:30
|
|
|
import { commaValuesParser } from 'lib/dashbaordVariables/customCommaValuesParser';
|
|
|
|
|
import sortValues from 'lib/dashbaordVariables/sortVariableValues';
|
2025-05-15 00:31:13 +05:30
|
|
|
import { debounce, isArray, isEmpty, isString } from 'lodash-es';
|
|
|
|
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
2023-11-30 13:56:49 +05:30
|
|
|
import { useQuery } from 'react-query';
|
2024-09-19 19:23:12 +05:30
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
import { AppState } from 'store/reducers';
|
2022-09-09 17:43:25 +05:30
|
|
|
import { IDashboardVariable } from 'types/api/dashboard/getAll';
|
2023-11-30 13:56:49 +05:30
|
|
|
import { VariableResponseProps } from 'types/api/dashboard/variables/query';
|
2024-09-19 19:23:12 +05:30
|
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
2024-01-27 12:59:28 +05:30
|
|
|
import { popupContainer } from 'utils/selectPopupContainer';
|
2022-09-09 17:43:25 +05:30
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
import { ALL_SELECT_VALUE, variablePropsToPayloadVariables } from '../utils';
|
2024-05-28 19:09:04 +05:30
|
|
|
import { SelectItemStyle } from './styles';
|
2025-01-09 23:24:18 +05:30
|
|
|
import { areArraysEqual, checkAPIInvocation, IDependencyData } from './util';
|
2022-09-09 17:43:25 +05:30
|
|
|
|
|
|
|
|
interface VariableItemProps {
|
|
|
|
|
variableData: IDashboardVariable;
|
2023-01-25 13:22:57 +05:30
|
|
|
existingVariables: Record<string, IDashboardVariable>;
|
|
|
|
|
onValueUpdate: (
|
2023-05-02 18:51:24 +05:30
|
|
|
name: string,
|
2023-12-15 13:10:02 +05:30
|
|
|
id: string,
|
2023-05-02 18:51:24 +05:30
|
|
|
arg1: IDashboardVariable['selectedValue'],
|
2023-11-30 13:56:49 +05:30
|
|
|
allSelected: boolean,
|
2023-01-25 13:22:57 +05:30
|
|
|
) => void;
|
2024-04-15 11:11:14 +05:30
|
|
|
variablesToGetUpdated: string[];
|
2024-06-20 17:21:04 +05:30
|
|
|
setVariablesToGetUpdated: React.Dispatch<React.SetStateAction<string[]>>;
|
2025-01-09 23:24:18 +05:30
|
|
|
dependencyData: IDependencyData | null;
|
2022-09-09 17:43:25 +05:30
|
|
|
}
|
2023-08-02 12:09:49 +02:00
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
export const getSelectValue = (
|
2023-08-02 12:09:49 +02:00
|
|
|
selectedValue: IDashboardVariable['selectedValue'],
|
2024-06-18 13:02:15 +05:30
|
|
|
variableData: IDashboardVariable,
|
2024-09-25 11:32:19 +05:30
|
|
|
): string | string[] | undefined => {
|
2023-08-02 12:09:49 +02:00
|
|
|
if (Array.isArray(selectedValue)) {
|
2024-06-18 13:02:15 +05:30
|
|
|
if (!variableData.multiSelect && selectedValue.length === 1) {
|
2024-09-25 11:32:19 +05:30
|
|
|
return selectedValue[0]?.toString();
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2023-08-02 12:09:49 +02:00
|
|
|
return selectedValue.map((item) => item.toString());
|
|
|
|
|
}
|
2024-09-25 11:32:19 +05:30
|
|
|
return selectedValue?.toString();
|
2023-08-02 12:09:49 +02:00
|
|
|
};
|
|
|
|
|
|
2024-01-27 12:59:28 +05:30
|
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
2022-09-09 17:43:25 +05:30
|
|
|
function VariableItem({
|
|
|
|
|
variableData,
|
2023-01-25 13:22:57 +05:30
|
|
|
existingVariables,
|
2022-09-09 17:43:25 +05:30
|
|
|
onValueUpdate,
|
2024-04-15 11:11:14 +05:30
|
|
|
variablesToGetUpdated,
|
2024-06-20 17:21:04 +05:30
|
|
|
setVariablesToGetUpdated,
|
2025-01-09 23:24:18 +05:30
|
|
|
dependencyData,
|
2022-09-09 17:43:25 +05:30
|
|
|
}: VariableItemProps): JSX.Element {
|
2023-01-25 13:22:57 +05:30
|
|
|
const [optionsData, setOptionsData] = useState<(string | number | boolean)[]>(
|
|
|
|
|
[],
|
|
|
|
|
);
|
2025-05-15 00:31:13 +05:30
|
|
|
const [tempSelection, setTempSelection] = useState<
|
|
|
|
|
string | string[] | undefined
|
|
|
|
|
>(undefined);
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2024-09-19 19:23:12 +05:30
|
|
|
const { maxTime, minTime } = useSelector<AppState, GlobalReducer>(
|
|
|
|
|
(state) => state.globalTime,
|
|
|
|
|
);
|
|
|
|
|
|
2025-01-09 23:24:18 +05:30
|
|
|
const validVariableUpdate = (): boolean => {
|
|
|
|
|
if (!variableData.name) {
|
|
|
|
|
return false;
|
2024-09-19 19:23:12 +05:30
|
|
|
}
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2025-01-09 23:24:18 +05:30
|
|
|
// variableData.name is present as the top element or next in the queue - variablesToGetUpdated
|
|
|
|
|
return Boolean(
|
|
|
|
|
variablesToGetUpdated.length &&
|
|
|
|
|
variablesToGetUpdated[0] === variableData.name,
|
2025-01-09 01:01:54 +05:30
|
|
|
);
|
|
|
|
|
};
|
2025-01-02 15:45:01 +05:30
|
|
|
|
2025-01-09 23:24:18 +05:30
|
|
|
const [errorMessage, setErrorMessage] = useState<null | string>(null);
|
|
|
|
|
|
2023-11-30 13:56:49 +05:30
|
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
|
|
|
const getOptions = (variablesRes: VariableResponseProps | null): void => {
|
|
|
|
|
if (variablesRes && variableData.type === 'QUERY') {
|
2022-09-09 17:43:25 +05:30
|
|
|
try {
|
|
|
|
|
setErrorMessage(null);
|
2023-11-30 13:56:49 +05:30
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
variablesRes?.variableValues &&
|
|
|
|
|
Array.isArray(variablesRes?.variableValues)
|
|
|
|
|
) {
|
2023-01-25 13:22:57 +05:30
|
|
|
const newOptionsData = sortValues(
|
2023-11-30 13:56:49 +05:30
|
|
|
variablesRes?.variableValues,
|
2023-01-25 13:22:57 +05:30
|
|
|
variableData.sort,
|
2022-09-09 17:43:25 +05:30
|
|
|
);
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2023-01-25 13:22:57 +05:30
|
|
|
const oldOptionsData = sortValues(optionsData, variableData.sort) as never;
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2023-01-25 13:22:57 +05:30
|
|
|
if (!areArraysEqual(newOptionsData, oldOptionsData)) {
|
|
|
|
|
/* eslint-disable no-useless-escape */
|
2024-06-04 11:18:44 +05:30
|
|
|
|
|
|
|
|
let valueNotInList = false;
|
|
|
|
|
|
|
|
|
|
if (isArray(variableData.selectedValue)) {
|
|
|
|
|
variableData.selectedValue.forEach((val) => {
|
|
|
|
|
const isUsed = newOptionsData.includes(val);
|
|
|
|
|
|
|
|
|
|
if (!isUsed) {
|
|
|
|
|
valueNotInList = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else if (isString(variableData.selectedValue)) {
|
|
|
|
|
const isUsed = newOptionsData.includes(variableData.selectedValue);
|
|
|
|
|
|
|
|
|
|
if (!isUsed) {
|
|
|
|
|
valueNotInList = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-19 19:23:12 +05:30
|
|
|
// variablesData.allSelected is added for the case where on change of options we need to update the
|
|
|
|
|
// local storage
|
2023-01-25 13:22:57 +05:30
|
|
|
if (
|
|
|
|
|
variableData.type === 'QUERY' &&
|
2024-04-15 11:11:14 +05:30
|
|
|
variableData.name &&
|
2025-01-09 23:24:18 +05:30
|
|
|
(validVariableUpdate() || valueNotInList || variableData.allSelected)
|
2023-01-25 13:22:57 +05:30
|
|
|
) {
|
2025-05-15 00:31:13 +05:30
|
|
|
const value = variableData.selectedValue;
|
2023-01-25 13:22:57 +05:30
|
|
|
let allSelected = false;
|
|
|
|
|
// The default value for multi-select is ALL and first value for
|
|
|
|
|
// single select
|
2025-05-15 00:31:13 +05:30
|
|
|
// console.log(valueNotInList);
|
|
|
|
|
// if (valueNotInList) {
|
|
|
|
|
// if (variableData.multiSelect) {
|
|
|
|
|
// value = newOptionsData;
|
|
|
|
|
// allSelected = true;
|
|
|
|
|
// } else {
|
|
|
|
|
// [value] = newOptionsData;
|
|
|
|
|
// }
|
|
|
|
|
// } else
|
|
|
|
|
|
|
|
|
|
if (variableData.multiSelect) {
|
2025-03-10 14:18:55 +05:30
|
|
|
const { selectedValue } = variableData;
|
|
|
|
|
allSelected =
|
|
|
|
|
newOptionsData.length > 0 &&
|
|
|
|
|
Array.isArray(selectedValue) &&
|
|
|
|
|
selectedValue.length === newOptionsData.length &&
|
|
|
|
|
newOptionsData.every((option) => selectedValue.includes(option));
|
2023-01-25 13:22:57 +05:30
|
|
|
}
|
2023-12-15 13:10:02 +05:30
|
|
|
|
|
|
|
|
if (variableData && variableData?.name && variableData?.id) {
|
|
|
|
|
onValueUpdate(variableData.name, variableData.id, value, allSelected);
|
2023-05-02 18:51:24 +05:30
|
|
|
}
|
2023-01-25 13:22:57 +05:30
|
|
|
}
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2023-01-25 13:22:57 +05:30
|
|
|
setOptionsData(newOptionsData);
|
2024-06-20 17:21:04 +05:30
|
|
|
} else {
|
|
|
|
|
setVariablesToGetUpdated((prev) =>
|
|
|
|
|
prev.filter((name) => name !== variableData.name),
|
|
|
|
|
);
|
2023-01-25 13:22:57 +05:30
|
|
|
}
|
|
|
|
|
}
|
2022-09-09 17:43:25 +05:30
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
} else if (variableData.type === 'CUSTOM') {
|
2023-12-15 13:10:02 +05:30
|
|
|
const optionsData = sortValues(
|
|
|
|
|
commaValuesParser(variableData.customValue || ''),
|
|
|
|
|
variableData.sort,
|
|
|
|
|
) as never;
|
|
|
|
|
|
|
|
|
|
setOptionsData(optionsData);
|
2022-09-09 17:43:25 +05:30
|
|
|
}
|
2023-11-30 13:56:49 +05:30
|
|
|
};
|
|
|
|
|
|
2025-01-09 23:24:18 +05:30
|
|
|
const { isLoading } = useQuery(
|
|
|
|
|
[
|
|
|
|
|
REACT_QUERY_KEY.DASHBOARD_BY_ID,
|
|
|
|
|
variableData.name || '',
|
|
|
|
|
`${minTime}`,
|
|
|
|
|
`${maxTime}`,
|
|
|
|
|
JSON.stringify(dependencyData?.order),
|
|
|
|
|
],
|
|
|
|
|
{
|
|
|
|
|
enabled:
|
|
|
|
|
variableData &&
|
|
|
|
|
variableData.type === 'QUERY' &&
|
|
|
|
|
checkAPIInvocation(
|
|
|
|
|
variablesToGetUpdated,
|
|
|
|
|
variableData,
|
|
|
|
|
dependencyData?.parentDependencyGraph,
|
|
|
|
|
),
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
dashboardVariablesQuery({
|
|
|
|
|
query: variableData.queryValue || '',
|
|
|
|
|
variables: variablePropsToPayloadVariables(existingVariables),
|
|
|
|
|
}),
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
onSuccess: (response) => {
|
|
|
|
|
getOptions(response.payload);
|
|
|
|
|
setVariablesToGetUpdated((prev) =>
|
|
|
|
|
prev.filter((v) => v !== variableData.name),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
onError: (error: {
|
|
|
|
|
details: {
|
|
|
|
|
error: string;
|
|
|
|
|
};
|
|
|
|
|
}) => {
|
|
|
|
|
const { details } = error;
|
|
|
|
|
|
|
|
|
|
if (details.error) {
|
|
|
|
|
let message = details.error;
|
2025-06-04 11:50:51 +05:30
|
|
|
if ((details.error ?? '').toString().includes('Syntax error:')) {
|
2025-01-09 23:24:18 +05:30
|
|
|
message =
|
|
|
|
|
'Please make sure query is valid and dependent variables are selected';
|
|
|
|
|
}
|
|
|
|
|
setErrorMessage(message);
|
2023-11-30 13:56:49 +05:30
|
|
|
}
|
2025-02-15 00:23:33 +05:30
|
|
|
setVariablesToGetUpdated((prev) =>
|
|
|
|
|
prev.filter((v) => v !== variableData.name),
|
|
|
|
|
);
|
2025-01-09 23:24:18 +05:30
|
|
|
},
|
2023-11-30 13:56:49 +05:30
|
|
|
},
|
2025-01-09 23:24:18 +05:30
|
|
|
);
|
2022-09-09 17:43:25 +05:30
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
const handleChange = useCallback(
|
|
|
|
|
(inputValue: string | string[]): void => {
|
|
|
|
|
const value = variableData.multiSelect && !inputValue ? [] : inputValue;
|
2025-03-10 14:18:55 +05:30
|
|
|
|
2023-05-02 18:51:24 +05:30
|
|
|
if (
|
2025-05-15 00:31:13 +05:30
|
|
|
value === variableData.selectedValue ||
|
|
|
|
|
(Array.isArray(value) &&
|
|
|
|
|
Array.isArray(variableData.selectedValue) &&
|
|
|
|
|
areArraysEqual(value, variableData.selectedValue))
|
2023-05-02 18:51:24 +05:30
|
|
|
) {
|
2025-05-15 00:31:13 +05:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (variableData.name) {
|
|
|
|
|
if (
|
|
|
|
|
value === ALL_SELECT_VALUE ||
|
|
|
|
|
(Array.isArray(value) && value.includes(ALL_SELECT_VALUE))
|
|
|
|
|
) {
|
|
|
|
|
onValueUpdate(variableData.name, variableData.id, optionsData, true);
|
|
|
|
|
} else {
|
|
|
|
|
onValueUpdate(variableData.name, variableData.id, value, false);
|
|
|
|
|
}
|
2023-05-02 18:51:24 +05:30
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
},
|
|
|
|
|
[
|
|
|
|
|
variableData.multiSelect,
|
|
|
|
|
variableData.selectedValue,
|
|
|
|
|
variableData.name,
|
|
|
|
|
variableData.id,
|
|
|
|
|
onValueUpdate,
|
|
|
|
|
optionsData,
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add a handler for tracking temporary selection changes
|
|
|
|
|
const handleTempChange = (inputValue: string | string[]): void => {
|
|
|
|
|
// Store the selection in temporary state while dropdown is open
|
|
|
|
|
const value = variableData.multiSelect && !inputValue ? [] : inputValue;
|
|
|
|
|
setTempSelection(value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Handle dropdown visibility changes
|
|
|
|
|
const handleDropdownVisibleChange = (visible: boolean): void => {
|
|
|
|
|
// Initialize temp selection when opening dropdown
|
|
|
|
|
if (visible) {
|
|
|
|
|
setTempSelection(getSelectValue(variableData.selectedValue, variableData));
|
|
|
|
|
}
|
|
|
|
|
// Apply changes when closing dropdown
|
|
|
|
|
else if (!visible && tempSelection !== undefined) {
|
|
|
|
|
// Call handleChange with the temporarily stored selection
|
|
|
|
|
handleChange(tempSelection);
|
|
|
|
|
setTempSelection(undefined);
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2022-09-09 17:43:25 +05:30
|
|
|
};
|
2023-01-25 13:22:57 +05:30
|
|
|
|
2024-01-25 23:12:19 +05:30
|
|
|
// do not debounce the above function as we do not need debounce in select variables
|
|
|
|
|
const debouncedHandleChange = debounce(handleChange, 500);
|
|
|
|
|
|
2023-08-02 12:09:49 +02:00
|
|
|
const { selectedValue } = variableData;
|
2024-06-18 13:02:15 +05:30
|
|
|
const selectedValueStringified = useMemo(
|
|
|
|
|
() => getSelectValue(selectedValue, variableData),
|
|
|
|
|
[selectedValue, variableData],
|
|
|
|
|
);
|
2023-08-02 12:09:49 +02:00
|
|
|
|
2024-06-18 13:02:15 +05:30
|
|
|
const enableSelectAll = variableData.multiSelect && variableData.showALLOption;
|
|
|
|
|
|
|
|
|
|
const selectValue =
|
|
|
|
|
variableData.allSelected && enableSelectAll
|
|
|
|
|
? 'ALL'
|
|
|
|
|
: selectedValueStringified;
|
2023-08-02 12:09:49 +02:00
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
// Apply default value on first render if no selection exists
|
|
|
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
|
|
|
const finalSelectedValues = useMemo(() => {
|
|
|
|
|
if (variableData.multiSelect) {
|
|
|
|
|
let value = tempSelection || selectedValue;
|
|
|
|
|
if (isEmpty(value)) {
|
|
|
|
|
if (variableData.showALLOption) {
|
|
|
|
|
if (variableData.defaultValue) {
|
|
|
|
|
value = variableData.defaultValue;
|
|
|
|
|
} else {
|
|
|
|
|
value = optionsData;
|
|
|
|
|
}
|
|
|
|
|
} else if (variableData.defaultValue) {
|
|
|
|
|
value = variableData.defaultValue;
|
|
|
|
|
} else {
|
|
|
|
|
value = optionsData?.[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-18 13:02:15 +05:30
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
return value;
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
if (isEmpty(selectedValue)) {
|
|
|
|
|
if (variableData.defaultValue) {
|
|
|
|
|
return variableData.defaultValue;
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
return optionsData[0]?.toString();
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
|
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
return selectedValue;
|
|
|
|
|
}, [
|
|
|
|
|
variableData.multiSelect,
|
|
|
|
|
variableData.showALLOption,
|
|
|
|
|
variableData.defaultValue,
|
|
|
|
|
selectedValue,
|
|
|
|
|
tempSelection,
|
|
|
|
|
optionsData,
|
|
|
|
|
]);
|
2024-06-18 13:02:15 +05:30
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
useEffect(() => {
|
2024-06-18 13:02:15 +05:30
|
|
|
if (
|
2025-05-15 00:31:13 +05:30
|
|
|
(variableData.multiSelect && !(tempSelection || selectValue)) ||
|
|
|
|
|
isEmpty(selectValue)
|
2024-06-18 13:02:15 +05:30
|
|
|
) {
|
2025-05-15 00:31:13 +05:30
|
|
|
handleChange(finalSelectedValues as string[] | string);
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
}, [
|
|
|
|
|
finalSelectedValues,
|
|
|
|
|
handleChange,
|
|
|
|
|
selectValue,
|
|
|
|
|
tempSelection,
|
|
|
|
|
variableData.multiSelect,
|
|
|
|
|
]);
|
2024-06-18 13:02:15 +05:30
|
|
|
|
2025-05-15 00:31:13 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
// Fetch options for CUSTOM Type
|
|
|
|
|
if (variableData.type === 'CUSTOM') {
|
|
|
|
|
getOptions(null);
|
2024-06-18 13:02:15 +05:30
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [variableData.type, variableData.customValue]);
|
2024-06-18 13:02:15 +05:30
|
|
|
|
2022-09-09 17:43:25 +05:30
|
|
|
return (
|
2024-05-28 19:09:04 +05:30
|
|
|
<div className="variable-item">
|
2024-03-15 12:28:03 +05:30
|
|
|
<Typography.Text className="variable-name" ellipsis>
|
|
|
|
|
${variableData.name}
|
2025-05-16 16:46:19 +05:30
|
|
|
{variableData.description && (
|
|
|
|
|
<Tooltip title={variableData.description}>
|
|
|
|
|
<InfoCircleOutlined className="info-icon" />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
2024-03-15 12:28:03 +05:30
|
|
|
</Typography.Text>
|
2025-05-16 16:46:19 +05:30
|
|
|
|
2024-05-28 19:09:04 +05:30
|
|
|
<div className="variable-value">
|
2024-03-15 12:28:03 +05:30
|
|
|
{variableData.type === 'TEXTBOX' ? (
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="Enter value"
|
|
|
|
|
bordered={false}
|
|
|
|
|
key={variableData.selectedValue?.toString()}
|
|
|
|
|
defaultValue={variableData.selectedValue?.toString()}
|
|
|
|
|
onChange={(e): void => {
|
|
|
|
|
debouncedHandleChange(e.target.value || '');
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
width:
|
|
|
|
|
50 + ((variableData.selectedValue?.toString()?.length || 0) * 7 || 50),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2025-05-15 00:31:13 +05:30
|
|
|
optionsData &&
|
|
|
|
|
(variableData.multiSelect ? (
|
|
|
|
|
<CustomMultiSelect
|
2024-03-15 12:28:03 +05:30
|
|
|
key={
|
|
|
|
|
selectValue && Array.isArray(selectValue)
|
|
|
|
|
? selectValue.join(' ')
|
|
|
|
|
: selectValue || variableData.id
|
|
|
|
|
}
|
2025-05-15 00:31:13 +05:30
|
|
|
options={optionsData.map((option) => ({
|
|
|
|
|
label: option.toString(),
|
|
|
|
|
value: option.toString(),
|
|
|
|
|
}))}
|
|
|
|
|
defaultValue={variableData.defaultValue || selectValue}
|
|
|
|
|
onChange={handleTempChange}
|
2023-11-30 13:56:49 +05:30
|
|
|
bordered={false}
|
2024-03-15 12:28:03 +05:30
|
|
|
placeholder="Select value"
|
2024-06-18 13:02:15 +05:30
|
|
|
placement="bottomLeft"
|
2024-03-15 12:28:03 +05:30
|
|
|
style={SelectItemStyle}
|
|
|
|
|
loading={isLoading}
|
|
|
|
|
showSearch
|
|
|
|
|
data-testid="variable-select"
|
|
|
|
|
className="variable-select"
|
2024-06-18 13:02:15 +05:30
|
|
|
popupClassName="dropdown-styles"
|
2025-05-15 00:31:13 +05:30
|
|
|
maxTagCount={2}
|
2024-03-15 12:28:03 +05:30
|
|
|
getPopupContainer={popupContainer}
|
2025-05-15 00:31:13 +05:30
|
|
|
value={tempSelection || selectValue}
|
|
|
|
|
onDropdownVisibleChange={handleDropdownVisibleChange}
|
|
|
|
|
errorMessage={errorMessage}
|
2024-06-18 13:02:15 +05:30
|
|
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
|
|
|
maxTagPlaceholder={(omittedValues): JSX.Element => (
|
|
|
|
|
<Tooltip title={omittedValues.map(({ value }) => value).join(', ')}>
|
|
|
|
|
<span>+ {omittedValues.length} </span>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
2025-05-15 00:31:13 +05:30
|
|
|
onClear={(): void => {
|
|
|
|
|
handleChange([]);
|
|
|
|
|
}}
|
|
|
|
|
enableAllSelection={enableSelectAll}
|
|
|
|
|
maxTagTextLength={30}
|
2025-05-17 00:48:41 +05:30
|
|
|
allowClear={selectValue !== ALL_SELECT_VALUE && selectValue !== 'ALL'}
|
2025-05-15 00:31:13 +05:30
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<CustomSelect
|
|
|
|
|
key={
|
|
|
|
|
selectValue && Array.isArray(selectValue)
|
|
|
|
|
? selectValue.join(' ')
|
|
|
|
|
: selectValue || variableData.id
|
|
|
|
|
}
|
|
|
|
|
defaultValue={variableData.defaultValue || selectValue}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
bordered={false}
|
|
|
|
|
placeholder="Select value"
|
|
|
|
|
style={SelectItemStyle}
|
|
|
|
|
loading={isLoading}
|
|
|
|
|
showSearch
|
|
|
|
|
data-testid="variable-select"
|
|
|
|
|
className="variable-select"
|
|
|
|
|
popupClassName="dropdown-styles"
|
|
|
|
|
getPopupContainer={popupContainer}
|
|
|
|
|
options={optionsData.map((option) => ({
|
|
|
|
|
label: option.toString(),
|
|
|
|
|
value: option.toString(),
|
|
|
|
|
}))}
|
|
|
|
|
value={selectValue}
|
|
|
|
|
errorMessage={errorMessage}
|
|
|
|
|
/>
|
|
|
|
|
))
|
2024-03-15 12:28:03 +05:30
|
|
|
)}
|
|
|
|
|
{variableData.type !== 'TEXTBOX' && errorMessage && (
|
|
|
|
|
<span style={{ margin: '0 0.5rem' }}>
|
|
|
|
|
<Popover
|
|
|
|
|
placement="top"
|
|
|
|
|
content={<Typography>{errorMessage}</Typography>}
|
|
|
|
|
>
|
|
|
|
|
<WarningOutlined style={{ color: orange[5] }} />
|
|
|
|
|
</Popover>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-05-28 19:09:04 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-09-09 17:43:25 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 13:53:53 +05:30
|
|
|
export default memo(VariableItem);
|