Skip to content

Commit 737c73b

Browse files
authored
Merge pull request #105 from devtron-labs/feat-deployment-window-common-lib
feat: Generalize common function from Deployment window
2 parents ff3866f + 67aa064 commit 737c73b

File tree

7 files changed

+125
-10
lines changed

7 files changed

+125
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.0.73",
3+
"version": "0.0.74",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Common.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const cdMaterialListModal = (artifacts: any[], offset: number, artifactId?: numb
159159
registryType: material.registryType ?? '',
160160
imagePath: material.image ?? '',
161161
registryName: material.registryName ?? '',
162+
deploymentWindowArtifactMetadata: material.deploymentWindowArtifactMetadata ?? null,
162163
}
163164
})
164165
return materials

src/Common/Constants.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,97 @@ export enum SortingOrder {
278278
*/
279279
export const DEFAULT_BASE_PAGE_SIZE = 20
280280

281+
/**
282+
* Deployment Window
283+
*/
284+
export enum MODAL_TYPE {
285+
HIBERNATE = 'HIBERNATE',
286+
UNHIBERNATE = 'UNHIBERNATE',
287+
RESTORE = 'RESTORE',
288+
DEPLOY = 'DEPLOY',
289+
RESOURCE = 'RESOURCE',
290+
RESTART = 'RESTART',
291+
PIPELINE = 'PIPELINE',
292+
OVERVIEW = 'OVERVIEW',
293+
APP_DETAILS_STATUS = 'APP_DETAILS_STATUS',
294+
}
295+
296+
export enum ACTION_STATE {
297+
ALLOWED = 'ALLOWED',
298+
PARTIAL = 'PARTIAL',
299+
BLOCKED = 'BLOCKED',
300+
}
301+
302+
export enum DEPLOYMENT_WINDOW_TYPE {
303+
MAINTENANCE = 'MAINTENANCE',
304+
BLACKOUT = 'BLACKOUT',
305+
}
306+
export const arrowUnicode = '\u279d'
307+
308+
export enum WEEK_DAYS_ENUM {
309+
SUNDAY = 'SUNDAY',
310+
MONDAY = 'MONDAY',
311+
TUESDAY = 'TUESDAY',
312+
WEDNESDAY = 'WEDNESDAY',
313+
THURSDAY = 'THURSDAY',
314+
FRIDAY = 'FRIDAY',
315+
SATURDAY = 'SATURDAY',
316+
}
317+
318+
export enum FREQUENCY_ENUM {
319+
FIXED = 'FIXED',
320+
DAILY = 'DAILY',
321+
WEEKLY = 'WEEKLY',
322+
MONTHLY = 'MONTHLY',
323+
YEARLY = 'YEARLY',
324+
WEEKLY_RANGE = 'WEEKLY_RANGE',
325+
}
326+
327+
export const TIME_FORMAT = {
328+
DD_MMM_YYYY_HH_MM: 'DD MMM YYYY, hh:mm',
329+
}
330+
331+
export function getOrdinal(number) {
332+
if (number % 100 >= 11 && number % 100 <= 13) {
333+
return `${number}th`
334+
}
335+
switch (number % 10) {
336+
case 1:
337+
return `${number}st`
338+
case 2:
339+
return `${number}nd`
340+
case 3:
341+
return `${number}rd`
342+
default:
343+
return `${number}th`
344+
}
345+
}
346+
347+
export const TIME_HOUR_SUFFIX_FOR_12_HOUR_FORMAT = {
348+
AM: 'AM',
349+
PM: 'PM',
350+
MIDNIGHT: 'midnight',
351+
NOON: 'noon',
352+
}
353+
354+
export const getTimeStampAMPMSuffix = (time: string): string => {
355+
// time is in format HH:mm 24hr format
356+
const [hoursStr, minutesStr] = time.split(':')
357+
const hours = parseInt(hoursStr, 10)
358+
const minutes = parseInt(minutesStr, 10)
359+
360+
if (hours === 12 && minutes === 0) {
361+
return TIME_HOUR_SUFFIX_FOR_12_HOUR_FORMAT.NOON
362+
}
363+
if (hours === 0 && minutes === 0) {
364+
return TIME_HOUR_SUFFIX_FOR_12_HOUR_FORMAT.MIDNIGHT
365+
}
366+
if (hours >= 12) {
367+
return TIME_HOUR_SUFFIX_FOR_12_HOUR_FORMAT.PM
368+
}
369+
return TIME_HOUR_SUFFIX_FOR_12_HOUR_FORMAT.AM
370+
}
371+
281372
export enum ReactSelectInputAction {
282373
inputChange = 'input-change',
283374
selectOption = 'select-option',

src/Common/Helper.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,13 @@ export const debounce = (func, timeout = 500) => {
692692
}
693693

694694
/**
695-
* Sorts the relative dates based on the sorting direction
695+
* Returns a capitalized string with first letter in uppercase and rest in lowercase
696696
*/
697+
698+
export const capitalizeFirstLetter = (text: string) => text.charAt(0).toUpperCase() + text.slice(1).toLowerCase()
699+
700+
// * Sorts the relative dates based on the sorting direction
701+
// */
697702
export const handleRelativeDateSorting = (dateStringA, dateStringB, sortOrder) => {
698703
// For date, we show relative date hence the logic for sorting is reversed here
699704
const dateA = new Date(dateStringA).getTime()

src/Common/TippyCustomized.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ReactComponent as QuestionFilled } from '../Assets/Icon/ic-help.svg'
55
import { ReactComponent as Question } from '../Assets/Icon/ic-help-outline.svg'
66
import 'tippy.js/animations/shift-toward-subtle.css'
77
import { TippyCustomizedProps, TippyTheme } from './Types'
8-
import { not } from './Helper'
8+
import { not, stopPropagation } from './Helper'
99

1010
// This component will handle some of the new tippy designs and interactions
1111
// So this can be updated to support further for new features or interactions
@@ -19,7 +19,8 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
1919
document.addEventListener('keydown', closeOnEsc)
2020
}
2121

22-
const closeTippy = () => {
22+
const closeTippy = (e) => {
23+
stopPropagation(e)
2324
if (tippyRef.current?.hide) {
2425
tippyRef.current.hide()
2526
tippyRef.current = null
@@ -33,7 +34,7 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
3334

3435
const closeOnEsc = (e) => {
3536
if (e.keyCode === 27) {
36-
closeTippy()
37+
closeTippy(e)
3738
}
3839
}
3940

@@ -163,7 +164,7 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
163164
content={getTippyContent()}
164165
trigger={trigger || 'mouseenter'}
165166
onMount={onTippyMount}
166-
onClickOutside={closeTippy}
167+
onClickOutside={(tippyInstance, e) => closeTippy(e)}
167168
showOnCreate={showOnCreate || false}
168169
animation={animation || 'fade'}
169170
duration={duration || 300}

src/Common/Types.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ReactNode, CSSProperties } from 'react'
22
import { Placement } from 'tippy.js'
33
import { ImageComment, ReleaseTag } from './ImageTags.Types'
4-
import { DockerConfigOverrideType, SortingOrder, TaskErrorObj } from '.'
4+
import { ACTION_STATE, DEPLOYMENT_WINDOW_TYPE, DockerConfigOverrideType, SortingOrder, TaskErrorObj } from '.'
55

66
/**
77
* Generic response type object with support for overriding the result type
@@ -174,7 +174,6 @@ export interface RadioGroupComposition {
174174
Radio?: React.FC<any>
175175
}
176176

177-
178177
export interface RadioGroupProps {
179178
children: ReactNode
180179
value: string
@@ -276,6 +275,12 @@ export enum MaterialDataSource {
276275
EXTERNAL = 'ext',
277276
}
278277

278+
export interface DeploymentWindowArtifactMetadata {
279+
id: number
280+
name: string
281+
type: DEPLOYMENT_WINDOW_TYPE
282+
}
283+
279284
export interface CDMaterialType {
280285
index: number
281286
id: string
@@ -313,6 +318,7 @@ export interface CDMaterialType {
313318
createdTime?: string
314319
deployed?: boolean
315320
dataSource?: MaterialDataSource
321+
deploymentWindowArtifactMetadata?: DeploymentWindowArtifactMetadata
316322
}
317323

318324
export enum CDMaterialServiceEnum {
@@ -407,6 +413,7 @@ export interface CommonNodeAttr {
407413
deploymentAppCreated?: boolean
408414
isLast?: boolean
409415
downstreamEnvironments?: DownstreamNodesEnvironmentsType[]
416+
isDeploymentBlocked?: boolean
410417
}
411418

412419
export enum DeploymentAppTypes {
@@ -803,3 +810,13 @@ export type SortingParams<T = string> =
803810
sortBy: T
804811
}
805812
| { sortOrder?: never; sortBy?: never }
813+
814+
export interface DeploymentWindowProfileMetaData {
815+
name: string
816+
userActionState: ACTION_STATE
817+
type: string | DEPLOYMENT_WINDOW_TYPE
818+
calculatedTimestamp: string
819+
isActive: boolean
820+
excludedUserEmails: string[]
821+
warningMessage: string
822+
}

0 commit comments

Comments
 (0)