import React, { useState } from 'react'; import { Select } from '@grafana/ui'; import { SelectableValue } from '../../../../../packages/grafana-data/src'; import { RuleSettingsEditor } from './RuleSettingsEditor'; import { RuleType, RuleSetting, PipeLineEntitiesInfo } from './types'; interface Props { ruleType: RuleType; onChange: (value: RuleSetting[]) => void; value: RuleSetting[]; entitiesInfo: PipeLineEntitiesInfo; } export const RuleSettingsArray: React.FC = ({ onChange, value, ruleType, entitiesInfo }) => { const [index, setIndex] = useState(0); const arr = value ?? []; const onRuleChange = (v: RuleSetting) => { if (!value) { onChange([v]); } else { const copy = [...value]; copy[index] = v; onChange(copy); } }; // create array of value.length + 1 let indexArr: Array> = []; for (let i = 0; i <= arr.length; i++) { indexArr.push({ label: `${ruleType}: ${i}`, value: i, }); } return ( <> ); };