1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/utils/formatConstraintValue.ts
olav f33ca9db4b feat: expand constraint operator descriptions (2) (#858)
* refactor: remove pre-CO constraints list

* refactor: improve constraints dropdown order

* refactor: simplify prop value

* refactor: add missing space around parameter names

* refactor: remove constraint accordion box shadow

* refactor: show operator descriptions in constraints accordion

* refactor: show operator descriptions in constraints dropdown

* refactor: use ConstraintAccordionList in FeatureOverviewExecution

* refactor: add separators between operators in constraints dropdown

* refactor: remove unnecessary comment
2022-04-07 10:31:06 +02:00

37 lines
1.1 KiB
TypeScript

import { IConstraint } from 'interfaces/strategy';
import { formatDateYMDHMS } from 'utils/formatDate';
import { ILocationSettings } from 'hooks/useLocationSettings';
import { CURRENT_TIME_CONTEXT_FIELD } from 'utils/operatorsForContext';
export const formatConstraintValuesOrValue = (
constraint: IConstraint,
locationSettings: ILocationSettings
): string | undefined => {
return (
formatConstraintValues(constraint) ??
formatConstraintValue(constraint, locationSettings)
);
};
export const formatConstraintValues = (
constraint: IConstraint
): string | undefined => {
if (constraint.values && constraint.values.length > 0) {
return constraint.values.join(', ');
}
};
export const formatConstraintValue = (
constraint: IConstraint,
locationSettings: ILocationSettings
): string | undefined => {
if (
constraint.value &&
constraint.contextName === CURRENT_TIME_CONTEXT_FIELD
) {
return formatDateYMDHMS(constraint.value, locationSettings.locale);
}
return constraint.value;
};