Skip to content

Commit ec675c9

Browse files
committed
Merge branch 'main' of https://github.com/devtron-labs/devtron-fe-common-lib into refactor/component-migration
2 parents ed8414e + 737c73b commit ec675c9

File tree

8 files changed

+182
-40
lines changed

8 files changed

+182
-40
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
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.72-beta-2",
3+
"version": "0.0.75",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -80,8 +80,8 @@
8080
"react-router-dom": "^5.3.0",
8181
"react-draggable": "^4.4.5",
8282
"react-ga4": "^1.4.1",
83-
"@typeform/embed-react": "2.20.0"
84-
83+
"@typeform/embed-react": "2.20.0",
84+
"yaml": "^2.4.1"
8585
},
8686
"dependencies": {
8787
"react-monaco-editor": "^0.54.0",

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'monaco-editor'
2121
// import YamlWorker from 'web-worker:monaco-yaml/lib/esm/yaml.worker';
2222
import { Progressing } from '../Progressing'
2323
import { useWindowSize } from '../Hooks/UseWindowSize/UseWindowSize'
24-
import { cleanKubeManifest, copyToClipboard, useJsonYaml } from '../Helper'
24+
import { YAMLStringify, cleanKubeManifest, copyToClipboard, useJsonYaml } from '../Helper'
2525
import Select from '../Select/Select'
2626
import RadioGroup from '../RadioGroup/RadioGroup'
2727

@@ -300,7 +300,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
300300
}
301301
let final = value
302302
if (obj) {
303-
final = state.mode === 'json' ? JSON.stringify(obj, null, tabSize) : YAML.stringify(obj, { indent: 2 })
303+
final = state.mode === 'json' ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj, { indent: 2 })
304304
}
305305
dispatch({ type: 'setCode', value: final })
306306
}, [value, noParsing])

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
@@ -290,6 +290,97 @@ export enum SortingOrder {
290290
*/
291291
export const DEFAULT_BASE_PAGE_SIZE = 20
292292

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

src/Common/Helper.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export function useJsonYaml(value, tabSize = 4, language = 'json', shouldRun = f
369369
}
370370
if (obj && typeof obj === 'object') {
371371
setJson(JSON.stringify(obj, null, tabSize))
372-
setYaml(YAML.stringify(obj, { indent: 2 }))
372+
setYaml(YAML.stringify(obj, { indent: 2, lineWidth: 0 }))
373373
setNativeObject(obj)
374374
setError('')
375375
} else {
@@ -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()
@@ -711,3 +716,11 @@ export const handleRelativeDateSorting = (dateStringA, dateStringB, sortOrder) =
711716
return sortOrder === SortingOrder.ASC ? dateB - dateA : dateA - dateB
712717
}
713718
}
719+
720+
/**
721+
* Returns a stringified YAML with default indentation & line width
722+
*/
723+
724+
export const YAMLStringify = (obj: object | unknown, option?: object) => (
725+
YAML.stringify(obj, { indent: 2, lineWidth: 0, ...option })
726+
)

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}

0 commit comments

Comments
 (0)