import { startCase } from 'lodash'; import React from 'react'; import type { ICapacity } from '../../index'; export interface IMinMaxDesiredChangesProps { current: ICapacity; next: ICapacity; } export function MinMaxDesiredChanges(props: IMinMaxDesiredChangesProps) { const { current, next } = props; const fields: Array = ['min', 'max', 'desired']; const changedCapacityFields = fields .map((field) => { const hasChanged = current[field] !== next[field]; return hasChanged ? { field, currentValue: current[field], nextValue: next[field] } : null; }) .filter((x) => !!x); if (!changedCapacityFields.length) { return No changes; } return ( <> {changedCapacityFields.map((field) => (
{startCase(field.field)}: {field.currentValue} {' '} {field.nextValue}
))} ); }