@devtron-labs/devtron-fe-common-lib 0.0.35 → 0.0.36-beta-1

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,6 @@
1
+ import { useSuperAdminType } from './types';
2
+ /**
3
+ * @description It will return isSuperAdmin and would be set to false by default, might need few optimizations like dep, etc
4
+ * @returns {useSuperAdminType} isSuperAdmin
5
+ */
6
+ export declare const useSuperAdmin: () => useSuperAdminType;
@@ -0,0 +1,3 @@
1
+ export interface useSuperAdminType {
2
+ isSuperAdmin: boolean;
3
+ }
@@ -0,0 +1 @@
1
+ export { useSuperAdmin } from './UseSuperAdmin/UseSuperAdmin';
@@ -24,6 +24,7 @@ export interface ImageTaggingContainerType {
24
24
  setTagsEditable?: (tagsEditable: boolean) => void;
25
25
  toggleCardMode?: (id: number) => void;
26
26
  hideHardDelete?: boolean;
27
+ isSuperAdmin?: boolean;
27
28
  }
28
29
  export interface ImageButtonType {
29
30
  text: string;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { ImageButtonType, ImageTaggingContainerType } from './ImageTags.Types';
3
- export declare const ImageTagsContainer: ({ ciPipelineId, artifactId, imageComment, imageReleaseTags, updateCurrentAppMaterial, appReleaseTagNames, setAppReleaseTagNames, tagsEditable, setTagsEditable, toggleCardMode, hideHardDelete, forceReInit, }: ImageTaggingContainerType) => JSX.Element;
3
+ export declare const ImageTagsContainer: ({ ciPipelineId, artifactId, imageComment, imageReleaseTags, updateCurrentAppMaterial, appReleaseTagNames, setAppReleaseTagNames, tagsEditable, setTagsEditable, toggleCardMode, hideHardDelete, forceReInit, isSuperAdmin }: ImageTaggingContainerType) => JSX.Element;
4
4
  export declare const ImageTagButton: ({ text, isSoftDeleted, isEditing, onSoftDeleteClick, onHardDeleteClick, tagId, softDeleteTags, isSuperAdmin, duplicateTag, hideHardDelete, }: ImageButtonType) => JSX.Element;
@@ -38,3 +38,4 @@ export * from './ResizableTextarea';
38
38
  export { default as DebouncedSearch } from './DebouncedSearch/DebouncedSearch';
39
39
  export { default as Grid } from './Grid/Grid';
40
40
  export { default as ClipboardButton } from './ClipboardButton/ClipboardButton';
41
+ export * from './Hooks';
package/dist/index.js CHANGED
@@ -23126,7 +23126,7 @@ var SvgIcEnter = function SvgIcEnter(props) {
23126
23126
  };
23127
23127
 
23128
23128
  var ImageTagsContainer = function (_a) {
23129
- var ciPipelineId = _a.ciPipelineId, artifactId = _a.artifactId, imageComment = _a.imageComment, imageReleaseTags = _a.imageReleaseTags, updateCurrentAppMaterial = _a.updateCurrentAppMaterial, appReleaseTagNames = _a.appReleaseTagNames, setAppReleaseTagNames = _a.setAppReleaseTagNames, tagsEditable = _a.tagsEditable, setTagsEditable = _a.setTagsEditable, toggleCardMode = _a.toggleCardMode, hideHardDelete = _a.hideHardDelete, forceReInit = _a.forceReInit;
23129
+ var ciPipelineId = _a.ciPipelineId, artifactId = _a.artifactId, imageComment = _a.imageComment, imageReleaseTags = _a.imageReleaseTags, updateCurrentAppMaterial = _a.updateCurrentAppMaterial, appReleaseTagNames = _a.appReleaseTagNames, setAppReleaseTagNames = _a.setAppReleaseTagNames, tagsEditable = _a.tagsEditable, setTagsEditable = _a.setTagsEditable, toggleCardMode = _a.toggleCardMode, hideHardDelete = _a.hideHardDelete, forceReInit = _a.forceReInit, isSuperAdmin = _a.isSuperAdmin;
23130
23130
  var _b = __read(React.useState(imageReleaseTags ? imageReleaseTags : []), 2), initialTags = _b[0], setInitialTags = _b[1];
23131
23131
  var _c = __read(React.useState(imageComment ? imageComment.comment : ''), 2), initialDescription = _c[0], setInitialDescription = _c[1];
23132
23132
  var _d = __read(React.useState(appReleaseTagNames ? appReleaseTagNames : []), 2), existingTags = _d[0], setExistingTags = _d[1];
@@ -23138,41 +23138,14 @@ var ImageTagsContainer = function (_a) {
23138
23138
  var _k = __read(React.useState([]), 2), createTags = _k[0], setCreateTags = _k[1];
23139
23139
  var _l = __read(React.useState([]), 2), softDeleteTags = _l[0], setSoftDeleteTags = _l[1];
23140
23140
  var _m = __read(React.useState([]), 2), hardDeleteTags = _m[0], setHardDeleteTags = _m[1];
23141
- var _o = __read(React.useState(false), 2), isSuperAdmin = _o[0], setSuperAdmin = _o[1];
23142
- var _p = __read(React.useState(''), 2), descriptionValidationMessage = _p[0], setDescriptionValidationMessage = _p[1];
23143
- var _q = __read(React.useState(''), 2), textInput = _q[0], setTextInput = _q[1];
23144
- React.useEffect(function () {
23145
- initialise();
23146
- }, []);
23141
+ var _o = __read(React.useState(''), 2), descriptionValidationMessage = _o[0], setDescriptionValidationMessage = _o[1];
23142
+ var _p = __read(React.useState(''), 2), textInput = _p[0], setTextInput = _p[1];
23147
23143
  React.useEffect(function () {
23148
23144
  reInitState();
23149
23145
  }, [imageReleaseTags, imageComment, tagsEditable]);
23150
23146
  React.useEffect(function () {
23151
23147
  setExistingTags(appReleaseTagNames ? appReleaseTagNames : []);
23152
23148
  }, [appReleaseTagNames]);
23153
- function initialise() {
23154
- var _a, _b;
23155
- return __awaiter(this, void 0, void 0, function () {
23156
- var userRole, superAdmin, err_1;
23157
- return __generator(this, function (_c) {
23158
- switch (_c.label) {
23159
- case 0:
23160
- _c.trys.push([0, 2, , 3]);
23161
- return [4 /*yield*/, getUserRole()];
23162
- case 1:
23163
- userRole = _c.sent();
23164
- superAdmin = (_b = (_a = userRole === null || userRole === void 0 ? void 0 : userRole.result) === null || _a === void 0 ? void 0 : _a.roles) === null || _b === void 0 ? void 0 : _b.includes('role:super-admin___');
23165
- setSuperAdmin(superAdmin);
23166
- return [3 /*break*/, 3];
23167
- case 2:
23168
- err_1 = _c.sent();
23169
- showError(err_1);
23170
- return [3 /*break*/, 3];
23171
- case 3: return [2 /*return*/];
23172
- }
23173
- });
23174
- });
23175
- }
23176
23149
  var reInitState = function () {
23177
23150
  if (forceReInit || !isEditing) {
23178
23151
  setInitialTags(imageReleaseTags ? imageReleaseTags : []);
@@ -23616,6 +23589,25 @@ function ClipboardButton(_a) {
23616
23589
  return (jsxRuntime.jsx("div", __assign({ className: "icon-dim-16 flex center" }, { children: jsxRuntime.jsx(Tippy, __assign({ className: "default-tt", content: copied ? copiedTippyText : 'Copy', placement: "right", visible: copied || enableTippy }, { children: jsxRuntime.jsx("button", __assign({ type: "button", className: "dc__hover-n100 dc__outline-none-imp p-0 flex bcn-0 dc__no-border", onMouseEnter: handleEnableTippy, onMouseLeave: handleDisableTippy, onClick: handleCopyContent }, { children: jsxRuntime.jsx(SvgIcCopy, { className: "icon-dim-16" }) })) })) })));
23617
23590
  }
23618
23591
 
23592
+ /**
23593
+ * @description It will return isSuperAdmin and would be set to false by default, might need few optimizations like dep, etc
23594
+ * @returns {useSuperAdminType} isSuperAdmin
23595
+ */
23596
+ var useSuperAdmin = function () {
23597
+ var _a = __read(React.useState(false), 2), isSuperAdmin = _a[0], setSuperAdmin = _a[1];
23598
+ React.useEffect(function () {
23599
+ getUserRole()
23600
+ .then(function (response) {
23601
+ var _a;
23602
+ setSuperAdmin((_a = response.result.superAdmin) !== null && _a !== void 0 ? _a : false);
23603
+ })
23604
+ .catch(function (error) {
23605
+ showError(error);
23606
+ });
23607
+ }, []);
23608
+ return { isSuperAdmin: isSuperAdmin };
23609
+ };
23610
+
23619
23611
  exports.BreadCrumb = BreadCrumb;
23620
23612
  exports.BreadcrumbStore = Store;
23621
23613
  exports.BuildStageVariable = BuildStageVariable;
@@ -23717,4 +23709,5 @@ exports.useBreadcrumb = useBreadcrumb;
23717
23709
  exports.useEffectAfterMount = useEffectAfterMount;
23718
23710
  exports.useForm = useForm;
23719
23711
  exports.useSearchString = useSearchString;
23712
+ exports.useSuperAdmin = useSuperAdmin;
23720
23713
  exports.useThrottledEffect = useThrottledEffect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.35",
3
+ "version": "0.0.36-beta-1",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,24 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { getUserRole } from '../../Common.service'
3
+ import { useSuperAdminType } from './types'
4
+ import { showError } from '../../Helper'
5
+
6
+ /**
7
+ * @description It will return isSuperAdmin and would be set to false by default, might need few optimizations like dep, etc
8
+ * @returns {useSuperAdminType} isSuperAdmin
9
+ */
10
+ export const useSuperAdmin = (): useSuperAdminType => {
11
+ const [isSuperAdmin, setSuperAdmin] = useState<boolean>(false)
12
+
13
+ useEffect(() => {
14
+ getUserRole()
15
+ .then((response) => {
16
+ setSuperAdmin(response.result.superAdmin ?? false)
17
+ })
18
+ .catch((error) => {
19
+ showError(error)
20
+ })
21
+ }, [])
22
+
23
+ return { isSuperAdmin }
24
+ }
@@ -0,0 +1,3 @@
1
+ export interface useSuperAdminType {
2
+ isSuperAdmin: boolean
3
+ }
@@ -0,0 +1 @@
1
+ export { useSuperAdmin } from './UseSuperAdmin/UseSuperAdmin'
@@ -27,6 +27,7 @@ export interface ImageTaggingContainerType {
27
27
  setTagsEditable?: (tagsEditable: boolean) => void
28
28
  toggleCardMode?: (id: number) => void
29
29
  hideHardDelete?: boolean
30
+ isSuperAdmin?: boolean
30
31
  }
31
32
 
32
33
  export interface ImageButtonType {
@@ -16,7 +16,7 @@ import { TippyTheme } from './Types'
16
16
  import { ImageButtonType, ImageTaggingContainerType, ReleaseTag } from './ImageTags.Types'
17
17
  import { showError, stopPropagation } from './Helper'
18
18
  import { TippyCustomized } from './TippyCustomized'
19
- import { setImageTags, getUserRole } from './Common.service'
19
+ import { setImageTags } from './Common.service'
20
20
  import Tippy from '@tippyjs/react'
21
21
 
22
22
  export const ImageTagsContainer = ({
@@ -32,6 +32,7 @@ export const ImageTagsContainer = ({
32
32
  toggleCardMode,
33
33
  hideHardDelete,
34
34
  forceReInit,
35
+ isSuperAdmin
35
36
  }: ImageTaggingContainerType) => {
36
37
  const [initialTags, setInitialTags] = useState<ReleaseTag[]>(imageReleaseTags ? imageReleaseTags : [])
37
38
  const [initialDescription, setInitialDescription] = useState(imageComment ? imageComment.comment : '')
@@ -44,13 +45,9 @@ export const ImageTagsContainer = ({
44
45
  const [createTags, setCreateTags] = useState<ReleaseTag[]>([])
45
46
  const [softDeleteTags, setSoftDeleteTags] = useState<ReleaseTag[]>([])
46
47
  const [hardDeleteTags, setHardDeleteTags] = useState<ReleaseTag[]>([])
47
- const [isSuperAdmin, setSuperAdmin] = useState<boolean>(false)
48
48
  const [descriptionValidationMessage, setDescriptionValidationMessage] = useState<string>('')
49
49
  const [textInput, setTextInput] = useState<string>('')
50
50
 
51
- useEffect(() => {
52
- initialise()
53
- }, [])
54
51
 
55
52
  useEffect(() => {
56
53
  reInitState()
@@ -60,16 +57,6 @@ export const ImageTagsContainer = ({
60
57
  setExistingTags(appReleaseTagNames ? appReleaseTagNames : [])
61
58
  }, [appReleaseTagNames])
62
59
 
63
- async function initialise() {
64
- try {
65
- const userRole = await getUserRole()
66
-
67
- const superAdmin = userRole?.result?.roles?.includes('role:super-admin___')
68
- setSuperAdmin(superAdmin)
69
- } catch (err) {
70
- showError(err)
71
- }
72
- }
73
60
 
74
61
  const reInitState = () => {
75
62
  if (forceReInit || !isEditing) {
@@ -38,3 +38,4 @@ export * from './ResizableTextarea'
38
38
  export { default as DebouncedSearch } from './DebouncedSearch/DebouncedSearch'
39
39
  export { default as Grid } from './Grid/Grid'
40
40
  export { default as ClipboardButton } from './ClipboardButton/ClipboardButton'
41
+ export * from './Hooks'