({
id,
condition,
onChange,
onRemove,
isOnly,
categoryOptions,
disabledFields,
disabledStateValues,
groupOptions,
}: LeafConditionProps)
| 129 | } |
| 130 | |
| 131 | export function LeafCondition({ |
| 132 | id, |
| 133 | condition, |
| 134 | onChange, |
| 135 | onRemove, |
| 136 | isOnly, |
| 137 | categoryOptions, |
| 138 | disabledFields, |
| 139 | disabledStateValues, |
| 140 | groupOptions, |
| 141 | }: LeafConditionProps) { |
| 142 | const { t } = useTranslation("automations"); |
| 143 | const { |
| 144 | attributes, |
| 145 | listeners, |
| 146 | setNodeRef, |
| 147 | transform, |
| 148 | isDragging, |
| 149 | } = useSortable({ id }); |
| 150 | |
| 151 | const style = { |
| 152 | transform: CSS.Translate.toString(transform), |
| 153 | }; |
| 154 | |
| 155 | const fieldType = condition.field ? getFieldType(condition.field) : "string"; |
| 156 | const operators = condition.field ? getTranslatedOperatorsForField(condition.field, t) : []; |
| 157 | const isGroupingField = isGroupingConditionField(condition.field); |
| 158 | const availableGroupOptions = (groupOptions && groupOptions.length > 0)? groupOptions: [{ id: DEFAULT_GROUP_ID, label: t("queryBuilder.defaultGroupLabel") }]; |
| 159 | const groupIdValue = condition.groupId || DEFAULT_GROUP_ID; |
| 160 | |
| 161 | // Track duration unit separately so it persists when value is empty |
| 162 | const [durationUnit, setDurationUnit] = useState<number>(() => |
| 163 | detectDurationUnit(parseFloat(condition.value ?? "0") || 0) |
| 164 | ); |
| 165 | |
| 166 | // Track speed unit separately so it persists when value is empty |
| 167 | const [speedUnit, setSpeedUnit] = useState<number>(() => { |
| 168 | // Initialize from existing value if present, default to MiB/s |
| 169 | const bytesPerSec = parseFloat(condition.value ?? "0") || 0; |
| 170 | const mib = 1024 * 1024; |
| 171 | const kib = 1024; |
| 172 | if (bytesPerSec >= mib && bytesPerSec % mib === 0) return mib; |
| 173 | if (bytesPerSec >= kib && bytesPerSec % kib === 0) return kib; |
| 174 | if (bytesPerSec === 0) return mib; // Default to MiB/s for new conditions |
| 175 | return 1; |
| 176 | }); |
| 177 | |
| 178 | // Track duration unit for BETWEEN operator (shared for min/max) |
| 179 | const [betweenDurationUnit, setBetweenDurationUnit] = useState<number>(() => |
| 180 | detectDurationUnit(condition.minValue ?? condition.maxValue ?? 0) |
| 181 | ); |
| 182 | |
| 183 | // Track bytes unit separately so it persists when value is empty |
| 184 | const [bytesUnit, setBytesUnit] = useState<number>(() => |
| 185 | detectBytesUnit(parseFloat(condition.value ?? "0") || 0) |
| 186 | ); |
| 187 | |
| 188 | // Track bytes unit for BETWEEN operator (shared for min/max) |
nothing calls this directly
no test coverage detected