@devtron-labs/devtron-fe-common-lib 1.10.6 → 1.10.9

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.
@@ -1,7 +1,7 @@
1
1
  import { j as n, au as y, aw as k, av as W } from "./@vendor-DZHtXPTX.js";
2
2
  import V, { forwardRef as J, useMemo as P } from "react";
3
3
  import K, { getDefaultRegistry as q } from "@rjsf/core";
4
- import { T as F, j as N, c as v, b as S, a as Y, i as z, d as w, e as E, S as G } from "./@code-editor-DRIyM3Bp.js";
4
+ import { T as F, j as N, c as v, b as S, a as Y, i as z, d as w, e as E, S as G } from "./@code-editor-AsGkdwLJ.js";
5
5
  import Q, { components as D } from "react-select";
6
6
  import { ReactComponent as X } from "./assets/ic-chevron-down.fc70d7a7.svg";
7
7
  import { getUiOptions as B, getTemplate as $, getSubmitButtonOptions as Z, ADDITIONAL_PROPERTY_FLAG as L, errorId as ee, englishStringTranslator as te, TranslatableString as ne, titleId as re, canExpand as se, deepEquals as ae } from "@rjsf/utils";
@@ -7,8 +7,22 @@ export declare const KEYBOARD_KEYS_MAP: {
7
7
  readonly E: "E";
8
8
  readonly R: "R";
9
9
  readonly K: "K";
10
+ readonly X: "X";
11
+ readonly A: "A";
10
12
  readonly Escape: "Esc";
11
13
  readonly Enter: "↩";
14
+ readonly ArrowLeft: "←";
15
+ readonly ArrowRight: "→";
16
+ readonly ArrowUp: "↑";
17
+ readonly ArrowDown: "↓";
18
+ readonly PageUp: "PgUp";
19
+ readonly PageDown: "PgDn";
20
+ readonly Home: "Home";
21
+ readonly End: "End";
22
+ readonly Backspace: "⌫";
23
+ readonly Delete: "⌦";
24
+ readonly '.': ".";
25
+ readonly Space: "Space";
12
26
  };
13
27
  export type SupportedKeyboardKeysType = keyof typeof KEYBOARD_KEYS_MAP;
