@devtron-labs/devtron-fe-common-lib 0.0.53-beta-3 → 0.0.53-beta-5

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.
@@ -12,9 +12,9 @@ export declare const SourceTypeMap: {
12
12
  BranchRegex: string;
13
13
  };
14
14
  export declare function getUserRole(appName?: string): Promise<UserRole>;
15
- export declare function setImageTags(request: any, pipelineId: number, artifactId: number): Promise<ResponseType>;
15
+ export declare function setImageTags(request: any, pipelineId: number, artifactId: number): Promise<ResponseType<any>>;
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
+ export declare function fetchChartTemplateVersions(): Promise<ResponseType<any>>;
20
20
  export {};
@@ -1,8 +1,39 @@
1
- import { FunctionComponent } from 'react';
1
+ /// <reference types="react" />
2
2
  import { SearchBarProps } from './types';
3
3
  import './searchBar.scss';
4
4
  /**
5
5
  * Generic search input component with support for enter based and debounced search
6
+ * Note: The component is uncontrolled
7
+ *
8
+ * @example Usage with default debounced search
9
+ * ```tsx
10
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce />
11
+ * ```
12
+ *
13
+ * @example Initial search text
14
+ * ```tsx
15
+ * <SearchBar initialSearchText="Keyword" />
16
+ * ```
17
+ *
18
+ * @example Custom width
19
+ * ```tsx
20
+ * <SearchBar containerClassName="w-300" />
21
+ * ```
22
+ *
23
+ * @example Trigger search on enter key press
24
+ * ```tsx
25
+ * <SearchBar handleEnter={triggerSearchApi} />
26
+ * ```
27
+ *
28
+ * @example Custom timeout for debounced search
29
+ * ```tsx
30
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce debounceTimeout={500} />
31
+ * ```
32
+ *
33
+ * @example Placeholder for the search
34
+ * ```tsx
35
+ * <SearchBar inputProps={{ placeholder: 'Enter search text' }} />
36
+ * ```
6
37
  */
