@verisoft/store 18.0.0 → 18.1.0

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,32 +1,32 @@
1
- export interface DetailState<T> {
2
- loaded: boolean;
3
- item?: T;
4
- formState?: FormState;
5
- error?: string | null;
6
- }
7
-
8
- export interface ChosenRowsState<T> {
9
- rows: Array<T>;
10
- }
11
-
12
- export const INITIAL_CHOSEN_ROW_STATE: ChosenRowsState<any> = {
13
- rows: []
14
- }
15
-
16
- export const INITIAL_DETAIL_STATE: DetailState<any> = {
17
- loaded: false,
18
- };
19
-
20
- export interface SaveItemState {
21
- saveInProgress: boolean;
22
- error?: string | null;
23
- }
24
-
25
- export const INITIAL_SAVE_ITEM_STATE: SaveItemState = {
26
- saveInProgress: false,
27
- };
28
-
29
- export interface FormState {
30
- dirty: boolean;
31
- valid: boolean;
32
- }
1
+ export interface DetailState<T> {
2
+ loaded: boolean;
3
+ item?: T;
4
+ formState?: FormState;
5
+ error?: string | null;
6
+ }
7
+
8
+ export interface ChosenRowsState<T> {
9
+ rows: Array<T>;
10
+ }
11
+
12
+ export const INITIAL_CHOSEN_ROW_STATE: ChosenRowsState<any> = {
13
+ rows: []
14
+ }
15
+
16
+ export const INITIAL_DETAIL_STATE: DetailState<any> = {
17
+ loaded: false,
18
+ };
19
+
20
+ export interface SaveItemState {
21
+ saveInProgress: boolean;
22
+ error?: string | null;
23
+ }
24
+
25
+ export const INITIAL_SAVE_ITEM_STATE: SaveItemState = {
26
+ saveInProgress: false,
27
+ };
28
+
29
+ export interface FormState {
30
+ dirty: boolean;
31
+ valid: boolean;
32
+ }
@@ -1,122 +1,122 @@
1
- import { ActionCreator, createReducer, on, ReducerTypes } from '@ngrx/store';
2
- import {
3
- createInitDetailAction,
4
- createLoadDetailFailureAction,
5
- createLoadDetailSuccessAction,
6
- createResetStateAction,
7
- createSaveDetailAction,
8
- createSaveDetailFailureAction,
9
- createSaveDetailSuccessAction,
10
- createUpdateDetailAction,
11
- createUpdateFormStateAction,
12
- } from './detail.actions';
13
- import {
14
- DetailState,
15
- INITIAL_DETAIL_STATE,
16
- INITIAL_SAVE_ITEM_STATE,
17
- } from './detail.models';
18
-
19
- export function createDetailReducers<
20
- T = any,
21
- TState extends DetailState<T> = DetailState<T>
22
- >(
23
- detailRepository: string,
24
- initialState: TState = INITIAL_DETAIL_STATE as unknown as TState,
25
- ...ons: ReducerTypes<TState, readonly ActionCreator[]>[]
26
- ) {
27
- return createReducer(
28
- initialState,
29
- on(createInitDetailAction(detailRepository), (state) => {
30
- return {
31
- ...state,
32
- loaded: false,
33
- error: null,
34
- };
35
- }),
36
-
37
- on(createLoadDetailSuccessAction(detailRepository), (state, { item }) => {
38
- return {
39
- ...state,
40
- loaded: true,
41
- item,
42
- };
43
- }),
44
-
45
- on(createLoadDetailFailureAction(detailRepository), (state, { error }) => {
46
- return {
47
- ...state,
48
- loaded: true,
49
- error,
50
- };
51
- }),
52
-
53
- on(createUpdateDetailAction(detailRepository), (state, { item }) => {
54
- return {
55
- ...state,
56
- item,
57
- formState: {
58
- dirty: true,
59
- valid: state.formState?.valid ?? true,
60
- },
61
- };
62
- }),
63
-
64
- on(
65
- createUpdateFormStateAction(detailRepository),
66
- (state, { formState }) => {
67
- return {
68
- ...state,
69
- formState,
70
- };
71
- }
72
- ),
73
-
74
- on(createSaveDetailSuccessAction(detailRepository), (state) => {
75
- return {
76
- ...state,
77
- formState: {
78
- dirty: false,
79
- valid: state.formState?.valid ?? true,
80
- },
81
- };
82
- }),
83
- on(createResetStateAction(detailRepository), () => {
84
- return {
85
- ...(initialState as any),
86
- };
87
- }),
88
- ...ons
89
- );
90
- }
91
-
92
- export function createSaveDetailReducers(
93
- detailRepository: string,
94
- initialState = INITIAL_SAVE_ITEM_STATE
95
- ) {
96
- return createReducer(
97
- initialState,
98
-
99
- on(createSaveDetailAction(detailRepository), (state) => {
100
- return {
101
- ...state,
102
- saveInProgress: true,
103
- };
104
- }),
105
-
106
- on(createSaveDetailSuccessAction(detailRepository), (state, { item }) => {
107
- return {
108
- ...state,
109
- item,
110
- saveInProgress: false,
111
- };
112
- }),
113
-
114
- on(createSaveDetailFailureAction(detailRepository), (state, { error }) => {
115
- return {
116
- ...state,
117
- error,
118
- saveInProgress: false,
119
- };
120
- })
121
- );
122
- }
1
+ import { ActionCreator, createReducer, on, ReducerTypes } from '@ngrx/store';
2
+ import {
3
+ createInitDetailAction,
4
+ createLoadDetailFailureAction,
5
+ createLoadDetailSuccessAction,
6
+ createResetStateAction,
7
+ createSaveDetailAction,
8
+ createSaveDetailFailureAction,
9
+ createSaveDetailSuccessAction,
10
+ createUpdateDetailAction,
11
+ createUpdateFormStateAction,
12
+ } from './detail.actions';
13
+ import {
14
+ DetailState,
15
+ INITIAL_DETAIL_STATE,
16
+ INITIAL_SAVE_ITEM_STATE,
17
+ } from './detail.models';
18
+
19
+ export function createDetailReducers<
20
+ T = any,
21
+ TState extends DetailState<T> = DetailState<T>
22
+ >(
23
+ detailRepository: string,
24
+ initialState: TState = INITIAL_DETAIL_STATE as unknown as TState,
25
+ ...ons: ReducerTypes<TState, readonly ActionCreator[]>[]
26
+ ) {
27
+ return createReducer(
28
+ initialState,
29
+ on(createInitDetailAction(detailRepository), (state) => {
30
+ return {
31
+ ...state,
32
+ loaded: false,
33
+ error: null,
34
+ };
35
+ }),
36
+
37
+ on(createLoadDetailSuccessAction(detailRepository), (state, { item }) => {
38
+ return {
39
+ ...state,
40
+ loaded: true,
41
+ item,
42
+ };
43
+ }),
44
+
45
+ on(createLoadDetailFailureAction(detailRepository), (state, { error }) => {
46
+ return {
47
+ ...state,
48
+ loaded: true,
49
+ error,
50
+ };
51
+ }),
52
+
53
+ on(createUpdateDetailAction(detailRepository), (state, { item }) => {
54
+ return {
55
+ ...state,
56
+ item,
57
+ formState: {
58
+ dirty: true,
59
+ valid: state.formState?.valid ?? true,
60
+ },
61
+ };
62
+ }),
63
+
64
+ on(
65
+ createUpdateFormStateAction(detailRepository),
66
+ (state, { formState }) => {
67
+ return {
68
+ ...state,
69
+ formState,
70
+ };
71
+ }
72
+ ),
73
+
74
+ on(createSaveDetailSuccessAction(detailRepository), (state) => {
75
+ return {
76
+ ...state,
77
+ formState: {
78
+ dirty: false,
79
+ valid: state.formState?.valid ?? true,
80
+ },
81
+ };
82
+ }),
83
+ on(createResetStateAction(detailRepository), () => {
84
+ return {
85
+ ...(initialState as any),
86
+ };
87
+ }),
88
+ ...ons
89
+ );
90
+ }
91
+
92
+ export function createSaveDetailReducers(
93
+ detailRepository: string,
94
+ initialState = INITIAL_SAVE_ITEM_STATE
95
+ ) {
96
+ return createReducer(
97
+ initialState,
98
+
99
+ on(createSaveDetailAction(detailRepository), (state) => {
100
+ return {
101
+ ...state,
102
+ saveInProgress: true,
103
+ };
104
+ }),
105
+
106
+ on(createSaveDetailSuccessAction(detailRepository), (state, { item }) => {
107
+ return {
108
+ ...state,
109
+ item,
110
+ saveInProgress: false,
111
+ };
112
+ }),
113
+
114
+ on(createSaveDetailFailureAction(detailRepository), (state, { error }) => {
115
+ return {
116
+ ...state,
117
+ error,
118
+ saveInProgress: false,
119
+ };
120
+ })
121
+ );
122
+ }
@@ -1,93 +1,93 @@
1
- import { createAction, props } from '@ngrx/store';
2
- import { Page, Sort } from '@verisoft/core';
3
-
4
- enum TablePageAction {
5
- GET_PAGE = 'Get page',
6
- CREATE_STATIC_FILTER = 'Create static filter',
7
- DATA_LOAD_SUCCESS = 'Data load success',
8
- DATA_LOAD_ERROR = 'Data load error',
9
- REFRESH_PAGE = 'Refresh page',
10
- FILTER_PAGE = 'Filter page',
11
- CHANGE_PAGE_SIZE = 'Change page size',
12
- SORT_PAGE = 'Sort page',
13
- DESTROY = 'Destroy',
14
- SELECT_ITEMS = 'Select items',
15
- REMOVE_RANGE = 'Remove range',
16
- }
17
-
18
- export function createGetPageTableAction<T = any>(tableRepository: string) {
19
- return createAction(
20
- `${tableRepository} ${TablePageAction.GET_PAGE}`,
21
- props<{
22
- page: number;
23
- size: number;
24
- id?: string | null;
25
- filter?: Partial<T>;
26
- sort?: Sort<T>[];
27
- }>()
28
- );
29
- }
30
-
31
- export function createStaticFilterTableAction<T = any>(
32
- tableRepository: string
33
- ) {
34
- return createAction(
35
- `${tableRepository} ${TablePageAction.CREATE_STATIC_FILTER}`,
36
- props<{
37
- filter?: Partial<T>;
38
- }>()
39
- );
40
- }
41
-
42
- export function createDataLoadSuccessTableAction<T>(tableRepository: string) {
43
- return createAction(
44
- `${tableRepository} ${TablePageAction.DATA_LOAD_SUCCESS}`,
45
- props<{ gPage: Page<T> }>()
46
- );
47
- }
48
-
49
- export function createDataLoadErrorTableAction(tableRepository: string) {
50
- return createAction(
51
- `${tableRepository} ${TablePageAction.DATA_LOAD_ERROR}`,
52
- props<{ error: any }>()
53
- );
54
- }
55
-
56
- export function createChangePageSizeTableAction(tableRepository: string) {
57
- return createAction(
58
- `${tableRepository} ${TablePageAction.CHANGE_PAGE_SIZE}`,
59
- props<{ size: number }>()
60
- );
61
- }
62
-
63
- // TODO: use action in delete item effect
64
- export function createRefreshPageTableAction(tableRepository: string) {
65
- return createAction(`${tableRepository} ${TablePageAction.REFRESH_PAGE}`);
66
- }
67
-
68
- export function createFilterPageTableAction<T>(tableRepository: string) {
69
- return createAction(
70
- `${tableRepository} ${TablePageAction.REFRESH_PAGE}`,
71
- props<{ filter: Partial<T> }>()
72
- );
73
- }
74
-
75
- export function createResetTableFilterAction(tableRepository: string) {
76
- return createAction(`${tableRepository} ${TablePageAction.REFRESH_PAGE}`);
77
- }
78
-
79
- export function createDestroyTableAction(tableRepository: string) {
80
- return createAction(`${tableRepository} ${TablePageAction.DESTROY}`);
81
- }
82
-
83
- export function createSelectItemsTableAction<T>(tableRepository: string) {
84
- return createAction(
85
- `${tableRepository} ${TablePageAction.SELECT_ITEMS}`,
86
- props<{ selectedItems: T[] }>()
87
- );
88
- }
89
-
90
- export function createRemoveRangeTableAction(tableRepository: string) {
91
- return createAction(`${tableRepository} ${TablePageAction.REMOVE_RANGE}`
92
- );
1
+ import { createAction, props } from '@ngrx/store';
2
+ import { Page, Sort } from '@verisoft/core';
3
+
4
+ enum TablePageAction {
5
+ GET_PAGE = 'Get page',
6
+ CREATE_STATIC_FILTER = 'Create static filter',
7
+ DATA_LOAD_SUCCESS = 'Data load success',
8
+ DATA_LOAD_ERROR = 'Data load error',
9
+ REFRESH_PAGE = 'Refresh page',
10
+ FILTER_PAGE = 'Filter page',
11
+ CHANGE_PAGE_SIZE = 'Change page size',
12
+ SORT_PAGE = 'Sort page',
13
+ DESTROY = 'Destroy',
14
+ SELECT_ITEMS = 'Select items',
15
+ REMOVE_RANGE = 'Remove range',
16
+ }
17
+
18
+ export function createGetPageTableAction<T = any>(tableRepository: string) {
19
+ return createAction(
20
+ `${tableRepository} ${TablePageAction.GET_PAGE}`,
21
+ props<{
22
+ page: number;
23
+ size: number;
24
+ id?: string | null;
25
+ filter?: Partial<T>;
26
+ sort?: Sort<T>[];
27
+ }>()
28
+ );
29
+ }
30
+
31
+ export function createStaticFilterTableAction<T = any>(
32
+ tableRepository: string
33
+ ) {
34
+ return createAction(
35
+ `${tableRepository} ${TablePageAction.CREATE_STATIC_FILTER}`,
36
+ props<{
37
+ filter?: Partial<T>;
38
+ }>()
39
+ );
40
+ }
41
+
42
+ export function createDataLoadSuccessTableAction<T>(tableRepository: string) {
43
+ return createAction(
44
+ `${tableRepository} ${TablePageAction.DATA_LOAD_SUCCESS}`,
45
+ props<{ gPage: Page<T> }>()
46
+ );
47
+ }
48
+
49
+ export function createDataLoadErrorTableAction(tableRepository: string) {
50
+ return createAction(
51
+ `${tableRepository} ${TablePageAction.DATA_LOAD_ERROR}`,
52
+ props<{ error: any }>()
53
+ );
54
+ }
55
+
56
+ export function createChangePageSizeTableAction(tableRepository: string) {
57
+ return createAction(
58
+ `${tableRepository} ${TablePageAction.CHANGE_PAGE_SIZE}`,
59
+ props<{ size: number }>()
60
+ );
61
+ }
62
+
63
+ // TODO: use action in delete item effect
64
+ export function createRefreshPageTableAction(tableRepository: string) {
65
+ return createAction(`${tableRepository} ${TablePageAction.REFRESH_PAGE}`);
66
+ }
67
+
68
+ export function createFilterPageTableAction<T>(tableRepository: string) {
69
+ return createAction(
70
+ `${tableRepository} ${TablePageAction.REFRESH_PAGE}`,
71
+ props<{ filter: Partial<T> }>()
72
+ );
73
+ }
74
+
75
+ export function createResetTableFilterAction(tableRepository: string) {
76
+ return createAction(`${tableRepository} ${TablePageAction.REFRESH_PAGE}`);
77
+ }
78
+
79
+ export function createDestroyTableAction(tableRepository: string) {
80
+ return createAction(`${tableRepository} ${TablePageAction.DESTROY}`);
81
+ }
82
+
83
+ export function createSelectItemsTableAction<T>(tableRepository: string) {
84
+ return createAction(
85
+ `${tableRepository} ${TablePageAction.SELECT_ITEMS}`,
86
+ props<{ selectedItems: T[] }>()
87
+ );
88
+ }
89
+
90
+ export function createRemoveRangeTableAction(tableRepository: string) {
91
+ return createAction(`${tableRepository} ${TablePageAction.REMOVE_RANGE}`
92
+ );
93
93
  }