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';
|
|
|
|
|
import { WarningOutlined } from '@ant-design/icons';
|
2024-06-18 13:02:15 +05:30
|
|
|
import {
|
|
|
|
|
Checkbox,
|
|
|
|
|
Input,
|
|
|
|
|
Popover,
|
|
|
|
|
Select,
|
|
|
|
|
Tag,
|
|
|
|
|
Tooltip,
|
|
|
|
|
Typography,
|
|
|
|
|
} from 'antd';
|
|
|
|
|
import { CheckboxChangeEvent } from 'antd/es/checkbox';
|
2023-11-30 13:56:49 +05:30
|
|
|
import dashboardVariablesQuery from 'api/dashboard/variables/dashboardVariablesQuery';
|
|
|
|
|
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';
|
2024-06-04 11:18:44 +05:30
|
|
|
import { debounce, isArray, isString } from 'lodash-es';
|
2023-05-02 18:51:24 +05:30
|
|
|
import map from 'lodash-es/map';
|
2024-06-18 13:02:15 +05:30
|
|
|
import { ChangeEvent, memo, 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
|
|
|
|
2023-01-25 13:22:57 +05:30
|
|
|
import { variablePropsToPayloadVariables } from '../utils';
|
2024-05-28 19:09:04 +05:30
|
|
|
import { SelectItemStyle } from './styles';
|
2025-01-02 15:45:01 +05:30
|
|
|
import { areArraysEqual, checkAPIInvocation, IDependencyData } from './util';
|
2022-09-09 17:43:25 +05:30
|
|
|
|
|
|
|
|
const ALL_SELECT_VALUE = '__ALL__';
|
|
|
|
|
|
2024-06-18 13:02:15 +05:30
|
|
|
enum ToggleTagValue {
|
|
|
|
|
Only = 'Only',
|
|
|
|
|
All = 'All',
|
|
|
|
|
}
|
|
|
|
|
|
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-02 15:45:01 +05:30
|
|
|
dependencyData: IDependencyData | null;
|
2022-09-09 17:43:25 +05:30
|
|
|
}
|
2023-08-02 12:09:49 +02:00
|
|
|
|
|
|
|
|
const getSelectValue = (
|
|
|
|
|
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-02 15:45:01 +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)[]>(
|
|
|
|
|
[],
|
|
|
|
|
);
|
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-02 15:45:01 +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-02 15:45:01 +05:30
|
|
|
// variableData.name is present as the top element or next in the queue - variablesToGetUpdated
|
|
|
|
|
return Boolean(
|
|
|
|
|
variablesToGetUpdated.length &&
|
|
|
|
|
variablesToGetUpdated[0] === variableData.name,
|
2023-11-30 13:56:49 +05:30
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-02 15:45:01 +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-02 15:45:01 +05:30
|
|
|
(validVariableUpdate() || valueNotInList || variableData.allSelected)
|
2023-01-25 13:22:57 +05:30
|
|
|
) {
|
|
|
|
|
let value = variableData.selectedValue;
|
|
|
|
|
let allSelected = false;
|
|
|
|
|
// The default value for multi-select is ALL and first value for
|
|
|
|
|
// single select
|
|
|
|
|
if (variableData.multiSelect) {
|
|
|
|
|
value = newOptionsData;
|
|
|
|
|
allSelected = true;
|
|
|
|
|
} else {
|
|
|
|
|
[value] = newOptionsData;
|
|
|
|
|
}
|
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-02 15:45:01 +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;
|
|
|
|
|
if (details.error.includes('Syntax error:')) {
|
|
|
|
|
message =
|
|
|
|
|
'Please make sure query is valid and dependent variables are selected';
|
|
|
|
|
}
|
|
|
|
|
setErrorMessage(message);
|
2023-11-30 13:56:49 +05:30
|
|
|
}
|
2025-01-02 15:45:01 +05:30
|
|
|
},
|
2023-11-30 13:56:49 +05:30
|
|
|
},
|
2025-01-02 15:45:01 +05:30
|
|
|
);
|
2022-09-09 17:43:25 +05:30
|
|
|
|
|
|
|
|
const handleChange = (value: string | string[]): void => {
|
2025-01-02 15:45:01 +05:30
|
|
|
// if value is equal to selected value then return
|
|
|
|
|
if (
|
|
|
|
|
value === variableData.selectedValue ||
|
|
|
|
|
(Array.isArray(value) &&
|
|
|
|
|
Array.isArray(variableData.selectedValue) &&
|
|
|
|
|
areArraysEqual(value, variableData.selectedValue))
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-18 13:02:15 +05:30
|
|
|
if (variableData.name) {
|
2023-05-02 18:51:24 +05:30
|
|
|
if (
|
|
|
|
|
value === ALL_SELECT_VALUE ||
|
2024-10-16 11:22:30 +05:30
|
|
|
(Array.isArray(value) && value.includes(ALL_SELECT_VALUE))
|
2023-05-02 18:51:24 +05:30
|
|
|
) {
|
2023-12-15 13:10:02 +05:30
|
|
|
onValueUpdate(variableData.name, variableData.id, optionsData, true);
|
2023-05-02 18:51:24 +05:30
|
|
|
} else {
|
2023-12-15 13:10:02 +05:30
|
|
|
onValueUpdate(variableData.name, variableData.id, value, false);
|
2023-05-02 18:51:24 +05:30
|
|
|
}
|
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
|
|
|
|
2024-06-18 13:02:15 +05:30
|
|
|
const mode: 'multiple' | undefined =
|
2023-01-25 13:22:57 +05:30
|
|
|
variableData.multiSelect && !variableData.allSelected
|
|
|
|
|
? 'multiple'
|
|
|
|
|
: undefined;
|
2023-11-30 13:56:49 +05:30
|
|
|
|
2023-12-05 16:09:50 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
// Fetch options for CUSTOM Type
|
|
|
|
|
if (variableData.type === 'CUSTOM') {
|
|
|
|
|
getOptions(null);
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2023-12-15 13:10:02 +05:30
|
|
|
}, [variableData.type, variableData.customValue]);
|
2023-12-05 16:09:50 +05:30
|
|
|
|
2024-06-18 13:02:15 +05:30
|
|
|
const checkAll = (e: MouseEvent): void => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const isChecked =
|
2024-09-25 11:32:19 +05:30
|
|
|
variableData.allSelected || selectValue?.includes(ALL_SELECT_VALUE);
|
2024-06-18 13:02:15 +05:30
|
|
|
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
handleChange([]);
|
|
|
|
|
} else {
|
|
|
|
|
handleChange(ALL_SELECT_VALUE);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleOptionSelect = (
|
|
|
|
|
e: CheckboxChangeEvent,
|
|
|
|
|
option: string | number | boolean,
|
|
|
|
|
): void => {
|
|
|
|
|
const newSelectedValue = Array.isArray(selectedValue)
|
|
|
|
|
? ((selectedValue.filter(
|
|
|
|
|
(val) => val.toString() !== option.toString(),
|
|
|
|
|
) as unknown) as string[])
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!e.target.checked &&
|
|
|
|
|
Array.isArray(selectedValueStringified) &&
|
|
|
|
|
selectedValueStringified.includes(option.toString())
|
|
|
|
|
) {
|
|
|
|
|
if (newSelectedValue.length === 1) {
|
|
|
|
|
handleChange(newSelectedValue[0].toString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
handleChange(newSelectedValue);
|
|
|
|
|
} else if (!e.target.checked && selectedValue === option.toString()) {
|
|
|
|
|
handleChange(ALL_SELECT_VALUE);
|
|
|
|
|
} else if (newSelectedValue.length === optionsData.length - 1) {
|
|
|
|
|
handleChange(ALL_SELECT_VALUE);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [optionState, setOptionState] = useState({
|
|
|
|
|
tag: '',
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function currentToggleTagValue({
|
|
|
|
|
option,
|
|
|
|
|
}: {
|
|
|
|
|
option: string;
|
|
|
|
|
}): ToggleTagValue {
|
|
|
|
|
if (
|
|
|
|
|
option.toString() === selectValue ||
|
|
|
|
|
(Array.isArray(selectValue) &&
|
|
|
|
|
selectValue?.includes(option.toString()) &&
|
|
|
|
|
selectValue.length === 1)
|
|
|
|
|
) {
|
|
|
|
|
return ToggleTagValue.All;
|
|
|
|
|
}
|
|
|
|
|
return ToggleTagValue.Only;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleToggle(e: ChangeEvent, option: string): void {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
const mode = currentToggleTagValue({ option: option as string });
|
|
|
|
|
const isChecked =
|
|
|
|
|
variableData.allSelected ||
|
|
|
|
|
option.toString() === selectValue ||
|
|
|
|
|
(Array.isArray(selectValue) && selectValue?.includes(option.toString()));
|
|
|
|
|
|
|
|
|
|
if (isChecked) {
|
2024-09-19 19:23:12 +05:30
|
|
|
if (mode === ToggleTagValue.Only && variableData.multiSelect) {
|
|
|
|
|
handleChange([option.toString()]);
|
2024-06-18 13:02:15 +05:30
|
|
|
} else if (!variableData.multiSelect) {
|
|
|
|
|
handleChange(option.toString());
|
|
|
|
|
} else {
|
|
|
|
|
handleChange(ALL_SELECT_VALUE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
handleChange(option.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function retProps(
|
|
|
|
|
option: string,
|
|
|
|
|
): {
|
|
|
|
|
onMouseOver: () => void;
|
|
|
|
|
onMouseOut: () => void;
|
|
|
|
|
} {
|
|
|
|
|
return {
|
|
|
|
|
onMouseOver: (): void =>
|
|
|
|
|
setOptionState({
|
|
|
|
|
tag: option.toString(),
|
|
|
|
|
visible: true,
|
|
|
|
|
}),
|
|
|
|
|
onMouseOut: (): void =>
|
|
|
|
|
setOptionState({
|
|
|
|
|
tag: option.toString(),
|
|
|
|
|
visible: false,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ensureValidOption = (option: string): boolean =>
|
|
|
|
|
!(
|
|
|
|
|
currentToggleTagValue({ option }) === ToggleTagValue.All && !enableSelectAll
|
|
|
|
|
);
|
|
|
|
|
|
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}
|
|
|
|
|
</Typography.Text>
|
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),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
!errorMessage &&
|
|
|
|
|
optionsData && (
|
|
|
|
|
<Select
|
|
|
|
|
key={
|
|
|
|
|
selectValue && Array.isArray(selectValue)
|
|
|
|
|
? selectValue.join(' ')
|
|
|
|
|
: selectValue || variableData.id
|
|
|
|
|
}
|
|
|
|
|
defaultValue={selectValue}
|
|
|
|
|
onChange={handleChange}
|
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
|
|
|
mode={mode}
|
|
|
|
|
style={SelectItemStyle}
|
|
|
|
|
loading={isLoading}
|
|
|
|
|
showSearch
|
|
|
|
|
data-testid="variable-select"
|
|
|
|
|
className="variable-select"
|
2024-06-18 13:02:15 +05:30
|
|
|
popupClassName="dropdown-styles"
|
|
|
|
|
maxTagCount={4}
|
2024-03-15 12:28:03 +05:30
|
|
|
getPopupContainer={popupContainer}
|
2024-06-18 13:02:15 +05:30
|
|
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
|
|
|
tagRender={(props): JSX.Element => (
|
|
|
|
|
<Tag closable onClose={props.onClose}>
|
|
|
|
|
{props.value}
|
|
|
|
|
</Tag>
|
|
|
|
|
)}
|
|
|
|
|
// 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>
|
|
|
|
|
)}
|
2024-09-25 11:32:19 +05:30
|
|
|
allowClear
|
2024-03-15 12:28:03 +05:30
|
|
|
>
|
|
|
|
|
{enableSelectAll && (
|
|
|
|
|
<Select.Option data-testid="option-ALL" value={ALL_SELECT_VALUE}>
|
2024-06-18 13:02:15 +05:30
|
|
|
<div className="all-label" onClick={(e): void => checkAll(e as any)}>
|
|
|
|
|
<Checkbox checked={variableData.allSelected} />
|
|
|
|
|
ALL
|
|
|
|
|
</div>
|
2024-03-15 12:28:03 +05:30
|
|
|
</Select.Option>
|
|
|
|
|
)}
|
|
|
|
|
{map(optionsData, (option) => (
|
|
|
|
|
<Select.Option
|
|
|
|
|
data-testid={`option-${option}`}
|
|
|
|
|
key={option.toString()}
|
|
|
|
|
value={option}
|
|
|
|
|
>
|
2024-06-18 13:02:15 +05:30
|
|
|
<div
|
|
|
|
|
className={variableData.multiSelect ? 'dropdown-checkbox-label' : ''}
|
|
|
|
|
>
|
|
|
|
|
{variableData.multiSelect && (
|
|
|
|
|
<Checkbox
|
|
|
|
|
onChange={(e): void => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleOptionSelect(e, option);
|
|
|
|
|
}}
|
|
|
|
|
checked={
|
|
|
|
|
variableData.allSelected ||
|
|
|
|
|
option.toString() === selectValue ||
|
|
|
|
|
(Array.isArray(selectValue) &&
|
|
|
|
|
selectValue?.includes(option.toString()))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<div
|
|
|
|
|
className="dropdown-value"
|
|
|
|
|
{...retProps(option as string)}
|
|
|
|
|
onClick={(e): void => handleToggle(e as any, option as string)}
|
|
|
|
|
>
|
2024-09-25 11:32:19 +05:30
|
|
|
<Typography.Text
|
|
|
|
|
ellipsis={{
|
|
|
|
|
tooltip: {
|
|
|
|
|
placement: variableData.multiSelect ? 'top' : 'right',
|
|
|
|
|
autoAdjustOverflow: true,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
className="option-text"
|
|
|
|
|
>
|
|
|
|
|
{option.toString()}
|
|
|
|
|
</Typography.Text>
|
2024-06-18 13:02:15 +05:30
|
|
|
|
|
|
|
|
{variableData.multiSelect &&
|
|
|
|
|
optionState.tag === option.toString() &&
|
|
|
|
|
optionState.visible &&
|
|
|
|
|
ensureValidOption(option as string) && (
|
|
|
|
|
<Typography.Text className="toggle-tag-label">
|
|
|
|
|
{currentToggleTagValue({ option: option as string })}
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-03-15 12:28:03 +05:30
|
|
|
</Select.Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
{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);
|