@devtron-labs/devtron-fe-common-lib 0.0.48-beta-5 → 0.0.48-beta-6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ChartVersionAndTypeSelectorProps } from './Types';
3
+ declare const ChartVersionAndTypeSelector: ({ setSelectedChartRefId }: ChartVersionAndTypeSelectorProps) => JSX.Element;
4
+ export default ChartVersionAndTypeSelector;
@@ -16,4 +16,5 @@ export declare function setImageTags(request: any, pipelineId: number, artifactI
16
16
  export declare const genericCDMaterialsService: (serviceType: CDMaterialServiceEnum, cdMaterialID: number, stage: DeploymentNodeType, signal: AbortSignal, queryParams?: CDMaterialServiceQueryParams) => Promise<CDMaterialResponseType>;
17
17
  export declare function extractImage(image: string): string;
18
18
  export declare function createGitCommitUrl(url: string, revision: string): string;
19
+ export declare function fetchChartTemplateVersions(): Promise<ResponseType>;
19
20
  export {};
@@ -20,6 +20,7 @@ export declare const ROUTES: {
20
20
  USER_CHECK_ROLE: string;
21
21
  IMAGE_TAGGING: string;
22
22
  CD_MATERIAL_GET: string;
23
+ DEPLOYMENT_TEMPLATE_LIST: string;
23
24
  };
24
25
  export declare enum KEY_VALUE {
25
26
  KEY = "key",
@@ -48,6 +48,13 @@ export declare const getUrlWithSearchParams: (url: string, params: Record<string
48
48
  * Custom exception logger function for logging errors to sentry
49
49
  */
50
50
  export declare const logExceptionToSentry: typeof Sentry.captureException;
51
+ export declare const customStyles: {
52
+ control: (base: any, state: any) => any;
53
+ indicatorSeparator: (base: any, state: any) => any;
54
+ valueContainer: (base: any, state: any) => any;
55
+ dropdownIndicator: (base: any, state: any) => any;
56
+ };
57
+ export declare const getFilteredChartVersions: (charts: any, selectedChartType: any) => any;
51
58
  export declare function getUnlockedJSON(json: any, jsonPathArray: any): any;
52
59
  export declare function getLockedJSON(json: any, jsonPathArray: string[]): any;
53
60
  export {};
@@ -625,6 +625,15 @@ export interface CodeEditorHeaderInterface {
625
625
  className?: string;
626
626
  hideDefaultSplitHeader?: boolean;
627
627
  }
628
+ export interface DeploymentChartVersionType {
629
+ chartRefId: number;
630
+ chartVersion: string;
631
+ chartType: string;
632
+ type: number;
633
+ }
634
+ export interface ChartVersionAndTypeSelectorProps {
635
+ setSelectedChartRefId: React.Dispatch<React.SetStateAction<number>>;
636
+ }
628
637
  export declare enum PipelineType {
629
638
  CI_PIPELINE = "CI_PIPELINE",
630
639
  CD_PIPELINE = "CD_PIPELINE",
@@ -42,5 +42,6 @@ export * from './Hooks';
42
42
  export { AppStatus } from './AppStatus';
43
43
  export * from './RJSF';
44
44
  export * from './DevtronProgressing';
45
+ export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSelector';
45
46
  export * from './AddCDButton';
46
47
  export * from './CustomInput';
package/dist/index.js CHANGED
@@ -48,7 +48,8 @@ var ROUTES = {
48
48
  PROJECT_LIST_MIN: 'team/autocomplete',
49
49
  USER_CHECK_ROLE: 'user/check/roles',
50
50
  IMAGE_TAGGING: 'app/image-tagging',
51
- CD_MATERIAL_GET: 'app/cd-pipeline'
51
+ CD_MATERIAL_GET: 'app/cd-pipeline',
52
+ DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
52
53
  };
53
54
  exports.KEY_VALUE = void 0;
54
55
  (function (KEY_VALUE) {
@@ -11761,6 +11762,22 @@ var getUrlWithSearchParams = function (url, params) {
11761
11762
  * Custom exception logger function for logging errors to sentry
11762
11763
  */
11763
11764
  var logExceptionToSentry = captureException.bind(window);
11765
+ var customStyles = {
11766
+ control: function (base, state) { return (__assign(__assign({}, base), { minHeight: '32px', boxShadow: 'none', border: 'none', cursor: 'pointer', background: 'transparent' })); },
11767
+ indicatorSeparator: function (base, state) { return (__assign(__assign({}, base), { width: 0 })); },
11768
+ valueContainer: function (base, state) { return (__assign(__assign({}, base), { padding: '0', fontSize: '13px', fontWeight: '600' })); },
11769
+ dropdownIndicator: function (base, state) { return (__assign(__assign({}, base), { color: 'var(--N400)', padding: '0 8px', transition: 'all .2s ease', transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)' })); },
11770
+ };
11771
+ var getFilteredChartVersions = function (charts, selectedChartType) {
11772
+ // Filter chart versions based on selected chart type
11773
+ return charts
11774
+ .filter(function (item) { return (item === null || item === void 0 ? void 0 : item.chartType) === selectedChartType.value; })
11775
+ .map(function (item) { return ({
11776
+ value: item === null || item === void 0 ? void 0 : item.chartVersion,
11777
+ label: item === null || item === void 0 ? void 0 : item.chartVersion,
11778
+ chartRefId: item.chartRefId,
11779
+ }); });
11780
+ };
11764
11781
  function removeEmptyObjectKeysAndNullValues(obj) {
11765
11782
  // It recursively removes empty object keys and array values that are null
11766
11783
  for (var key in obj) {
@@ -24495,6 +24512,9 @@ function createGitCommitUrl(url, revision) {
24495
24512
  }
24496
24513
  }
24497
24514
  return "NA";
24515
+ }
24516
+ function fetchChartTemplateVersions() {
24517
+ return get("".concat(ROUTES.DEPLOYMENT_TEMPLATE_LIST, "?appId=-1&envId=-1"));
24498
24518
  }
24499
24519
 
24500
24520
  /*
@@ -28209,6 +28229,53 @@ function DevtronProgressing(_a) {
28209
28229
  return (jsxRuntime.jsx("div", __assign({ className: parentClasses ? parentClasses : '' }, { children: jsxRuntime.jsx(SvgIcRotateDevtron, { className: classes ? classes : '' }) })));
28210
28230
  }
28211
28231
 
28232
+ // @TODO: Generalize this component to be used in CodeEditor as Chart selector toolbar
28233
+ // when the Code Editor is moved to the fe-common-lib
28234
+ var ChartVersionAndTypeSelector = function (_a) {
28235
+ var setSelectedChartRefId = _a.setSelectedChartRefId;
28236
+ var _b = __read(React.useState([]), 2), charts = _b[0], setCharts = _b[1];
28237
+ var _c = __read(React.useState(null), 2), selectedChartType = _c[0], setSelectedChartType = _c[1];
28238
+ var _d = __read(React.useState([]), 2), chartVersionOptions = _d[0], setChartVersionOptions = _d[1];
28239
+ var _e = __read(React.useState([]), 2), chartTypeOptions = _e[0], setChartTypeOptions = _e[1];
28240
+ var _f = __read(React.useState(null), 2), selectedChartVersion = _f[0], setSelectedChartVersion = _f[1];
28241
+ React.useEffect(function () {
28242
+ fetchChartTemplateVersions()
28243
+ .then(function (res) {
28244
+ var charts = (res === null || res === void 0 ? void 0 : res.result) || [];
28245
+ setCharts(charts);
28246
+ // Extract unique chart types from the data
28247
+ var chartTypeOptions = __spreadArray([], __read(new Set(charts.map(function (item) { return item.chartType; }))), false).map(function (type) { return ({
28248
+ value: type,
28249
+ label: type,
28250
+ }); });
28251
+ setChartTypeOptions(chartTypeOptions);
28252
+ var filteredVersions = getFilteredChartVersions(charts, chartTypeOptions[0]);
28253
+ selectFirstChartVersion(filteredVersions);
28254
+ })
28255
+ .catch(function (err) {
28256
+ showError(err);
28257
+ });
28258
+ }, []);
28259
+ var selectFirstChartVersion = function (filteredVersions) {
28260
+ var _a;
28261
+ setChartVersionOptions(filteredVersions);
28262
+ setSelectedChartVersion(filteredVersions[0]); // Select the first chart version by default
28263
+ setSelectedChartRefId((_a = filteredVersions[0]) === null || _a === void 0 ? void 0 : _a.chartRefId);
28264
+ };
28265
+ // Function to update chart version options based on selected chart type
28266
+ var handleChartTypeChange = function (selectedOption) {
28267
+ setSelectedChartType(selectedOption);
28268
+ var filteredVersions = getFilteredChartVersions(charts, selectedOption);
28269
+ selectFirstChartVersion(filteredVersions);
28270
+ };
28271
+ // Function to handle the change of the selected chart version
28272
+ var handleChartVersionChange = function (selectedOption) {
28273
+ setSelectedChartVersion(selectedOption);
28274
+ setSelectedChartRefId(selectedOption.chartRefId);
28275
+ };
28276
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "chart-type-options flex", "data-testid": "chart-type-options" }, { children: [jsxRuntime.jsx("span", __assign({ className: "chart-type-options-label mr-4" }, { children: "Chart Type" })), jsxRuntime.jsx(ReactSelect, { value: selectedChartType !== null && selectedChartType !== void 0 ? selectedChartType : chartTypeOptions[0], options: chartTypeOptions, onChange: handleChartTypeChange, styles: customStyles })] })), jsxRuntime.jsxs("div", __assign({ className: "chart-version-options flex", "data-testid": "chart-version-options" }, { children: [jsxRuntime.jsx("span", __assign({ className: "chart-version-options-label mr-4" }, { children: "Chart Version" })), jsxRuntime.jsx(ReactSelect, { value: selectedChartVersion !== null && selectedChartVersion !== void 0 ? selectedChartVersion : chartVersionOptions[0], options: chartVersionOptions, onChange: handleChartVersionChange, styles: customStyles })] }))] })));
28277
+ };
28278
+
28212
28279
  function TooltipContent(_a) {
28213
28280
  var tooltipContent = _a.tooltipContent;
28214
28281
  if (tooltipContent) {
@@ -28313,6 +28380,7 @@ exports.BreadCrumb = BreadCrumb;
28313
28380
  exports.BreadcrumbStore = Store;
28314
28381
  exports.BuildStageVariable = BuildStageVariable;
28315
28382
  exports.CDModalTab = CDModalTab;
28383
+ exports.ChartVersionAndTypeSelector = ChartVersionAndTypeSelector;
28316
28384
  exports.Checkbox = Checkbox$1;
28317
28385
  exports.ClearIndicator = ClearIndicator;
28318
28386
  exports.ClipboardButton = ClipboardButton;
@@ -28385,12 +28453,15 @@ exports.VisibleModal2 = VisibleModal2;
28385
28453
  exports.closeOnEscKeyPressed = closeOnEscKeyPressed;
28386
28454
  exports.copyToClipboard = copyToClipboard;
28387
28455
  exports.createGitCommitUrl = createGitCommitUrl;
28456
+ exports.customStyles = customStyles;
28388
28457
  exports.extractImage = extractImage;
28458
+ exports.fetchChartTemplateVersions = fetchChartTemplateVersions;
28389
28459
  exports.genericCDMaterialsService = genericCDMaterialsService;
28390
28460
  exports.get = get;
28391
28461
  exports.getAlphabetIcon = getAlphabetIcon;
28392
28462
  exports.getCookie = getCookie;
28393
28463
  exports.getEmptyArrayOfLength = getEmptyArrayOfLength;
28464
+ exports.getFilteredChartVersions = getFilteredChartVersions;
28394
28465
  exports.getInferredTypeFromValueType = getInferredTypeFromValueType;
28395
28466
  exports.getLockedJSON = getLockedJSON;
28396
28467
  exports.getLoginInfo = getLoginInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.48-beta-5",
3
+ "version": "0.0.48-beta-6",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,78 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { fetchChartTemplateVersions } from './Common.service'
3
+ import { ChartVersionAndTypeSelectorProps, DeploymentChartVersionType } from './Types'
4
+ import ReactSelect from 'react-select'
5
+ import { customStyles, getFilteredChartVersions, showError } from './Helper'
6
+
7
+ // @TODO: Generalize this component to be used in CodeEditor as Chart selector toolbar
8
+ // when the Code Editor is moved to the fe-common-lib
9
+ const ChartVersionAndTypeSelector = ({ setSelectedChartRefId }: ChartVersionAndTypeSelectorProps) => {
10
+ const [charts, setCharts] = useState<DeploymentChartVersionType[]>([])
11
+ const [selectedChartType, setSelectedChartType] = useState(null)
12
+ const [chartVersionOptions, setChartVersionOptions] = useState([])
13
+ const [chartTypeOptions, setChartTypeOptions] = useState([])
14
+ const [selectedChartVersion, setSelectedChartVersion] = useState(null)
15
+
16
+ useEffect(() => {
17
+ fetchChartTemplateVersions()
18
+ .then((res) => {
19
+ const charts = res?.result || []
20
+ setCharts(charts)
21
+ // Extract unique chart types from the data
22
+ const chartTypeOptions = [...new Set(charts.map((item) => item.chartType))].map((type) => ({
23
+ value: type,
24
+ label: type,
25
+ }))
26
+ setChartTypeOptions(chartTypeOptions)
27
+ const filteredVersions = getFilteredChartVersions(charts, chartTypeOptions[0])
28
+ selectFirstChartVersion(filteredVersions)
29
+ })
30
+ .catch((err) => {
31
+ showError(err)
32
+ })
33
+ }, [])
34
+
35
+ const selectFirstChartVersion = (filteredVersions) => {
36
+ setChartVersionOptions(filteredVersions)
37
+ setSelectedChartVersion(filteredVersions[0]) // Select the first chart version by default
38
+ setSelectedChartRefId(filteredVersions[0]?.chartRefId)
39
+ }
40
+
41
+ // Function to update chart version options based on selected chart type
42
+ const handleChartTypeChange = (selectedOption) => {
43
+ setSelectedChartType(selectedOption)
44
+ const filteredVersions = getFilteredChartVersions(charts, selectedOption)
45
+ selectFirstChartVersion(filteredVersions)
46
+ }
47
+
48
+ // Function to handle the change of the selected chart version
49
+ const handleChartVersionChange = (selectedOption) => {
50
+ setSelectedChartVersion(selectedOption)
51
+ setSelectedChartRefId(selectedOption.chartRefId)
52
+ }
53
+
54
+ return (
55
+ <div className="flex">
56
+ <div className="chart-type-options flex" data-testid="chart-type-options">
57
+ <span className="chart-type-options-label mr-4">Chart Type</span>
58
+ <ReactSelect
59
+ value={selectedChartType ?? chartTypeOptions[0]}
60
+ options={chartTypeOptions}
61
+ onChange={handleChartTypeChange}
62
+ styles={customStyles}
63
+ />
64
+ </div>
65
+ <div className="chart-version-options flex" data-testid="chart-version-options">
66
+ <span className="chart-version-options-label mr-4">Chart Version</span>
67
+ <ReactSelect
68
+ value={selectedChartVersion ?? chartVersionOptions[0]}
69
+ options={chartVersionOptions}
70
+ onChange={handleChartVersionChange}
71
+ styles={customStyles}
72
+ />
73
+ </div>
74
+ </div>
75
+ )
76
+ }
77
+
78
+ export default ChartVersionAndTypeSelector
@@ -309,3 +309,7 @@ export function createGitCommitUrl(url: string, revision: string): string {
309
309
  }
310
310
  return "NA"
311
311
  }
312
+
313
+ export function fetchChartTemplateVersions() {
314
+ return get(`${ROUTES.DEPLOYMENT_TEMPLATE_LIST}?appId=-1&envId=-1`)
315
+ }
@@ -24,7 +24,8 @@ export const ROUTES = {
24
24
  PROJECT_LIST_MIN: 'team/autocomplete',
25
25
  USER_CHECK_ROLE: 'user/check/roles',
26
26
  IMAGE_TAGGING:'app/image-tagging',
27
- CD_MATERIAL_GET: 'app/cd-pipeline'
27
+ CD_MATERIAL_GET: 'app/cd-pipeline',
28
+ DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
28
29
  }
29
30
 
30
31
  export enum KEY_VALUE {
@@ -461,6 +461,44 @@ export const getUrlWithSearchParams = (url: string, params: Record<string | numb
461
461
  */
462
462
  export const logExceptionToSentry = Sentry.captureException.bind(window)
463
463
 
464
+ export const customStyles = {
465
+ control: (base, state) => ({
466
+ ...base,
467
+ minHeight: '32px',
468
+ boxShadow: 'none',
469
+ border: 'none',
470
+ cursor: 'pointer',
471
+ background: 'transparent',
472
+ }),
473
+ indicatorSeparator: (base, state) => ({
474
+ ...base,
475
+ width: 0,
476
+ }),
477
+ valueContainer: (base, state) => ({
478
+ ...base,
479
+ padding: '0',
480
+ fontSize: '13px',
481
+ fontWeight: '600',
482
+ }),
483
+ dropdownIndicator: (base, state) => ({
484
+ ...base,
485
+ color: 'var(--N400)',
486
+ padding: '0 8px',
487
+ transition: 'all .2s ease',
488
+ transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
489
+ }),
490
+ }
491
+
492
+ export const getFilteredChartVersions = (charts, selectedChartType) => {
493
+ // Filter chart versions based on selected chart type
494
+ return charts
495
+ .filter((item) => item?.chartType === selectedChartType.value)
496
+ .map((item) => ({
497
+ value: item?.chartVersion,
498
+ label: item?.chartVersion,
499
+ chartRefId: item.chartRefId,
500
+ }))
501
+ }
464
502
  function removeEmptyObjectKeysAndNullValues(obj) {
465
503
  // It recursively removes empty object keys and array values that are null
466
504
  for (let key in obj) {
@@ -690,6 +690,17 @@ export interface CodeEditorHeaderInterface {
690
690
  hideDefaultSplitHeader?: boolean;
691
691
  }
692
692
 
693
+ export interface DeploymentChartVersionType {
694
+ chartRefId: number
695
+ chartVersion: string
696
+ chartType: string
697
+ type: number
698
+ }
699
+
700
+ export interface ChartVersionAndTypeSelectorProps {
701
+ setSelectedChartRefId: React.Dispatch<React.SetStateAction<number>>
702
+ }
703
+
693
704
  export enum PipelineType {
694
705
  CI_PIPELINE = 'CI_PIPELINE',
695
706
  CD_PIPELINE = 'CD_PIPELINE',
@@ -42,5 +42,6 @@ export * from './Hooks'
42
42
  export { AppStatus } from './AppStatus'
43
43
  export * from './RJSF'
44
44
  export * from './DevtronProgressing'
45
+ export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSelector'
45
46
  export * from './AddCDButton'
46
47
  export * from './CustomInput'