@addev-be/ui 0.17.0 → 0.17.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/ui",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc -b --watch",
@@ -147,6 +147,7 @@ export const useDataGrid = <R,>(
147
147
  updatedRows,
148
148
  editRow,
149
149
  addRow,
150
+ addRows,
150
151
  updateRow,
151
152
  clearChangedRows,
152
153
  } = useDataGridChangedRows<R>(rowKeyGetter as any, onRowAdded);
@@ -291,6 +292,7 @@ export const useDataGrid = <R,>(
291
292
  updatedRows,
292
293
  editRow,
293
294
  addRow,
295
+ addRows,
294
296
  updateRow,
295
297
  clearChangedRows,
296
298
 
@@ -325,6 +327,7 @@ export const useDataGrid = <R,>(
325
327
  updatedRows,
326
328
  editRow,
327
329
  addRow,
330
+ addRows,
328
331
  updateRow,
329
332
  clearChangedRows,
330
333
  setRows,
@@ -367,6 +370,7 @@ export const useDataGrid = <R,>(
367
370
  setRows: () => {},
368
371
  editRow: () => {},
369
372
  addRow: () => {},
373
+ addRows: () => {},
370
374
  updateRow: () => {},
371
375
  clearChangedRows: () => {},
372
376
  }),
@@ -15,6 +15,13 @@ export const useDataGridChangedRows = <R>(
15
15
  [onRowAdded]
16
16
  );
17
17
 
18
+ const addRows = useCallback(
19
+ (rows: R[]) => {
20
+ rows.forEach(addRow);
21
+ },
22
+ [addRow]
23
+ );
24
+
18
25
  const updateRow = useCallback(
19
26
  (row: Partial<R>) => {
20
27
  const rowKey = rowKeyGetter(row);
@@ -83,6 +90,7 @@ export const useDataGridChangedRows = <R>(
83
90
  updatedRows,
84
91
  editRow,
85
92
  addRow,
93
+ addRows,
86
94
  updateRow,
87
95
  clearChangedRows,
88
96
  };
@@ -15,10 +15,10 @@ import {
15
15
  } from './constants';
16
16
  import { DataGridContextProps, DataGridProps, DataGridRefProps } from './types';
17
17
 
18
- import { VirtualScroller } from '../VirtualScroller';
19
18
  import { DataGridFooter } from './DataGridFooter';
20
19
  import { DataGridHeader } from './DataGridHeader';
21
20
  import { DataGridRowTemplate } from './DataGridRowTemplate';
21
+ import { VirtualScroller } from '../VirtualScroller';
22
22
  import { useDataGrid } from './hooks';
23
23
 
24
24
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -31,7 +31,7 @@ export const DataGridInner = <R,>(
31
31
  }: DataGridProps<R> & {
32
32
  contextOverride?: Partial<DataGridContextProps<R>>;
33
33
  },
34
- ref: ForwardedRef<DataGridRefProps>
34
+ ref: ForwardedRef<DataGridRefProps<R>>
35
35
  ) => {
36
36
  const scrollableRef = useRef<HTMLDivElement>(null);
37
37
  const { className } = props;
@@ -46,6 +46,7 @@ export const DataGridInner = <R,>(
46
46
  onVisibleRowsChange,
47
47
  refresh,
48
48
  setSelectedKeys,
49
+ addRows,
49
50
  fixedColumnsCount,
50
51
  resizingColumnKey,
51
52
  moveResizing,
@@ -57,8 +58,9 @@ export const DataGridInner = <R,>(
57
58
  () => ({
58
59
  refresh: refresh ?? (() => {}),
59
60
  setSelectedKeys,
61
+ addRows,
60
62
  }),
61
- [refresh, setSelectedKeys]
63
+ [addRows, refresh, setSelectedKeys]
62
64
  );
63
65
 
64
66
  const hasFooter = Object.values(columns).some((col) => col.footer);
@@ -210,6 +210,7 @@ export type DataGridContextProps<R> = DataGridProps<R> & {
210
210
  updatedRows: DataGridEditedRows<R>;
211
211
  editRow: (row: Partial<R>) => void;
212
212
  addRow: (row: R) => void;
213
+ addRows: (rows: R[]) => void;
213
214
  updateRow: (row: Partial<R>) => void;
214
215
  clearChangedRows: (keys?: string[]) => void;
215
216
  };
@@ -359,9 +360,10 @@ export type DataGridRowTemplateProps<R> = {
359
360
  context: DataGridContext<R>;
360
361
  };
361
362
 
362
- export type DataGridRefProps = {
363
+ export type DataGridRefProps<R> = {
363
364
  refresh: () => void;
364
365
  setSelectedKeys: (keys: string[]) => void;
366
+ addRows: (rows: R[]) => void;
365
367
  };
366
368
 
367
369
  export type DataGridEditedRows<R> = Partial<R>[];
@@ -36,7 +36,7 @@ export const SqlRequestDataGridInner = <R,>(
36
36
  onSelectionChange: onSelectionChangeFromProps,
37
37
  ...props
38
38
  }: SqlRequestDataGridProps<R>,
39
- ref: ForwardedRef<DataGridRefProps>
39
+ ref: ForwardedRef<DataGridRefProps<R>>
40
40
  ) => {
41
41
  const currentRows = useRef<R[]>([]);
42
42
  const [rows, setRows] = useState<R[]>([]);
@@ -53,7 +53,7 @@ export const SqlRequestDataGridInner = <R,>(
53
53
  const [sqlRequest, sqlIdRequest, sqlPartialRequest] = useSqlRequestHandler<R>(
54
54
  props.type
55
55
  );
56
- const gridRef = useRef<DataGridRefProps>(null);
56
+ const gridRef = useRef<DataGridRefProps<R>>(null);
57
57
 
58
58
  const [conditions, setConditions] = useState<Record<string, ConditionDTO>>(
59
59
  {}
@@ -375,6 +375,7 @@ export const SqlRequestDataGridInner = <R,>(
375
375
  () => ({
376
376
  refresh,
377
377
  setSelectedKeys: gridRef.current?.setSelectedKeys ?? (() => {}),
378
+ addRows: gridRef.current?.addRows ?? (() => {}),
378
379
  }),
379
380
  [refresh]
380
381
  );
@@ -1,7 +1,7 @@
1
1
  import styled, { css } from 'styled-components';
2
2
 
3
3
  export const inputStyle = css`
4
- font-family: inherit;
4
+ font-family: var(--font-sans);
5
5
  font-size: inherit;
6
6
  color: inherit;
7
7
  border: 1px solid var(--color-gray-300);
@@ -15,9 +15,7 @@ export const inputStyle = css`
15
15
  }
16
16
  `;
17
17
 
18
- export const Input = styled.input.attrs({
19
- className: 'Input',
20
- })`
18
+ export const Input = styled.input`
21
19
  ${inputStyle}
22
20
  `;
23
21
 
@@ -1,6 +1,13 @@
1
1
  import * as styles from './styles';
2
2
 
3
- import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import {
4
+ ComponentProps,
5
+ FC,
6
+ useCallback,
7
+ useEffect,
8
+ useRef,
9
+ useState,
10
+ } from 'react';
4
11
  import { SearchResults, SearchTypeDefinitions } from './types';
5
12
 
6
13
  import { useDebounce } from '@uidotdev/usehooks';
@@ -12,11 +19,16 @@ import { QuickSearchResults } from './QuickSearchResults';
12
19
  type QuickSearchBarProps<R> = {
13
20
  definitions: SearchTypeDefinitions<R>;
14
21
  types?: string[];
22
+ conditions?: { field: string; operator: string }[];
23
+ placeholder?: string;
24
+ inputComponent?: FC<ComponentProps<typeof Input>>;
15
25
  };
16
26
 
17
27
  export const QuickSearchBar = <R,>({
18
28
  definitions,
19
29
  types,
30
+ placeholder,
31
+ inputComponent: InputComponent = Input,
20
32
  }: QuickSearchBarProps<R>) => {
21
33
  const [term, setTerm] = useState('');
22
34
  const [dropdownVisible, setDropdownVisible] = useState(false);
@@ -58,7 +70,13 @@ export const QuickSearchBar = <R,>({
58
70
 
59
71
  return (
60
72
  <>
61
- <Input type="text" ref={fakeInputRef} value={term} onFocus={onFocus} />
73
+ <InputComponent
74
+ type="text"
75
+ ref={fakeInputRef}
76
+ value={term}
77
+ onFocus={onFocus}
78
+ placeholder={placeholder}
79
+ />
62
80
  {dropdownVisible && rect && (
63
81
  <Dropdown
64
82
  $sourceRect={destRect}
@@ -68,10 +86,11 @@ export const QuickSearchBar = <R,>({
68
86
  $autoPositionY={false}
69
87
  >
70
88
  <styles.QuickSearchDropdownContainer>
71
- <Input
89
+ <InputComponent
72
90
  type="text"
73
91
  ref={inputRef}
74
92
  value={term}
93
+ placeholder={placeholder}
75
94
  onChange={(e) => setTerm(e.target.value)}
76
95
  onClick={(e) => e.stopPropagation()}
77
96
  />