7
- declare const SearchBar: FunctionComponent<SearchBarProps>;
38
+ declare const SearchBar: ({ initialSearchText, handleSearchChange, handleEnter, inputProps, containerClassName, shouldDebounce, debounceTimeout, }: SearchBarProps) => JSX.Element;
8
39
  export default SearchBar;
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component';
2
+ export type { SearchBarProps } from './types';
@@ -1,4 +1,4 @@
1
- import { InputHTMLAttributes, SyntheticEvent } from 'react';
1
+ import { InputHTMLAttributes } from 'react';
2
2
  export interface SearchBarProps {
3
3
  /**
4
4
  * Initial search text
@@ -13,7 +13,7 @@ export interface SearchBarProps {
13
13
  /**
14
14
  * Enter event handler for the search input
15
15
  */
16
- handleEnter?: (event: SyntheticEvent) => void;
16
+ handleEnter?: (searchText: string) => void;
17
17
  /**
18
18
  * Input props for the search input
19
19
  */
@@ -2,10 +2,23 @@ import React, { ReactNode, CSSProperties } from 'react';
2
2
  import { Placement } from 'tippy.js';
3
3
  import { ImageComment, ReleaseTag } from './ImageTags.Types';
4
4
  import { DockerConfigOverrideType, TaskErrorObj } from '.';
5
- export interface ResponseType {
5
+ /**
6
+ * Generic response type object with support for overriding the result type
7
+ *
8
+ * @example Default usage:
9
+ * ```ts
10
+ * interface UserResponse extends ResponseType {}
11
+ * ```
12
+ *
13
+ * @example Override the response type:
14
+ * ```ts
15
+ * interface UserResponse extends ResponseType<Record<string, string>> {}
16
+ * ```
17
+ */
18
+ export interface ResponseType<T = any> {
6
19
  code: number;
7
20
  status: string;
8
- result?: any;
21
+ result?: T;
9
22
  errors?: any;
10
23
  }
11
24
  export interface APIOptions {
@@ -26,7 +26,7 @@ export * from './Common.service';
26
26
  export * from './Checkbox';
27
27
  export { default as EmptyState } from './EmptyState/EmptyState';
28
28
  export { default as GenericEmptyState } from './EmptyState/GenericEmptyState';
29
- export { default as SearchBar } from './SearchBar/SearchBar.component';
29
+ export * from './SearchBar';
30
30
  export { default as Toggle } from './Toggle/Toggle';
31
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable';
32
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup';
package/dist/index.js CHANGED
@@ -24618,9 +24618,40 @@ styleInject(css_248z$4);
24618
24618
 
24619
24619
  /**
24620
24620
  * Generic search input component with support for enter based and debounced search
24621
+ * Note: The component is uncontrolled
24622
+ *
24623
+ * @example Usage with default debounced search
24624
+ * ```tsx
24625
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce />
24626
+ * ```
24627
+ *
24628
+ * @example Initial search text
24629
+ * ```tsx
24630
+ * <SearchBar initialSearchText="Keyword" />
24631
+ * ```
24632
+ *
24633
+ * @example Custom width
24634
+ * ```tsx
24635
+ * <SearchBar containerClassName="w-300" />
24636
+ * ```
24637
+ *
24638
+ * @example Trigger search on enter key press
24639
+ * ```tsx
24640
+ * <SearchBar handleEnter={triggerSearchApi} />
24641
+ * ```
24642
+ *
24643
+ * @example Custom timeout for debounced search
24644
+ * ```tsx
24645
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce debounceTimeout={500} />
24646
+ * ```
24647
+ *
24648
+ * @example Placeholder for the search
24649
+ * ```tsx
24650
+ * <SearchBar inputProps={{ placeholder: 'Enter search text' }} />
24651
+ * ```
24621
24652
  */
24622
24653
  var SearchBar = function (_a) {
24623
- var _b = _a.initialSearchText, initialSearchText = _b === void 0 ? '' : _b, _c = _a.handleSearchChange, handleSearchChange = _c === void 0 ? noop$1 : _c, _d = _a.handleEnter, handleEnter = _d === void 0 ? noop$1 : _d, _e = _a.inputProps, inputProps = _e === void 0 ? {} : _e, containerClassName = _a.containerClassName, _f = _a.shouldDebounce, shouldDebounce = _f === void 0 ? false : _f, _g = _a.debounceTimeout, debounceTimeout = _g === void 0 ? 300 : _g;
24654
+ var _b = _a.initialSearchText, initialSearchText = _b === void 0 ? '' : _b, _c = _a.handleSearchChange, handleSearchChange = _c === void 0 ? function () { } : _c, _d = _a.handleEnter, handleEnter = _d === void 0 ? function () { } : _d, _e = _a.inputProps, inputProps = _e === void 0 ? {} : _e, containerClassName = _a.containerClassName, _f = _a.shouldDebounce, shouldDebounce = _f === void 0 ? false : _f, _g = _a.debounceTimeout, debounceTimeout = _g === void 0 ? 300 : _g;
24624
24655
  var _h = __read(React.useState(!!initialSearchText), 2), showClearButton = _h[0], setShowClearButton = _h[1];
24625
24656
  var inputRef = React.useRef();
24626
24657
  var debouncedSearchChange = React.useCallback(debounce$2(handleSearchChange, debounceTimeout), [
@@ -24637,18 +24668,21 @@ var SearchBar = function (_a) {
24637
24668
  handleSearchChange(value);
24638
24669
  }
24639
24670
  };
24671
+ var _applySearch = function (value) {
24672
+ handleSearchChange(value);
24673
+ handleEnter(value);
24674
+ };
24640
24675
  var handleKeyDown = function (e) {
24641
24676
  var key = e.key;
24642
24677
  if (key === 'Enter') {
24643
24678
  var inputTarget = e.target;
24644
- var event_1 = __assign(__assign({}, e), { target: __assign(__assign({}, inputTarget), { value: inputTarget.value.trim() }) });
24645
- handleSearchChange(event_1.target.value);
24646
- handleEnter(event_1);
24679
+ var value = inputTarget.value.trim();
24680
+ _applySearch(value);
24647
24681
  }
24648
24682
  };
24649
24683
  var clearSearch = function () {
24650
24684
  inputRef.current.value = '';
24651
- handleSearchChange('');
24685
+ _applySearch('');
24652
24686
  };
24653
24687
  return (jsxRuntime.jsx("div", __assign({ className: containerClassName }, { children: jsxRuntime.jsxs("div", __assign({ className: "search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32" }, { children: [jsxRuntime.jsx(SvgIcSearch, { className: "search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" }), jsxRuntime.jsx("input", __assign({ placeholder: "Search", "data-testid": "search-bar", type: "text" }, inputProps, { defaultValue: initialSearchText, className: "search-bar__input bcn-0 dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ".concat(showClearButton ? 'pr-30' : 'pr-10'), onChange: handleChange, onKeyDown: handleKeyDown, ref: inputRef })), showClearButton && (jsxRuntime.jsx("button", __assign({ className: "flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5", type: "button", onClick: clearSearch, "aria-label": "Clear search" }, { children: jsxRuntime.jsx(SvgIcErrorCross, { className: "icon-dim-18 icon-n4 dc__vertical-align-middle" }) })))] })) })));
24654
24688
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.53-beta-3",
3
+ "version": "0.0.53-beta-5",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,22 +1,53 @@
1
- import { ChangeEvent, FunctionComponent, useCallback, useRef, useState, KeyboardEvent } from 'react'
1
+ import { ChangeEvent, useCallback, useRef, useState, KeyboardEvent } from 'react'
2
2
  import { ReactComponent as Search } from '../../Assets/Icon/ic-search.svg'
3
3
  import { ReactComponent as Clear } from '../../Assets/Icon/ic-error-cross.svg'
4
4
  import { SearchBarProps } from './types'
5
5
  import './searchBar.scss'
6
- import { debounce, noop } from '../Helper'
6
+ import { debounce } from '../Helper'
7
7
 
8
8
  /**
9
9
  * Generic search input component with support for enter based and debounced search
10
+ * Note: The component is uncontrolled
11
+ *
12
+ * @example Usage with default debounced search
13
+ * ```tsx
14
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce />
15
+ * ```
16
+ *
17
+ * @example Initial search text
18
+ * ```tsx
19
+ * <SearchBar initialSearchText="Keyword" />
20
+ * ```
21
+ *
22
+ * @example Custom width
23
+ * ```tsx
24
+ * <SearchBar containerClassName="w-300" />
25
+ * ```
26
+ *
27
+ * @example Trigger search on enter key press
28
+ * ```tsx
29
+ * <SearchBar handleEnter={triggerSearchApi} />
30
+ * ```
31
+ *
32
+ * @example Custom timeout for debounced search
33
+ * ```tsx
34
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce debounceTimeout={500} />
35
+ * ```
36
+ *
37
+ * @example Placeholder for the search
38
+ * ```tsx
39
+ * <SearchBar inputProps={{ placeholder: 'Enter search text' }} />
40
+ * ```
10
41
  */
11
- const SearchBar: FunctionComponent<SearchBarProps> = ({
42
+ const SearchBar = ({
12
43
  initialSearchText = '',
13
- handleSearchChange = noop,
14
- handleEnter = noop,
44
+ handleSearchChange = () => {},
45
+ handleEnter = () => {},
15
46
  inputProps = {},
16
47
  containerClassName,
17
48
  shouldDebounce = false,
18
49
  debounceTimeout = 300,
19
- }) => {
50
+ }: SearchBarProps) => {
20
51
  const [showClearButton, setShowClearButton] = useState(!!initialSearchText)
21
52
  const inputRef = useRef<HTMLInputElement>()
22
53
  const debouncedSearchChange = useCallback(debounce(handleSearchChange, debounceTimeout), [
@@ -34,20 +65,24 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
34
65
  }
35
66
  }
36
67
 
68
+ const _applySearch = (value: string) => {
69
+ handleSearchChange(value)
70
+ handleEnter(value)
71
+ }
72
+
37
73
  const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
38
74
  const { key } = e
39
75
 
40
76
  if (key === 'Enter') {
41
77
  const inputTarget = e.target as HTMLInputElement
42
- const event = { ...e, target: { ...inputTarget, value: inputTarget.value.trim() } }
43
- handleSearchChange(event.target.value)
44
- handleEnter(event)
78
+ const value = inputTarget.value.trim()
79
+ _applySearch(value)
45
80
  }
46
81
  }
47
82
 
48
83
  const clearSearch = () => {
49
84
  inputRef.current.value = ''
50
- handleSearchChange('')
85
+ _applySearch('')
51
86
  }
52
87
 
53
88
  return (
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component'
2
+ export type { SearchBarProps } from './types'
@@ -1,4 +1,4 @@
1
- import { InputHTMLAttributes, SyntheticEvent } from 'react'
1
+ import { InputHTMLAttributes } from 'react'
2
2
 
3
3
  export interface SearchBarProps {
4
4
  /**
@@ -14,7 +14,7 @@ export interface SearchBarProps {
14
14
  /**
15
15
  * Enter event handler for the search input
16
16
  */
17
- handleEnter?: (event: SyntheticEvent) => void
17
+ handleEnter?: (searchText: string) => void
18
18
  /**
19
19
  * Input props for the search input
20
20
  */
@@ -3,10 +3,23 @@ import { Placement } from 'tippy.js'
3
3
  import { ImageComment, ReleaseTag } from './ImageTags.Types'
4
4
  import { DockerConfigOverrideType, TaskErrorObj } from '.'
5
5
 
6
- export interface ResponseType {
6
+ /**
7
+ * Generic response type object with support for overriding the result type
8
+ *
9
+ * @example Default usage:
10
+ * ```ts
11
+ * interface UserResponse extends ResponseType {}
12
+ * ```
13
+ *
14
+ * @example Override the response type:
15
+ * ```ts
16
+ * interface UserResponse extends ResponseType<Record<string, string>> {}
17
+ * ```
18
+ */
19
+ export interface ResponseType<T = any> {
7
20
  code: number
8
21
  status: string
9
- result?: any
22
+ result?: T
10
23
  errors?: any
11
24
  }
12
25
 
@@ -26,7 +26,7 @@ export * from './Common.service'
26
26
  export * from './Checkbox'
27
27
  export { default as EmptyState } from './EmptyState/EmptyState'
28
28
  export { default as GenericEmptyState } from './EmptyState/GenericEmptyState'
29
- export { default as SearchBar } from './SearchBar/SearchBar.component'
29
+ export * from './SearchBar'
30
30
  export { default as Toggle } from './Toggle/Toggle'
31
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
32
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'