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