14
28
  export interface ShortcutType {
@@ -1,6 +1,6 @@
1
1
  import { ShortcutType } from './types';
2
2
  export declare const preprocessKeys: (keys: ShortcutType["keys"]) => {
3
- keys: ("Escape" | "Control" | "Alt" | "F" | "E" | "R" | "K" | "Shift" | "Meta" | "Enter")[];
3
+ keys: ("Escape" | "Control" | "Alt" | "F" | "E" | "R" | "K" | "X" | "A" | "Home" | "End" | "." | "Space" | "Shift" | "Meta" | "Enter" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "ArrowDown" | "PageUp" | "PageDown" | "Backspace" | "Delete")[];
4
4
  id: string;
5
5
  };
6
6
  export declare const verifyCallbackStack: (stack: ShortcutType["callbackStack"]) => void;
@@ -1,7 +1,7 @@
1
1
  import { UseUrlFiltersProps, UseUrlFiltersReturnType } from '../useUrlFilters';
2
2
  export interface UseStateFiltersProps<T> extends Pick<UseUrlFiltersProps<T, never>, 'initialSortKey'> {
3
3
  }
4
- export interface UseStateFiltersReturnType<T> extends Pick<UseUrlFiltersReturnType<T>, 'sortBy' | 'sortOrder' | 'handleSorting' | 'clearFilters' | 'changePage' | 'changePageSize' | 'offset' | 'pageSize' | 'searchKey' | 'handleSearch'> {
4
+ export interface UseStateFiltersReturnType<T> extends Pick<UseUrlFiltersReturnType<T>, 'sortBy' | 'sortOrder' | 'handleSorting' | 'clearFilters' | 'changePage' | 'changePageSize' | 'offset' | 'pageSize' | 'searchKey' | 'handleSearch' | 'isFilterApplied'> {
5
5
  }
6
6
  export interface PaginationType<T> extends Pick<UseUrlFiltersReturnType<T>, 'pageSize'> {
7
7
  pageNumber: number;
@@ -1,5 +1,5 @@
1
1
  import { SortingOrder } from '../../Constants';
2
- export interface UseUrlFiltersProps<T, K> {
2
+ export interface UseUrlFiltersProps<T, K extends {}> {
3
3
  /**
4
4
  * The key on which the sorting should be applied
5
5
  */
@@ -19,8 +19,8 @@ export interface UseUrlFiltersProps<T, K> {
19
19
  */
20
20
  redirectionMethod?: 'replace' | 'push';
21
21
  }
22
- export type UpdateSearchParamsOptionsType<T, K = unknown> = Partial<Pick<UseUrlFiltersProps<T, K>, 'redirectionMethod'>>;
23
- export type UseUrlFiltersReturnType<T, K = unknown> = K & {
22
+ export type UpdateSearchParamsOptionsType<T, K = {}> = Partial<Pick<UseUrlFiltersProps<T, K>, 'redirectionMethod'>>;
23
+ export type UseUrlFiltersReturnType<T, K = {}> = K & {
24
24
  /**
25
25
  * Currently applied page size
26
26
  */
@@ -67,4 +67,5 @@ export type UseUrlFiltersReturnType<T, K = unknown> = K & {
67
67
  * Update the search params with the passed object
68
68
  */
69
69
  updateSearchParams: (paramsToSerialize: Partial<K>, options?: UpdateSearchParamsOptionsType<T, K>) => void;
70
+ isFilterApplied: boolean;
70
71
  };
@@ -16,5 +16,5 @@ import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types';
16
16
  * ```
17
17
  *
18
18
  */
19
- declare const useUrlFilters: <T = string, K = unknown>({ initialSortKey, parseSearchParams, localStorageKey, redirectionMethod, }?: UseUrlFiltersProps<T, K>) => UseUrlFiltersReturnType<T, K>;
19
+ declare const useUrlFilters: <T = string, K = {}>({ initialSortKey, parseSearchParams, localStorageKey, redirectionMethod, }?: UseUrlFiltersProps<T, K>) => UseUrlFiltersReturnType<T, K>;
20
20
  export default useUrlFilters;
@@ -1 +1,2 @@
1
1
  export declare const setItemInLocalStorageIfKeyExists: (localStorageKey: string, value: string) => void;
2
+ export declare const areAnyAdditionalFiltersApplied: (parsedParams: Record<string | number, any>) => boolean;
@@ -1,6 +1,6 @@
1
1
  import { TooltipProps } from '@Common/Tooltip/types';
2
2
  import { ComponentSizeType } from '../../constants';
3
- import { ButtonHTMLAttributes, ReactElement } from 'react';
3
+ import { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactElement } from 'react';
4
4
  import { LinkProps } from 'react-router-dom';
5
5
  export declare enum ButtonVariantType {
6
6
  primary = "primary",
@@ -18,7 +18,8 @@ export declare enum ButtonStyleType {
18
18
  }
19
19
  export declare enum ButtonComponentType {
20
20
  button = "button",
21
- link = "link"
21
+ link = "link",
22
+ anchor = "anchor"
22
23
  }
23
24
  export type ButtonProps<ComponentType extends ButtonComponentType = ButtonComponentType.button> = (ComponentType extends ButtonComponentType.link ? {
24
25
  component: ButtonComponentType.link;
@@ -27,7 +28,19 @@ export type ButtonProps<ComponentType extends ButtonComponentType = ButtonCompon
27
28
  */
28
29
  linkProps: Omit<LinkProps, 'children' | 'styles' | 'className' | 'onClick'>;
29
30
  buttonProps?: never;
31
+ anchorProps?: never;
30
32
  onClick?: LinkProps['onClick'];
33
+ } : ComponentType extends ButtonComponentType.anchor ? {
34
+ component: ButtonComponentType.anchor;
35
+ linkProps?: never;
36
+ buttonProps?: never;
37
+ /**
38
+ * Props for the anchor component
39
+ *
40
+ * Note: The target is '_blank' & rel is 'noopener noreferrer' by default.
41
+ */
42
+ anchorProps: Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'children' | 'styles' | 'className' | 'onClick'>;
43
+ onClick?: AnchorHTMLAttributes<HTMLAnchorElement>['onClick'];
31
44
  } : {
32
45
  /**
33
46
  * Component to be rendered from the available options
@@ -40,6 +53,7 @@ export type ButtonProps<ComponentType extends ButtonComponentType = ButtonCompon
40
53
  */
41
54
  buttonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'styles' | 'className' | 'disabled' | 'onClick'>;
42
55
  linkProps?: never;
56
+ anchorProps?: never;
43
57
  onClick?: ButtonHTMLAttributes<HTMLButtonElement>['onClick'];
44
58
  }) & {
45
59
  /**
@@ -0,0 +1,3 @@
1
+ import { BulkSelectionActionWidgetProps } from './types';
2
+ declare const BulkSelectionActionWidget: ({ count, handleClearBulkSelection, parentRef, BulkActionsComponent, }: BulkSelectionActionWidgetProps) => JSX.Element;
3
+ export default BulkSelectionActionWidget;
@@ -0,0 +1,3 @@
1
+ import { InternalTableProps } from './types';
2
+ declare const InternalTable: ({ filtersVariant, filterData, rows, getRows, columns, ViewWrapper, resizableConfig, emptyStateConfig, additionalProps, areColumnsConfigurable, filter, setVisibleColumns, visibleColumns, stylesConfig, loading, bulkSelectionConfig, bulkSelectionReturnValue, handleClearBulkSelection, handleToggleBulkSelectionOnRow, paginationVariant, RowActionsOnHoverComponent, }: InternalTableProps) => JSX.Element;
3
+ export default InternalTable;
@@ -0,0 +1,3 @@
1
+ import { TableProps } from './types';
2
+ declare const TableWrapper: (tableProps: TableProps) => JSX.Element;
3
+ export default TableWrapper;
@@ -0,0 +1,7 @@
1
+ export declare const SEARCH_SORT_CHANGE_DEBOUNCE_TIME = 350; /** in ms */
2
+ export declare const LOCAL_STORAGE_EXISTS: boolean;
3
+ export declare const LOCAL_STORAGE_KEY_FOR_VISIBLE_COLUMNS = "generic-table-configurable-columns";
4
+ export declare const BULK_ACTION_GUTTER_LABEL = "bulk-action-gutter";
5
+ export declare const EVENT_TARGET: EventTarget;
6
+ export declare const DRAG_SELECTOR_IDENTIFIER = "table-drag-selector";
7
+ export declare const SHIMMER_DUMMY_ARRAY: number[];
@@ -0,0 +1,3 @@
1
+ export { default as Table } from './Table.component';
2
+ export { FiltersTypeEnum, PaginationEnum, SignalEnum as TableSignalEnum } from './types';
3
+ export type { ViewWrapperProps as TableViewWrapperProps, Column as TableColumnType, TableProps, CellComponentProps as TableCellComponentProps, } from './types';
@@ -0,0 +1,193 @@
1
+ import { Dispatch, FunctionComponent, PropsWithChildren, SetStateAction } from 'react';
2
+ import { SortableTableHeaderCellProps, useResizableTableConfig } from '../../../Common/SortableTableHeaderCell';
3
+ import { UseStateFiltersProps, UseStateFiltersReturnType, UseUrlFiltersProps } from '../../../Common/Hooks';
4
+ import { GenericEmptyStateType } from '../../../Common/index';
5
+ import { GenericFilterEmptyStateProps } from '@Common/EmptyState/types';
6
+ import { useBulkSelection, UseBulkSelectionProps } from '../BulkSelection';
7
+ export interface UseFiltersReturnType extends UseStateFiltersReturnType<string> {
8
+ }
9
+ export declare enum SignalEnum {
10
+ ENTER_PRESSED = "enter-pressed",
11
+ DELETE_PRESSED = "delete-pressed",
12
+ ESCAPE_PRESSED = "escape-pressed",
13
+ OPEN_CONTEXT_MENU = "open-context-menu",
14
+ ROW_CLICKED = "row-clicked"
15
+ }
16
+ export interface SignalsType<T extends string = SignalEnum> extends Pick<EventTarget, 'addEventListener' | 'removeEventListener'> {
17
+ addEventListener: (type: T, callback: (event: CustomEvent) => void, options?: Parameters<EventTarget['addEventListener']>[2]) => ReturnType<EventTarget['addEventListener']>;
18
+ removeEventListener: (type: T, callback: (event: CustomEvent) => void, options?: Parameters<EventTarget['removeEventListener']>[2]) => ReturnType<EventTarget['removeEventListener']>;
19
+ }
20
+ type SizeType = {
21
+ /** This signifies this column is resizable */
22
+ range: {
23
+ startWidth: number;
24
+ minWidth: number;
25
+ maxWidth: number | 'infinite';
26
+ };
27
+ /** If we want a fixed width */
28
+ fixed?: never;
29
+ } | {
30
+ range?: never;
31
+ fixed: number;
32
+ } | null;
33
+ type BaseColumnType = {
34
+ /** This is the key using which we will fetch the data of */
35
+ field: string;
36
+ /** This is the string that will be displayed to the user as header text */
37
+ label?: string;
38
+ /**
39
+ * If we want resizable columns, then every column has to have a fixed height
40
+ * If we specify size to be null then the size be will set to 1fr
41
+ */
42
+ size: SizeType;
43
+ horizontallySticky?: boolean;
44
+ };
45
+ interface AdditionalProps {
46
+ [key: string]: unknown;
47
+ }
48
+ export type RowType = {
49
+ id: string;
50
+ data: Record<string, unknown>;
51
+ };
52
+ export type RowsType = RowType[];
53
+ export interface CellComponentProps extends Pick<BaseColumnType, 'field'>, AdditionalProps {
54
+ signals: SignalsType;
55
+ value: unknown;
56
+ row: RowType;
57
+ filterData: UseFiltersReturnType;
58
+ isRowActive: boolean;
59
+ }
60
+ export type Column = Pick<SortableTableHeaderCellProps, 'showTippyOnTruncate'> & BaseColumnType & {
61
+ CellComponent?: FunctionComponent<CellComponentProps>;
62
+ } & ({
63
+ isSortable: true;
64
+ /**
65
+ * Compare two rows when sorting is triggered on this column
66
+ * Values fed are from the field key in the row's data object
67
+ * @returns -1 if a < b, 0 if a === b, 1 if a > b
68
+ */
69
+ comparator?: (a: unknown, b: unknown) => number;
70
+ } | {
71
+ isSortable?: false;
72
+ comparator?: never;
73
+ });
74
+ type BulkSelectionConfigType = Pick<UseBulkSelectionProps<unknown>, 'getSelectAllDialogStatus'> & {
75
+ /** Make sure to wrap it in useCallback */
76
+ onBulkSelectionChanged: (selectedRows: RowsType) => void;
77
+ BulkActionsComponent: FunctionComponent<{}>;
78
+ };
79
+ export declare enum PaginationEnum {
80
+ PAGINATED = "paginated",
81
+ INFINITE = "infinite",
82
+ NOT_PAGINATED = "not-paginated"
83
+ }
84
+ export declare enum FiltersTypeEnum {
85
+ STATE = "state",
86
+ URL = "url",
87
+ NONE = "none"
88
+ }
89
+ export interface ConfigurableColumnsType {
90
+ allColumns: Column[];
91
+ visibleColumns: Column[];
92
+ setVisibleColumns: Dispatch<SetStateAction<ConfigurableColumnsType['visibleColumns']>>;
93
+ }
94
+ interface GetRowsProps extends Pick<UseFiltersReturnType, 'offset' | 'pageSize' | 'searchKey' | 'sortBy' | 'sortOrder'> {
95
+ }
96
+ type AdditionalFilterPropsType<T extends Exclude<FiltersTypeEnum, FiltersTypeEnum.NONE>> = T extends FiltersTypeEnum.URL ? Pick<UseUrlFiltersProps<string, unknown>, 'parseSearchParams' | 'localStorageKey' | 'redirectionMethod' | 'initialSortKey'> : Pick<UseStateFiltersProps<string>, 'initialSortKey'>;
97
+ export type ViewWrapperProps = PropsWithChildren<Pick<UseFiltersReturnType, 'offset' | 'handleSearch' | 'searchKey' | 'sortBy' | 'sortOrder' | 'clearFilters'> & AdditionalProps & Partial<ConfigurableColumnsType> & {
98
+ areRowsLoading: boolean;
99
+ }>;
100
+ export type InternalTableProps = Required<Pick<ConfigurableColumnsType, 'visibleColumns' | 'setVisibleColumns'>> & {
101
+ id: `table__${string}`;
102
+ loading?: boolean;
103
+ paginationVariant: PaginationEnum;
104
+ /**
105
+ * Memoize columns before passing as props.
106
+ *
107
+ * For columns from backend: initialize as empty array and set loading
108
+ * to true until API call completes.
109
+ */
110
+ columns: Column[];
111
+ /** If bulk selections are not a concern omit this prop */
112
+ bulkSelectionConfig?: BulkSelectionConfigType;
113
+ emptyStateConfig: {
114
+ noRowsConfig: Omit<GenericEmptyStateType, 'children'>;
115
+ noRowsForFilterConfig?: Pick<GenericFilterEmptyStateProps, 'title' | 'subTitle'> & {
116
+ clearFilters: () => void;
117
+ };
118
+ };
119
+ filterData: UseFiltersReturnType | null;
120
+ resizableConfig: ReturnType<typeof useResizableTableConfig> | null;
121
+ /**
122
+ * Enable this to let users choose which columns to display.
123
+ * Example: Resource Browser > Node Listing
124
+ *
125
+ * Using the provided id for this table, we will store the user's preference in localStorage
126
+ */
127
+ areColumnsConfigurable?: boolean;
128
+ additionalProps?: AdditionalProps;
129
+ /** Control the look of the table using this prop */
130
+ stylesConfig?: {
131
+ showSeparatorBetweenRows: boolean;
132
+ };
133
+ /**
134
+ * Use this component to display additional content at the end of a row when it is hovered over.
135
+ */
136
+ RowActionsOnHoverComponent?: FunctionComponent<{
137
+ row: RowType;
138
+ }>;
139
+ bulkSelectionReturnValue: ReturnType<typeof useBulkSelection> | null;
140
+ handleClearBulkSelection: () => void;
141
+ handleToggleBulkSelectionOnRow: (row: RowType) => void;
142
+ ViewWrapper?: FunctionComponent<ViewWrapperProps>;
143
+ } & ({
144
+ /**
145
+ * Direct rows data for frontend-only datasets like resource browser.
146
+ */
147
+ rows: RowsType;
148
+ /**
149
+ * Use `getRows` function instead for data that needs to be fetched from backend with pagination/sorting/filtering.
150
+ */
151
+ getRows?: never;
152
+ } | {
153
+ rows?: never;
154
+ /** NOTE: Sorting on frontend is only handled if rows is provided instead of getRows */
155
+ getRows: (props: GetRowsProps) => Promise<RowsType>;
156
+ }) & ({
157
+ filtersVariant: FiltersTypeEnum.URL;
158
+ /**
159
+ * props for useUrlFilters/useStateFilters hooks
160
+ */
161
+ additionalFilterProps?: AdditionalFilterPropsType<FiltersTypeEnum.URL>;
162
+ /**
163
+ * This func is used to filter the rows based on filter data.
164
+ * Only applicable if filtersVariant is NOT set to NONE
165
+ *
166
+ * If filter is only being used for sorting, then send `noop` in this prop
167
+ */
168
+ filter: (row: RowType, filterData: UseFiltersReturnType) => boolean;
169
+ } | {
170
+ filtersVariant: FiltersTypeEnum.STATE;
171
+ additionalFilterProps?: AdditionalFilterPropsType<FiltersTypeEnum.STATE>;
172
+ filter: (row: RowType, filterData: UseFiltersReturnType) => boolean;
173
+ } | {
174
+ filtersVariant: FiltersTypeEnum.NONE;
175
+ additionalFilterProps?: never;
176
+ filter?: never;
177
+ });
178
+ export type UseResizableTableConfigWrapperProps = Omit<InternalTableProps, 'resizableConfig'>;
179
+ export type TableWithBulkSelectionProps = Omit<UseResizableTableConfigWrapperProps, 'bulkSelectionReturnValue' | 'handleClearBulkSelection' | 'handleToggleBulkSelectionOnRow'>;
180
+ export type VisibleColumnsWrapperProps = Omit<TableWithBulkSelectionProps, 'visibleColumns' | 'setVisibleColumns'>;
181
+ export type FilterWrapperProps = Omit<VisibleColumnsWrapperProps, 'filterData'>;
182
+ export type TableProps = Pick<FilterWrapperProps, 'additionalFilterProps' | 'bulkSelectionConfig' | 'areColumnsConfigurable' | 'emptyStateConfig' | 'filtersVariant' | 'filter' | 'additionalProps' | 'columns' | 'getRows' | 'rows' | 'paginationVariant' | 'stylesConfig' | 'id' | 'RowActionsOnHoverComponent' | 'loading' | 'ViewWrapper'>;
183
+ export interface BulkSelectionActionWidgetProps extends Pick<BulkSelectionConfigType, 'BulkActionsComponent'> {
184
+ count: number;
185
+ handleClearBulkSelection: () => void;
186
+ parentRef: React.RefObject<HTMLDivElement>;
187
+ }
188
+ export type ConfigurableColumnsConfigType = Record<string, ConfigurableColumnsType['visibleColumns']>;
189
+ export interface GetFilteringPromiseProps {
190
+ searchSortTimeoutRef: React.MutableRefObject<number>;
191
+ callback: () => Promise<RowsType> | RowsType;
192
+ }
193
+ export {};
@@ -0,0 +1,6 @@
1
+ import { InternalTableProps, RowsType } from './types';
2
+ declare const useTableWithKeyboardShortcuts: ({ bulkSelectionConfig, handleToggleBulkSelectionOnRow, bulkSelectionReturnValue, }: Pick<InternalTableProps, "bulkSelectionConfig" | "bulkSelectionReturnValue" | "handleToggleBulkSelectionOnRow">, visibleRows: RowsType) => {
3
+ activeRowIndex: number;
4
+ setActiveRowIndex: import('react').Dispatch<import('react').SetStateAction<number>>;
5
+ };
6
+ export default useTableWithKeyboardShortcuts;
@@ -0,0 +1,6 @@
1
+ import { Column, ConfigurableColumnsType, GetFilteringPromiseProps, RowsType, TableProps, UseFiltersReturnType } from './types';
2
+ export declare const searchAndSortRows: (rows: TableProps["rows"], filter: TableProps["filter"], filterData: UseFiltersReturnType, comparator?: Column["comparator"]) => RowsType;
3
+ export declare const getVisibleColumnsFromLocalStorage: ({ allColumns, id, }: Pick<ConfigurableColumnsType, "allColumns"> & Pick<TableProps, "id">) => Column[];
4
+ export declare const setVisibleColumnsToLocalStorage: ({ id, visibleColumns, }: Pick<ConfigurableColumnsType, "visibleColumns"> & Pick<TableProps, "id">) => void;
5
+ export declare const getVisibleColumns: ({ areColumnsConfigurable, columns, id, }: Pick<TableProps, "areColumnsConfigurable" | "columns" | "id">) => Column[];
6
+ export declare const getFilteringPromise: ({ searchSortTimeoutRef, callback }: GetFilteringPromiseProps) => Promise<RowsType>;
@@ -69,6 +69,7 @@ export * from './CustomInput';
69
69
  export * from './InfoBlock';
70
70
  export * from './CodeEditorWrapper';
71
71
  export * from './SSOProviderIcon';
72
+ export * from './Table';
72
73
  export * from './Backdrop';
73
74
  export * from './CountrySelect';
74
75
  export * from './PhoneInput';