@@ -27,6 +27,7 @@ import { defaultFlags } from 'common/stores/default-flags'
2727import Color from 'color'
2828import { selectBuildVersion } from 'common/services/useBuildVersion'
2929import { getStore } from 'common/store'
30+ import { TimeUnit } from 'components/release-pipelines/constants'
3031
3132const semver = require ( 'semver' )
3233
@@ -599,6 +600,53 @@ const Utils = Object.assign({}, require('./base/_utils'), {
599600 removeElementFromArray ( array : any [ ] , index : number ) {
600601 return array . slice ( 0 , index ) . concat ( array . slice ( index + 1 ) )
601602 } ,
603+ getExistingWaitForTime : (
604+ waitFor : string | undefined ,
605+ ) : { amountOfTime : number ; timeUnit : ( typeof TimeUnit ) [ keyof typeof TimeUnit ] } | undefined => {
606+ if ( ! waitFor ) {
607+ return
608+ }
609+
610+ const timeParts = waitFor . split ( ':' )
611+
612+ if ( timeParts . length != 3 ) return
613+
614+ const [ hours , minutes , seconds ] = timeParts
615+
616+ const amountOfMinutes = Number ( minutes )
617+ const amountOfHours = Number ( hours )
618+ const amountOfSeconds = Number ( seconds )
619+
620+ if ( amountOfHours + amountOfMinutes + amountOfSeconds === 0 ) {
621+ return
622+ }
623+
624+ // Days
625+ if (
626+ amountOfHours % 24 === 0 &&
627+ amountOfMinutes === 0 &&
628+ amountOfSeconds === 0
629+ ) {
630+ return {
631+ amountOfTime : amountOfHours / 24 ,
632+ timeUnit : TimeUnit . DAY ,
633+ }
634+ }
635+
636+ // Hours
637+ if ( amountOfHours > 0 && amountOfMinutes === 0 && amountOfSeconds === 0 ) {
638+ return {
639+ amountOfTime : amountOfHours ,
640+ timeUnit : TimeUnit . HOUR ,
641+ }
642+ }
643+
644+ // Minutes
645+ return {
646+ amountOfTime : amountOfMinutes ,
647+ timeUnit : TimeUnit . MINUTE ,
648+ }
649+ } ,
602650 renderWithPermission ( permission : boolean , name : string , el : ReactNode ) {
603651 return permission ? (
604652 el
@@ -608,6 +656,7 @@ const Utils = Object.assign({}, require('./base/_utils'), {
608656 </ Tooltip >
609657 )
610658 } ,
659+
611660 sanitiseDiffString : ( value : FlagsmithValue ) => {
612661 if ( value === undefined || value == null ) {
613662 return ''
@@ -671,11 +720,11 @@ const Utils = Object.assign({}, require('./base/_utils'), {
671720 }
672721 }
673722 } ,
674-
675723 tagDisabled : ( tag : Tag | undefined ) => {
676724 const hasStaleFlagsPermission = Utils . getPlansPermission ( 'STALE_FLAGS' )
677725 return tag ?. type === 'STALE' && ! hasStaleFlagsPermission
678726 } ,
727+
679728 toKebabCase : ( string : string ) =>
680729 string
681730 . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' )
@@ -705,7 +754,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
705754 return true
706755 }
707756 } ,
708-
709757 validateRule ( rule : SegmentCondition ) {
710758 if ( ! rule ) return false
711759 if ( rule . delete ) {
@@ -762,6 +810,7 @@ const Utils = Object.assign({}, require('./base/_utils'), {
762810 )
763811 }
764812 } ,
813+
765814 valueToFeatureState ( value : FlagsmithValue , trimSpaces = true ) {
766815 const val = Utils . getTypedValue ( value , undefined , trimSpaces )
767816
@@ -790,7 +839,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
790839 type : 'unicode' ,
791840 }
792841 } ,
793-
794842 valueToTrait ( value : FlagsmithValue ) {
795843 const val = Utils . getTypedValue ( value )
796844
0 commit comments