mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
refactor: improve constraint date formatting (#789)
* refactor: fix add constraint button text * refactor: improve constraint date formatting * refactor: the value, it must be
This commit is contained in:
parent
75ca8077e3
commit
a202b81344
@ -11,6 +11,8 @@ import ConditionallyRender from '../ConditionallyRender';
|
|||||||
import PermissionIconButton from '../PermissionIconButton/PermissionIconButton';
|
import PermissionIconButton from '../PermissionIconButton/PermissionIconButton';
|
||||||
import StringTruncator from '../StringTruncator/StringTruncator';
|
import StringTruncator from '../StringTruncator/StringTruncator';
|
||||||
import { useStyles } from './Constraint.styles';
|
import { useStyles } from './Constraint.styles';
|
||||||
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
|
import { formatConstraintValuesOrValue } from 'component/common/Constraint/formatConstraintValue';
|
||||||
|
|
||||||
interface IConstraintProps {
|
interface IConstraintProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint;
|
||||||
@ -29,6 +31,7 @@ const Constraint = ({
|
|||||||
// CHANGEME - Feat: Constraint Operators
|
// CHANGEME - Feat: Constraint Operators
|
||||||
const { uiConfig } = useUiConfig();
|
const { uiConfig } = useUiConfig();
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
const { projectId } = useParams<IFeatureViewParams>();
|
const { projectId } = useParams<IFeatureViewParams>();
|
||||||
|
|
||||||
const classes = classnames(styles.constraint, {
|
const classes = classnames(styles.constraint, {
|
||||||
@ -54,7 +57,10 @@ const Constraint = ({
|
|||||||
/>
|
/>
|
||||||
<StrategySeparator text={constraint.operator} maxWidth="none" />
|
<StrategySeparator text={constraint.operator} maxWidth="none" />
|
||||||
<span className={styles.values}>
|
<span className={styles.values}>
|
||||||
{constraint.values?.join(', ') ?? constraint.value}
|
{formatConstraintValuesOrValue(
|
||||||
|
constraint,
|
||||||
|
locationSettings
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
import { IConstraint } from 'interfaces/strategy';
|
||||||
|
import { CURRENT_TIME_CONTEXT_FIELD } from 'component/common/ConstraintAccordion/ConstraintAccordionEdit/ConstraintAccordionEditHeader/ConstraintAccordionEditHeader';
|
||||||
|
import { formatDateYMDHMS } from 'utils/format-date';
|
||||||
|
import { ILocationSettings } from 'hooks/useLocationSettings';
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
@ -31,7 +31,7 @@ const constraintOperators = allOperators.map(operator => {
|
|||||||
return { key: operator, label: operator };
|
return { key: operator, label: operator };
|
||||||
});
|
});
|
||||||
|
|
||||||
const CURRENT_TIME_CONTEXT_FIELD = 'currentTime';
|
export const CURRENT_TIME_CONTEXT_FIELD = 'currentTime';
|
||||||
|
|
||||||
export const ConstraintAccordionEditHeader = ({
|
export const ConstraintAccordionEditHeader = ({
|
||||||
compact,
|
compact,
|
||||||
|
@ -8,6 +8,8 @@ import { oneOf } from '../../../../../utils/one-of';
|
|||||||
import ConditionallyRender from '../../../ConditionallyRender';
|
import ConditionallyRender from '../../../ConditionallyRender';
|
||||||
import { useStyles } from '../../ConstraintAccordion.styles';
|
import { useStyles } from '../../ConstraintAccordion.styles';
|
||||||
import { ConstraintValueSearch } from '../../ConstraintValueSearch/ConstraintValueSearch';
|
import { ConstraintValueSearch } from '../../ConstraintValueSearch/ConstraintValueSearch';
|
||||||
|
import { formatConstraintValue } from 'component/common/Constraint/formatConstraintValue';
|
||||||
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
|
|
||||||
interface IConstraintAccordionViewBodyProps {
|
interface IConstraintAccordionViewBodyProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint;
|
||||||
@ -17,6 +19,7 @@ export const ConstraintAccordionViewBody = ({
|
|||||||
constraint,
|
constraint,
|
||||||
}: IConstraintAccordionViewBodyProps) => {
|
}: IConstraintAccordionViewBodyProps) => {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -46,7 +49,7 @@ export const ConstraintAccordionViewBody = ({
|
|||||||
<div className={styles.valuesContainer}>
|
<div className={styles.valuesContainer}>
|
||||||
<MultipleValues values={constraint.values} />
|
<MultipleValues values={constraint.values} />
|
||||||
<SingleValue
|
<SingleValue
|
||||||
value={constraint.value}
|
value={formatConstraintValue(constraint, locationSettings)}
|
||||||
operator={constraint.operator}
|
operator={constraint.operator}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -65,7 +68,7 @@ const SingleValue = ({ value, operator }: ISingleValueProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.singleValueView}>
|
<div className={styles.singleValueView}>
|
||||||
<p className={styles.singleValueText}>Value must {operator}</p>{' '}
|
<p className={styles.singleValueText}>Value must be {operator}</p>{' '}
|
||||||
<Chip
|
<Chip
|
||||||
label={
|
label={
|
||||||
<StringTruncator
|
<StringTruncator
|
||||||
|
@ -11,6 +11,8 @@ import { UPDATE_FEATURE_STRATEGY } from 'component/providers/AccessProvider/perm
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { IFeatureViewParams } from 'interfaces/params';
|
import { IFeatureViewParams } from 'interfaces/params';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { formatConstraintValue } from 'component/common/Constraint/formatConstraintValue';
|
||||||
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
|
|
||||||
interface IConstraintAccordionViewHeaderProps {
|
interface IConstraintAccordionViewHeaderProps {
|
||||||
compact: boolean;
|
compact: boolean;
|
||||||
@ -30,6 +32,7 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
environmentId,
|
environmentId,
|
||||||
}: IConstraintAccordionViewHeaderProps) => {
|
}: IConstraintAccordionViewHeaderProps) => {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
const { projectId } = useParams<IFeatureViewParams>();
|
const { projectId } = useParams<IFeatureViewParams>();
|
||||||
const smallScreen = useMediaQuery(`(max-width:${790}px)`);
|
const smallScreen = useMediaQuery(`(max-width:${790}px)`);
|
||||||
|
|
||||||
@ -67,7 +70,14 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
<div className={styles.headerViewValuesContainer}>
|
<div className={styles.headerViewValuesContainer}>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={singleValue}
|
condition={singleValue}
|
||||||
show={<Chip label={constraint.value} />}
|
show={
|
||||||
|
<Chip
|
||||||
|
label={formatConstraintValue(
|
||||||
|
constraint,
|
||||||
|
locationSettings
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
elseShow={
|
elseShow={
|
||||||
<div className={styles.headerValuesContainer}>
|
<div className={styles.headerValuesContainer}>
|
||||||
<p className={styles.headerValues}>
|
<p className={styles.headerValues}>
|
||||||
|
@ -96,7 +96,7 @@ export const FeatureStrategyConstraints2 = ({
|
|||||||
environmentId={environmentId}
|
environmentId={environmentId}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
>
|
>
|
||||||
Add constraints
|
Add constraint
|
||||||
</PermissionButton>
|
</PermissionButton>
|
||||||
{strategy.constraints?.map((constraint, index) => (
|
{strategy.constraints?.map((constraint, index) => (
|
||||||
<ConstraintAccordion
|
<ConstraintAccordion
|
||||||
|
Loading…
Reference in New Issue
Block a user