proje-react-panel 1.4.0 → 1.4.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.
@@ -8,6 +8,7 @@ import { ListPageMeta } from '../../decorators/list/getListPageMeta';
8
8
  import { AnyClass } from '../../types/AnyClass';
9
9
  import { CellField } from './CellField';
10
10
  import { CellConfiguration } from '../../decorators/list/Cell';
11
+ import { useAppStore } from '../../store/store';
11
12
 
12
13
  interface DatagridProps<T extends AnyClass> {
13
14
  data: T[];
@@ -21,6 +22,7 @@ export function Datagrid<T extends AnyClass>({
21
22
  onRemoveItem,
22
23
  }: DatagridProps<T>) {
23
24
  const cells = listPageMeta.cells;
25
+ const listData = useAppStore(state => state.listData[listPageMeta.class.key]);
24
26
  const listGeneralCells = data?.[0]
25
27
  ? typeof listPageMeta.class.cells === 'function'
26
28
  ? listPageMeta.class.cells?.(data[0])
@@ -50,10 +52,13 @@ export function Datagrid<T extends AnyClass>({
50
52
  ? listPageMeta.class.cells?.(item)
51
53
  : listPageMeta.class.cells
52
54
  : null;
55
+ const listDataItem = listData?.[item[listPageMeta.class.primaryId]] as
56
+ | Record<string, unknown>
57
+ | undefined;
53
58
  return (
54
59
  <tr key={index}>
55
60
  {cells.map((configuration: CellConfiguration) => {
56
- const value = item[configuration.name];
61
+ const value = listDataItem?.[configuration.name] ?? item[configuration.name];
57
62
  return (
58
63
  <CellField
59
64
  key={configuration.name}
@@ -35,9 +35,14 @@ export interface ListOptions<T> {
35
35
  getData: GetDataForList<T>;
36
36
  headers?: ListHeaderOptions;
37
37
  cells?: ((item: T) => ListCellOptions<T>) | ListCellOptions<T>;
38
+ primaryId: string;
39
+ key?: string;
38
40
  }
39
41
 
40
- export type ListConfiguration<T> = ListOptions<T>;
42
+ export type ListConfiguration<T> = ListOptions<T> & {
43
+ primaryId: string;
44
+ key: string;
45
+ };
41
46
 
42
47
  export function List<T>(options?: ListOptions<T> | ((item: T) => ListOptions<T>)): ClassDecorator {
43
48
  return (target: object) => {
@@ -50,11 +55,13 @@ export function List<T>(options?: ListOptions<T> | ((item: T) => ListOptions<T>)
50
55
  export function getListConfiguration<T extends AnyClass>(
51
56
  entityClass: AnyClassConstructor<T>
52
57
  ): ListConfiguration<T> {
53
- const listConfiguration = Reflect.getMetadata(LIST_METADATA_KEY, entityClass);
58
+ const listConfiguration: ListOptions<T> = Reflect.getMetadata(LIST_METADATA_KEY, entityClass);
54
59
  if (!listConfiguration) {
55
60
  throw new Error('List decerator should be used on class');
56
61
  }
57
62
  return {
58
63
  ...listConfiguration,
64
+ primaryId: listConfiguration.primaryId,
65
+ key: listConfiguration.key || entityClass.name,
59
66
  };
60
67
  }
package/src/index.ts CHANGED
@@ -39,3 +39,4 @@ export { logout } from './utils/logout';
39
39
 
40
40
  //SERVICES
41
41
  export { updateDetailsData } from './services/DataService';
42
+ export { updateListData } from './services/DataService';
@@ -1,6 +1,7 @@
1
1
  import { getDetailsPageMeta } from '../decorators/details/getDetailsPageMeta';
2
2
  import { AnyClass, AnyClassConstructor } from '../types/AnyClass';
3
3
  import { useAppStore } from '../store/store';
4
+ import { getListPageMeta } from '../decorators/list/getListPageMeta';
4
5
 
5
6
  export function updateDetailsData<T extends AnyClass>(
6
7
  model: AnyClassConstructor<T>,
@@ -16,3 +17,18 @@ export function updateDetailsData<T extends AnyClass>(
16
17
 
17
18
  useAppStore.getState().updateDetailsData(key, data[id]?.toString(), data);
18
19
  }
20
+
21
+ export function updateListData<T extends AnyClass>(
22
+ model: AnyClassConstructor<T>,
23
+ data: Partial<T>
24
+ ) {
25
+ const { class: listClass } = getListPageMeta(model);
26
+ const key = listClass.key;
27
+ const id = listClass.primaryId;
28
+ console.log('updateListData', model, data, listClass);
29
+ if (!data[id]) {
30
+ throw new Error(`Id ${id} not found in data`);
31
+ }
32
+
33
+ useAppStore.getState().updateListData(key, data[id]?.toString(), data);
34
+ }
@@ -6,6 +6,8 @@ import { User } from '../types/User';
6
6
  interface AppState {
7
7
  detailsData: Record<string, Record<string, unknown>>;
8
8
  updateDetailsData: (key: string, id: string, data: unknown) => void;
9
+ listData: Record<string, Record<string, unknown>>;
10
+ updateListData: (key: string, id: string, data: unknown) => void;
9
11
  user: User | null;
10
12
  login: (user: User) => void;
11
13
  logout: () => void;
@@ -25,6 +27,11 @@ export const useAppStore = createWithEqualityFn<AppState>()(
25
27
  [key]: { ...get().detailsData[key], [id]: data },
26
28
  },
27
29
  }),
30
+ listData: {},
31
+ updateListData: (key: string, id: string, data: unknown) =>
32
+ set({
33
+ listData: { ...get().listData, [key]: { ...get().listData[key], [id]: data } },
34
+ }),
28
35
  }),
29
36
  {
30
37
  name: 'app-store-1',