@gpa-gemstone/common-pages 0.0.150 → 0.0.152
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/lib/Gemstone/ControllerFunctions.d.ts +22 -0
- package/lib/Gemstone/ControllerFunctions.js +266 -0
- package/lib/Gemstone/Gemstone.d.ts +18 -0
- package/lib/Gemstone/Gemstone.js +41 -0
- package/lib/Gemstone/GenericSlices/ReadOnlyGenericSlice.d.ts +51 -0
- package/lib/Gemstone/GenericSlices/ReadOnlyGenericSlice.js +230 -0
- package/lib/Gemstone/GenericSlices/ReadWriteGenericSlice.d.ts +19 -0
- package/lib/Gemstone/GenericSlices/ReadWriteGenericSlice.js +241 -0
- package/lib/Gemstone/GenericSlices/useInitializeData.d.ts +10 -0
- package/lib/Gemstone/GenericSlices/useInitializeData.js +65 -0
- package/lib/Note.js +1 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.js +12 -1
- package/package.json +7 -7
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Gemstone } from "./Gemstone";
|
2
|
+
export declare class ReadOnlyControllerFunctions<T> {
|
3
|
+
protected APIPath: string;
|
4
|
+
constructor(APIPath: string);
|
5
|
+
GetPageInfo: (filter?: Gemstone.Types.ISearchFilter<T>[], parentID?: string | number) => JQuery.jqXHR<Gemstone.Types.IPageInfo>;
|
6
|
+
GetOne: (id: string | number) => JQuery.jqXHR<T>;
|
7
|
+
GetPage: (page: number, sortField?: keyof T, asc?: boolean, parentID?: string | number) => JQuery.jqXHR<T[]>;
|
8
|
+
/**
|
9
|
+
* Use with caution as this could be VERY network resource intensive.
|
10
|
+
*/
|
11
|
+
GetAll: (sortField: keyof T, asc: boolean, filter?: Gemstone.Types.ISearchFilter<T>[], parentID?: string | number) => JQuery.jqXHR<T[]>;
|
12
|
+
SearchPage: (page: number, sortField: keyof T, asc: boolean, filter: Gemstone.Types.ISearchFilter<T>[], parentID?: number | string) => JQuery.jqXHR<T[]>;
|
13
|
+
New: () => JQuery.jqXHR<T>;
|
14
|
+
GetMaxValue: (fieldName: keyof T) => JQuery.jqXHR<number>;
|
15
|
+
}
|
16
|
+
export declare class ReadWriteControllerFunctions<T> extends ReadOnlyControllerFunctions<T> {
|
17
|
+
constructor(APIPath: string);
|
18
|
+
Add: (record: T) => JQuery.jqXHR<T>;
|
19
|
+
Update: (record: T) => JQuery.jqXHR<T>;
|
20
|
+
Delete: (record: T) => JQuery.jqXHR<T>;
|
21
|
+
DeleteByID: (id: string | number) => JQuery.jqXHR<T>;
|
22
|
+
}
|
@@ -0,0 +1,266 @@
|
|
1
|
+
"use strict";
|
2
|
+
//******************************************************************************************************
|
3
|
+
// ControllerFunctions.tsx - Gbtc
|
4
|
+
//
|
5
|
+
// Copyright (c) 2024, Grid Protection Alliance. All Rights Reserved.
|
6
|
+
//
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
9
|
+
// The GPA may license this file to you under the MIT License (MIT), the "License"; you may not use this
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
11
|
+
//
|
12
|
+
// http://opensource.org/licenses/MIT
|
13
|
+
//
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
16
|
+
// License for the specific language governing permissions and limitations.
|
17
|
+
//
|
18
|
+
// Code Modification History:
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
20
|
+
// 04/02/2024 - C. Lackner
|
21
|
+
// Generated original version of source code.
|
22
|
+
//
|
23
|
+
//******************************************************************************************************
|
24
|
+
var __extends = (this && this.__extends) || (function () {
|
25
|
+
var extendStatics = function (d, b) {
|
26
|
+
extendStatics = Object.setPrototypeOf ||
|
27
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
28
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
29
|
+
return extendStatics(d, b);
|
30
|
+
};
|
31
|
+
return function (d, b) {
|
32
|
+
if (typeof b !== "function" && b !== null)
|
33
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
34
|
+
extendStatics(d, b);
|
35
|
+
function __() { this.constructor = d; }
|
36
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
37
|
+
};
|
38
|
+
})();
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
41
|
+
};
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
43
|
+
exports.ReadWriteControllerFunctions = exports.ReadOnlyControllerFunctions = void 0;
|
44
|
+
var jquery_1 = __importDefault(require("jquery"));
|
45
|
+
var ReadOnlyControllerFunctions = /** @class */ (function () {
|
46
|
+
function ReadOnlyControllerFunctions(APIPath) {
|
47
|
+
var _this = this;
|
48
|
+
this.GetPageInfo = function (filter, parentID) {
|
49
|
+
var route = parentID == null ? "".concat(_this.APIPath, "/PageInfo") : "".concat(_this.APIPath, "/PageInfo/").concat(parentID);
|
50
|
+
if (filter === undefined || filter.length === 0)
|
51
|
+
return jquery_1.default.ajax({
|
52
|
+
type: 'GET',
|
53
|
+
url: "".concat(route),
|
54
|
+
contentType: "application/json; charset=utf-8",
|
55
|
+
dataType: 'json',
|
56
|
+
cache: false,
|
57
|
+
async: true
|
58
|
+
});
|
59
|
+
return jquery_1.default.ajax({
|
60
|
+
type: 'POST',
|
61
|
+
url: "".concat(route),
|
62
|
+
contentType: "application/json; charset=utf-8",
|
63
|
+
dataType: 'json',
|
64
|
+
data: JSON.stringify({ Searches: filter, OrderBy: '', Ascending: false }),
|
65
|
+
cache: false,
|
66
|
+
async: true
|
67
|
+
});
|
68
|
+
};
|
69
|
+
this.GetOne = function (id) {
|
70
|
+
return jquery_1.default.ajax({
|
71
|
+
type: 'GET',
|
72
|
+
url: "".concat(_this.APIPath, "/One/").concat(id),
|
73
|
+
contentType: "application/json; charset=utf-8",
|
74
|
+
dataType: 'json',
|
75
|
+
cache: false,
|
76
|
+
async: true
|
77
|
+
});
|
78
|
+
};
|
79
|
+
this.GetPage = function (page, sortField, asc, parentID) {
|
80
|
+
if (sortField == null || asc == null) {
|
81
|
+
if (parentID != null) {
|
82
|
+
return jquery_1.default.ajax({
|
83
|
+
type: 'GET',
|
84
|
+
url: "".concat(_this.APIPath, "/").concat(page, "/").concat(parentID),
|
85
|
+
contentType: "application/json; charset=utf-8",
|
86
|
+
dataType: 'json',
|
87
|
+
cache: false,
|
88
|
+
async: true
|
89
|
+
});
|
90
|
+
}
|
91
|
+
return jquery_1.default.ajax({
|
92
|
+
type: 'GET',
|
93
|
+
url: "".concat(_this.APIPath, "/").concat(page),
|
94
|
+
contentType: "application/json; charset=utf-8",
|
95
|
+
dataType: 'json',
|
96
|
+
cache: false,
|
97
|
+
async: true
|
98
|
+
});
|
99
|
+
}
|
100
|
+
if (parentID != null)
|
101
|
+
return jquery_1.default.ajax({
|
102
|
+
type: 'GET',
|
103
|
+
url: "".concat(_this.APIPath, "/").concat(page, "/").concat(parentID, "/").concat(sortField.toString(), "/").concat(asc),
|
104
|
+
contentType: "application/json; charset=utf-8",
|
105
|
+
dataType: 'json',
|
106
|
+
cache: false,
|
107
|
+
async: true
|
108
|
+
});
|
109
|
+
return jquery_1.default.ajax({
|
110
|
+
type: 'GET',
|
111
|
+
url: "".concat(_this.APIPath, "/").concat(page, "/").concat(sortField.toString(), "/").concat(asc),
|
112
|
+
contentType: "application/json; charset=utf-8",
|
113
|
+
dataType: 'json',
|
114
|
+
cache: false,
|
115
|
+
async: true
|
116
|
+
});
|
117
|
+
};
|
118
|
+
/**
|
119
|
+
* Use with caution as this could be VERY network resource intensive.
|
120
|
+
*/
|
121
|
+
this.GetAll = function (sortField, asc, filter, parentID) {
|
122
|
+
var deferred = jquery_1.default.Deferred();
|
123
|
+
var pending = [];
|
124
|
+
// First, determine the number of pages.
|
125
|
+
var pagReq = _this.GetPageInfo(filter !== null && filter !== void 0 ? filter : [], parentID).done(function (pageInfo) {
|
126
|
+
var pageCount = pageInfo.PageCount;
|
127
|
+
if (pageCount <= 0) {
|
128
|
+
deferred.resolve([]);
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
// Build an array of page requests.
|
132
|
+
var pageRequests = [];
|
133
|
+
for (var i = 0; i < pageCount; i++) {
|
134
|
+
var req = _this.SearchPage(i, sortField, asc, filter !== null && filter !== void 0 ? filter : [], parentID);
|
135
|
+
pageRequests.push(req);
|
136
|
+
pending.push(req);
|
137
|
+
}
|
138
|
+
// Combine all page requests.
|
139
|
+
jquery_1.default.when.apply(jquery_1.default, pageRequests).done(function () {
|
140
|
+
var _a;
|
141
|
+
var results = [];
|
142
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
143
|
+
results[_i] = arguments[_i];
|
144
|
+
}
|
145
|
+
// If there's only one page, 'arguments' is not an array of arrays.
|
146
|
+
var responses = pageRequests.length === 1 ? [results] : jquery_1.default.makeArray(results);
|
147
|
+
var pages = responses.map(function (result) { return result[0]; });
|
148
|
+
var allData = (_a = []).concat.apply(_a, pages);
|
149
|
+
deferred.resolve(allData);
|
150
|
+
}).fail(function (err) { return deferred.reject(err); });
|
151
|
+
}).fail(function (err) { return deferred.reject(err); });
|
152
|
+
pending.push(pagReq);
|
153
|
+
// Attach an abort handler to cancel all pending requests.
|
154
|
+
var promise = deferred.promise();
|
155
|
+
promise.abort = function () {
|
156
|
+
pending.forEach(function (req) { return req.abort(); });
|
157
|
+
deferred.reject('Aborted');
|
158
|
+
};
|
159
|
+
return promise;
|
160
|
+
};
|
161
|
+
this.SearchPage = function (page, sortField, asc, filter, parentID) {
|
162
|
+
if (parentID != null)
|
163
|
+
return jquery_1.default.ajax({
|
164
|
+
type: 'POST',
|
165
|
+
url: "".concat(_this.APIPath, "/Search/").concat(page, "/").concat(parentID),
|
166
|
+
contentType: "application/json; charset=utf-8",
|
167
|
+
dataType: 'json',
|
168
|
+
data: JSON.stringify({
|
169
|
+
Searches: filter,
|
170
|
+
OrderBy: sortField,
|
171
|
+
Ascending: asc
|
172
|
+
}),
|
173
|
+
cache: false,
|
174
|
+
async: true
|
175
|
+
});
|
176
|
+
return jquery_1.default.ajax({
|
177
|
+
type: 'POST',
|
178
|
+
url: "".concat(_this.APIPath, "/Search/").concat(page),
|
179
|
+
contentType: "application/json; charset=utf-8",
|
180
|
+
dataType: 'json',
|
181
|
+
data: JSON.stringify({
|
182
|
+
Searches: filter,
|
183
|
+
OrderBy: sortField,
|
184
|
+
Ascending: asc
|
185
|
+
}),
|
186
|
+
cache: false,
|
187
|
+
async: true
|
188
|
+
});
|
189
|
+
};
|
190
|
+
this.New = function () {
|
191
|
+
return jquery_1.default.ajax({
|
192
|
+
type: 'GET',
|
193
|
+
url: "".concat(_this.APIPath, "/New"),
|
194
|
+
contentType: "application/json; charset=utf-8",
|
195
|
+
dataType: 'json',
|
196
|
+
cache: false,
|
197
|
+
async: true
|
198
|
+
});
|
199
|
+
};
|
200
|
+
this.GetMaxValue = function (fieldName) {
|
201
|
+
return jquery_1.default.ajax({
|
202
|
+
type: 'GET',
|
203
|
+
url: "".concat(_this.APIPath, "/Max/").concat(fieldName),
|
204
|
+
contentType: "application/json; charset=utf-8",
|
205
|
+
dataType: 'json',
|
206
|
+
cache: false,
|
207
|
+
async: true
|
208
|
+
});
|
209
|
+
};
|
210
|
+
this.APIPath = APIPath;
|
211
|
+
}
|
212
|
+
return ReadOnlyControllerFunctions;
|
213
|
+
}());
|
214
|
+
exports.ReadOnlyControllerFunctions = ReadOnlyControllerFunctions;
|
215
|
+
var ReadWriteControllerFunctions = /** @class */ (function (_super) {
|
216
|
+
__extends(ReadWriteControllerFunctions, _super);
|
217
|
+
function ReadWriteControllerFunctions(APIPath) {
|
218
|
+
var _this = _super.call(this, APIPath) || this;
|
219
|
+
_this.Add = function (record) {
|
220
|
+
return jquery_1.default.ajax({
|
221
|
+
type: 'POST',
|
222
|
+
url: "".concat(_this.APIPath),
|
223
|
+
contentType: "application/json; charset=utf-8",
|
224
|
+
dataType: 'json',
|
225
|
+
data: JSON.stringify(record),
|
226
|
+
cache: false,
|
227
|
+
async: true
|
228
|
+
});
|
229
|
+
};
|
230
|
+
_this.Update = function (record) {
|
231
|
+
return jquery_1.default.ajax({
|
232
|
+
type: 'PATCH',
|
233
|
+
url: "".concat(_this.APIPath),
|
234
|
+
contentType: "application/json; charset=utf-8",
|
235
|
+
dataType: 'json',
|
236
|
+
data: JSON.stringify(record),
|
237
|
+
cache: false,
|
238
|
+
async: true
|
239
|
+
});
|
240
|
+
};
|
241
|
+
_this.Delete = function (record) {
|
242
|
+
return jquery_1.default.ajax({
|
243
|
+
type: 'DELETE',
|
244
|
+
url: "".concat(_this.APIPath),
|
245
|
+
contentType: "application/json; charset=utf-8",
|
246
|
+
dataType: 'json',
|
247
|
+
data: JSON.stringify(record),
|
248
|
+
cache: false,
|
249
|
+
async: true
|
250
|
+
});
|
251
|
+
};
|
252
|
+
_this.DeleteByID = function (id) {
|
253
|
+
return jquery_1.default.ajax({
|
254
|
+
type: 'DELETE',
|
255
|
+
url: "".concat(_this.APIPath, "/").concat(id),
|
256
|
+
contentType: "application/json; charset=utf-8",
|
257
|
+
dataType: 'json',
|
258
|
+
cache: false,
|
259
|
+
async: true
|
260
|
+
});
|
261
|
+
};
|
262
|
+
return _this;
|
263
|
+
}
|
264
|
+
return ReadWriteControllerFunctions;
|
265
|
+
}(ReadOnlyControllerFunctions));
|
266
|
+
exports.ReadWriteControllerFunctions = ReadWriteControllerFunctions;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Search } from "@gpa-gemstone/react-interactive";
|
2
|
+
export declare namespace Gemstone {
|
3
|
+
namespace Types {
|
4
|
+
interface ISearchFilter<T> {
|
5
|
+
FieldName: keyof T;
|
6
|
+
SearchParameter: string | boolean | number | string[] | number[] | boolean[];
|
7
|
+
Operator: Search.OperatorType;
|
8
|
+
}
|
9
|
+
interface IPageInfo {
|
10
|
+
PageSize: number;
|
11
|
+
PageCount: number;
|
12
|
+
TotalCount: number;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
namespace HelperFunctions {
|
16
|
+
const getSearchFilter: <T>(searchFilter: Search.IFilter<T>[]) => Types.ISearchFilter<T>[];
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
//******************************************************************************************************
|
3
|
+
// Gemstone.tsx - Gbtc
|
4
|
+
//
|
5
|
+
// Copyright (c) 2025, Grid Protection Alliance. All Rights Reserved.
|
6
|
+
//
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
9
|
+
// The GPA may license this file to you under the MIT License (MIT), the "License"; you may not use this
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
11
|
+
//
|
12
|
+
// http://opensource.org/licenses/MIT
|
13
|
+
//
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
16
|
+
// License for the specific language governing permissions and limitations.
|
17
|
+
//
|
18
|
+
// Code Modification History:
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
20
|
+
// 09/12/2025 - Preston Crawford
|
21
|
+
// Generated original version of source code.
|
22
|
+
//
|
23
|
+
//******************************************************************************************************
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
25
|
+
exports.Gemstone = void 0;
|
26
|
+
var Gemstone;
|
27
|
+
(function (Gemstone) {
|
28
|
+
var HelperFunctions;
|
29
|
+
(function (HelperFunctions) {
|
30
|
+
HelperFunctions.getSearchFilter = function (searchFilter) {
|
31
|
+
return searchFilter.map(function (s) {
|
32
|
+
var searchText = s.SearchText;
|
33
|
+
if (s.Operator === 'IN' || s.Operator === 'NOT IN') {
|
34
|
+
if (searchText.startsWith('(') && searchText.endsWith(')'))
|
35
|
+
searchText = searchText.slice(1, -1).split(',').map(function (v) { return v.trim(); });
|
36
|
+
}
|
37
|
+
return { FieldName: s.FieldName, SearchParameter: searchText, Operator: s.Operator };
|
38
|
+
});
|
39
|
+
};
|
40
|
+
})(HelperFunctions = Gemstone.HelperFunctions || (Gemstone.HelperFunctions = {}));
|
41
|
+
})(Gemstone || (exports.Gemstone = Gemstone = {}));
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { AsyncThunk, Slice, ActionReducerMapBuilder, Reducer } from '@reduxjs/toolkit';
|
2
|
+
import { ReadOnlyControllerFunctions } from '../ControllerFunctions';
|
3
|
+
import { Application } from '@gpa-gemstone/application-typings';
|
4
|
+
import { Gemstone } from '../Gemstone';
|
5
|
+
export interface IError {
|
6
|
+
Message: string;
|
7
|
+
Action: 'FETCH' | 'UPDATE' | 'ADD' | 'DELETE';
|
8
|
+
Time: string;
|
9
|
+
}
|
10
|
+
export interface IState<T> {
|
11
|
+
FetchStatus: Application.Types.Status;
|
12
|
+
Data: T[];
|
13
|
+
SortField: keyof T;
|
14
|
+
Ascending: boolean;
|
15
|
+
Filter: Gemstone.Types.ISearchFilter<T>[];
|
16
|
+
PageInfo: Gemstone.Types.IPageInfo;
|
17
|
+
ParentID: string | number | null;
|
18
|
+
ActiveID: string[];
|
19
|
+
Error: (IError | null);
|
20
|
+
}
|
21
|
+
export interface IFetchThunkArg<T> {
|
22
|
+
sortField?: keyof T;
|
23
|
+
ascending?: boolean;
|
24
|
+
parentID?: string | number;
|
25
|
+
filter?: Gemstone.Types.ISearchFilter<T>[];
|
26
|
+
}
|
27
|
+
export interface IReadOnlyThunkReturn<T> {
|
28
|
+
Data: T[];
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* A generic class providing functionalities related to a slice of data.
|
32
|
+
*/
|
33
|
+
export default class ReadOnlyGenericSlice<T> {
|
34
|
+
protected Name: string;
|
35
|
+
protected Slice: Slice<any>;
|
36
|
+
Fetch: AsyncThunk<IReadOnlyThunkReturn<T>, IFetchThunkArg<T>, {}>;
|
37
|
+
SetStatusToChanged: AsyncThunk<void, void, {}>;
|
38
|
+
Reducer: Reducer<IState<T>>;
|
39
|
+
private fetchHandle;
|
40
|
+
protected controller: ReadOnlyControllerFunctions<T>;
|
41
|
+
constructor(name: string, defaultSortField: keyof T, ascending: boolean, apiPath: string);
|
42
|
+
constructor(name: string, defaultSortField: keyof T, ascending: boolean, readonlyController: ReadOnlyControllerFunctions<T>);
|
43
|
+
protected initializeSlice(defaultSortField: keyof T, ascending?: boolean): void;
|
44
|
+
protected addExtraReducers(builder: ActionReducerMapBuilder<IState<T>>): void;
|
45
|
+
Data: (state: any) => T[];
|
46
|
+
Error: (state: any) => IError | null;
|
47
|
+
FetchStatus: (state: any) => Application.Types.Status;
|
48
|
+
SortField: (state: any) => keyof T;
|
49
|
+
Ascending: (state: any) => boolean;
|
50
|
+
ParentID: (state: any) => string | number | null;
|
51
|
+
}
|
@@ -0,0 +1,230 @@
|
|
1
|
+
"use strict";
|
2
|
+
// ******************************************************************************************************
|
3
|
+
// ReadOnlyGenericSlice.tsx - Gbtc
|
4
|
+
//
|
5
|
+
// Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
|
6
|
+
//
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
11
|
+
//
|
12
|
+
// http://opensource.org/licenses/MIT
|
13
|
+
//
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
16
|
+
// License for the specific language governing permissions and limitations.
|
17
|
+
//
|
18
|
+
// Code Modification History:
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
20
|
+
// 08/12/2024 - Preston Crawford
|
21
|
+
// Generated original version of source code.
|
22
|
+
// ******************************************************************************************************
|
23
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
30
|
+
});
|
31
|
+
};
|
32
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
33
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
34
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
35
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
36
|
+
function step(op) {
|
37
|
+
if (f) throw new TypeError("Generator is already executing.");
|
38
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
39
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
40
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
41
|
+
switch (op[0]) {
|
42
|
+
case 0: case 1: t = op; break;
|
43
|
+
case 4: _.label++; return { value: op[1], done: false };
|
44
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
45
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
46
|
+
default:
|
47
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
48
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
49
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
50
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
51
|
+
if (t[2]) _.ops.pop();
|
52
|
+
_.trys.pop(); continue;
|
53
|
+
}
|
54
|
+
op = body.call(thisArg, _);
|
55
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
56
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
57
|
+
}
|
58
|
+
};
|
59
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
60
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
61
|
+
if (ar || !(i in from)) {
|
62
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
63
|
+
ar[i] = from[i];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
67
|
+
};
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
69
|
+
var toolkit_1 = require("@reduxjs/toolkit");
|
70
|
+
var ControllerFunctions_1 = require("../ControllerFunctions");
|
71
|
+
/**
|
72
|
+
* A generic class providing functionalities related to a slice of data.
|
73
|
+
*/
|
74
|
+
var ReadOnlyGenericSlice = /** @class */ (function () {
|
75
|
+
function ReadOnlyGenericSlice(name, defaultSortField, ascending, apiPathOrReadOnlyController) {
|
76
|
+
var _this = this;
|
77
|
+
this.Data = function (state) { return state[_this.Name].Data; };
|
78
|
+
this.Error = function (state) { return state[_this.Name].Error; };
|
79
|
+
this.FetchStatus = function (state) { return state[_this.Name].FetchStatus; };
|
80
|
+
this.SortField = function (state) { return state[_this.Name].SortField; };
|
81
|
+
this.Ascending = function (state) { return state[_this.Name].Ascending; };
|
82
|
+
this.ParentID = function (state) { return state[_this.Name].ParentID; };
|
83
|
+
this.Name = name;
|
84
|
+
this.fetchHandle = null;
|
85
|
+
if (typeof apiPathOrReadOnlyController === 'string')
|
86
|
+
this.controller = new ControllerFunctions_1.ReadOnlyControllerFunctions(apiPathOrReadOnlyController);
|
87
|
+
else
|
88
|
+
this.controller = apiPathOrReadOnlyController;
|
89
|
+
this.Fetch = (0, toolkit_1.createAsyncThunk)("".concat(this.Name, "/Fetch").concat(this.Name), function () {
|
90
|
+
var args_1 = [];
|
91
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
92
|
+
args_1[_i] = arguments[_i];
|
93
|
+
}
|
94
|
+
return __awaiter(_this, __spreadArray([], args_1, true), void 0, function (arg, _a) {
|
95
|
+
var stateMap, state, fetchHandle, sortField, ascending, filter, parentID, paginationHandle;
|
96
|
+
var _b, _c, _d, _e, _f;
|
97
|
+
if (arg === void 0) { arg = undefined; }
|
98
|
+
var signal = _a.signal, getState = _a.getState;
|
99
|
+
return __generator(this, function (_g) {
|
100
|
+
stateMap = getState();
|
101
|
+
state = stateMap[this.Name];
|
102
|
+
if (this.fetchHandle != null && this.fetchHandle.abort != null)
|
103
|
+
this.fetchHandle.abort('Prev');
|
104
|
+
sortField = (_b = arg === null || arg === void 0 ? void 0 : arg.sortField) !== null && _b !== void 0 ? _b : state.SortField;
|
105
|
+
ascending = (_c = arg === null || arg === void 0 ? void 0 : arg.ascending) !== null && _c !== void 0 ? _c : state.Ascending;
|
106
|
+
filter = (_d = arg === null || arg === void 0 ? void 0 : arg.filter) !== null && _d !== void 0 ? _d : state.Filter;
|
107
|
+
parentID = (_f = (_e = arg === null || arg === void 0 ? void 0 : arg.parentID) !== null && _e !== void 0 ? _e : state.ParentID) !== null && _f !== void 0 ? _f : undefined;
|
108
|
+
if ((arg === null || arg === void 0 ? void 0 : arg.filter) == null)
|
109
|
+
fetchHandle = this.controller.GetPage(0, sortField, ascending, parentID);
|
110
|
+
else
|
111
|
+
fetchHandle = this.controller.SearchPage(0, sortField, ascending, filter, parentID);
|
112
|
+
this.fetchHandle = fetchHandle;
|
113
|
+
paginationHandle = this.controller.GetPageInfo();
|
114
|
+
signal.addEventListener('abort', function () {
|
115
|
+
if (fetchHandle.abort !== undefined)
|
116
|
+
fetchHandle.abort();
|
117
|
+
if (paginationHandle.abort !== undefined)
|
118
|
+
paginationHandle.abort();
|
119
|
+
});
|
120
|
+
return [2 /*return*/, Promise.all([fetchHandle]).then(function (responses) { return ({ Data: responses[0] }); })];
|
121
|
+
});
|
122
|
+
});
|
123
|
+
});
|
124
|
+
this.SetStatusToChanged = (0, toolkit_1.createAsyncThunk)("".concat(this.Name, "/SetChanged").concat(this.Name), function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
125
|
+
return [2 /*return*/];
|
126
|
+
}); }); });
|
127
|
+
this.initializeSlice(defaultSortField, ascending);
|
128
|
+
}
|
129
|
+
ReadOnlyGenericSlice.prototype.initializeSlice = function (defaultSortField, ascending) {
|
130
|
+
var _this = this;
|
131
|
+
if (ascending === void 0) { ascending = true; }
|
132
|
+
var initialState = {
|
133
|
+
FetchStatus: 'uninitiated',
|
134
|
+
Error: null,
|
135
|
+
Data: [],
|
136
|
+
SortField: defaultSortField,
|
137
|
+
Ascending: ascending,
|
138
|
+
Filter: [],
|
139
|
+
ActiveID: [],
|
140
|
+
PageInfo: {
|
141
|
+
PageCount: 0,
|
142
|
+
TotalCount: 0,
|
143
|
+
PageSize: 0
|
144
|
+
},
|
145
|
+
ParentID: null
|
146
|
+
};
|
147
|
+
this.Slice = (0, toolkit_1.createSlice)({
|
148
|
+
name: this.Name,
|
149
|
+
initialState: initialState,
|
150
|
+
reducers: {},
|
151
|
+
extraReducers: function (builder) {
|
152
|
+
builder.addCase(_this.Fetch.pending, function (state, action) {
|
153
|
+
state.FetchStatus = 'loading';
|
154
|
+
state.ActiveID.push(action.meta.requestId);
|
155
|
+
});
|
156
|
+
builder.addCase(_this.Fetch.rejected, function (state, action) {
|
157
|
+
var _a;
|
158
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
159
|
+
if (state.ActiveID.length > 0)
|
160
|
+
return;
|
161
|
+
state.FetchStatus = 'error';
|
162
|
+
state.Error = {
|
163
|
+
Message: (_a = action.error.message) !== null && _a !== void 0 ? _a : '',
|
164
|
+
Action: 'FETCH',
|
165
|
+
Time: new Date().toString()
|
166
|
+
};
|
167
|
+
});
|
168
|
+
builder.addCase(_this.Fetch.fulfilled, function (state, action) {
|
169
|
+
var _a, _b;
|
170
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
171
|
+
state.FetchStatus = 'idle';
|
172
|
+
state.Error = null;
|
173
|
+
state.Data = action.payload.Data;
|
174
|
+
if (action.meta.arg == null)
|
175
|
+
return;
|
176
|
+
if (action.meta.arg.filter != null)
|
177
|
+
state.Filter = (_a = action.meta.arg) === null || _a === void 0 ? void 0 : _a.filter;
|
178
|
+
if (action.meta.arg.parentID != null)
|
179
|
+
state.ParentID = (_b = action.meta.arg) === null || _b === void 0 ? void 0 : _b.parentID;
|
180
|
+
if (state.SortField === action.meta.arg.sortField)
|
181
|
+
state.Ascending = !state.Ascending;
|
182
|
+
else if (action.meta.arg.sortField != null)
|
183
|
+
state.SortField = action.meta.arg.sortField;
|
184
|
+
});
|
185
|
+
builder.addCase(_this.SetStatusToChanged.pending, function (state) {
|
186
|
+
state.FetchStatus = 'changed';
|
187
|
+
});
|
188
|
+
}
|
189
|
+
});
|
190
|
+
this.Reducer = this.Slice.reducer;
|
191
|
+
};
|
192
|
+
ReadOnlyGenericSlice.prototype.addExtraReducers = function (builder) {
|
193
|
+
builder.addCase(this.Fetch.pending, function (state, action) {
|
194
|
+
state.FetchStatus = 'loading';
|
195
|
+
state.ActiveID.push(action.meta.requestId);
|
196
|
+
});
|
197
|
+
builder.addCase(this.Fetch.rejected, function (state, action) {
|
198
|
+
var _a;
|
199
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
200
|
+
if (state.ActiveID.length > 0)
|
201
|
+
return;
|
202
|
+
state.FetchStatus = 'error';
|
203
|
+
state.Error = {
|
204
|
+
Message: (_a = action.error.message) !== null && _a !== void 0 ? _a : '',
|
205
|
+
Action: 'FETCH',
|
206
|
+
Time: new Date().toString()
|
207
|
+
};
|
208
|
+
});
|
209
|
+
builder.addCase(this.Fetch.fulfilled, function (state, action) {
|
210
|
+
var _a, _b;
|
211
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
212
|
+
state.FetchStatus = 'idle';
|
213
|
+
state.Error = null;
|
214
|
+
state.Data = action.payload.Data;
|
215
|
+
if (action.meta.arg.filter != null)
|
216
|
+
state.Filter = (_a = action.meta.arg) === null || _a === void 0 ? void 0 : _a.filter;
|
217
|
+
if (action.meta.arg.parentID != null)
|
218
|
+
state.ParentID = (_b = action.meta.arg) === null || _b === void 0 ? void 0 : _b.parentID;
|
219
|
+
if (state.SortField === action.meta.arg.sortField)
|
220
|
+
state.Ascending = !state.Ascending;
|
221
|
+
else if (action.meta.arg.sortField != null)
|
222
|
+
state.SortField = action.meta.arg.sortField;
|
223
|
+
});
|
224
|
+
builder.addCase(this.SetStatusToChanged.pending, function (state) {
|
225
|
+
state.FetchStatus = 'changed';
|
226
|
+
});
|
227
|
+
};
|
228
|
+
return ReadOnlyGenericSlice;
|
229
|
+
}());
|
230
|
+
exports.default = ReadOnlyGenericSlice;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { AsyncThunk } from '@reduxjs/toolkit';
|
2
|
+
import { ReadOnlyControllerFunctions, ReadWriteControllerFunctions } from '../ControllerFunctions';
|
3
|
+
import ReadOnlyGenericSlice from './ReadOnlyGenericSlice';
|
4
|
+
import { Application } from '@gpa-gemstone/application-typings';
|
5
|
+
export default class ReadWriteGenericSlice<T> extends ReadOnlyGenericSlice<T> {
|
6
|
+
Add: AsyncThunk<T, T, {}>;
|
7
|
+
Update: AsyncThunk<T, T, {}>;
|
8
|
+
Delete: AsyncThunk<T, (string | number | T), {}>;
|
9
|
+
private updateHandle;
|
10
|
+
private addHandle;
|
11
|
+
private deleteHandle;
|
12
|
+
private readWriteController;
|
13
|
+
constructor(name: string, defaultSortField: keyof T, ascending: boolean, apiPath: string);
|
14
|
+
constructor(name: string, defaultSortField: keyof T, ascending: boolean, readWriteController: ReadWriteControllerFunctions<T>, readOnlyController?: ReadOnlyControllerFunctions<T>);
|
15
|
+
private initializeReadWriteSlice;
|
16
|
+
UpdateStatus: (state: any) => Application.Types.Status;
|
17
|
+
AddStatus: (state: any) => Application.Types.Status;
|
18
|
+
DeleteStatus: (state: any) => Application.Types.Status;
|
19
|
+
}
|
@@ -0,0 +1,241 @@
|
|
1
|
+
"use strict";
|
2
|
+
// ******************************************************************************************************
|
3
|
+
// ReadWriteGenericSlice.tsx - Gbtc
|
4
|
+
//
|
5
|
+
// Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
|
6
|
+
//
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
11
|
+
//
|
12
|
+
// http://opensource.org/licenses/MIT
|
13
|
+
//
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
16
|
+
// License for the specific language governing permissions and limitations.
|
17
|
+
//
|
18
|
+
// Code Modification History:
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
20
|
+
// 08/12/2024 - Preston Crawford
|
21
|
+
// Generated original version of source code.
|
22
|
+
// ******************************************************************************************************
|
23
|
+
var __extends = (this && this.__extends) || (function () {
|
24
|
+
var extendStatics = function (d, b) {
|
25
|
+
extendStatics = Object.setPrototypeOf ||
|
26
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
27
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
28
|
+
return extendStatics(d, b);
|
29
|
+
};
|
30
|
+
return function (d, b) {
|
31
|
+
if (typeof b !== "function" && b !== null)
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
33
|
+
extendStatics(d, b);
|
34
|
+
function __() { this.constructor = d; }
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
36
|
+
};
|
37
|
+
})();
|
38
|
+
var __assign = (this && this.__assign) || function () {
|
39
|
+
__assign = Object.assign || function(t) {
|
40
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
41
|
+
s = arguments[i];
|
42
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
43
|
+
t[p] = s[p];
|
44
|
+
}
|
45
|
+
return t;
|
46
|
+
};
|
47
|
+
return __assign.apply(this, arguments);
|
48
|
+
};
|
49
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
50
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
51
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
52
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
53
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
54
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
55
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
56
|
+
});
|
57
|
+
};
|
58
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
59
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
60
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
61
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
62
|
+
function step(op) {
|
63
|
+
if (f) throw new TypeError("Generator is already executing.");
|
64
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
65
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
66
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
67
|
+
switch (op[0]) {
|
68
|
+
case 0: case 1: t = op; break;
|
69
|
+
case 4: _.label++; return { value: op[1], done: false };
|
70
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
71
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
72
|
+
default:
|
73
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
74
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
75
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
76
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
77
|
+
if (t[2]) _.ops.pop();
|
78
|
+
_.trys.pop(); continue;
|
79
|
+
}
|
80
|
+
op = body.call(thisArg, _);
|
81
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
82
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
83
|
+
}
|
84
|
+
};
|
85
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
86
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
87
|
+
};
|
88
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
89
|
+
var toolkit_1 = require("@reduxjs/toolkit");
|
90
|
+
var ControllerFunctions_1 = require("../ControllerFunctions");
|
91
|
+
var ReadOnlyGenericSlice_1 = __importDefault(require("./ReadOnlyGenericSlice"));
|
92
|
+
var ReadWriteGenericSlice = /** @class */ (function (_super) {
|
93
|
+
__extends(ReadWriteGenericSlice, _super);
|
94
|
+
function ReadWriteGenericSlice(name, defaultSortField, ascending, apiPathOrReadWriteController, readOnlyController) {
|
95
|
+
var _this = _super.call(this, name, defaultSortField, ascending, typeof apiPathOrReadWriteController === 'string' ? new ControllerFunctions_1.ReadWriteControllerFunctions(apiPathOrReadWriteController) : (readOnlyController !== null && readOnlyController !== void 0 ? readOnlyController : apiPathOrReadWriteController)) || this;
|
96
|
+
_this.updateHandle = null;
|
97
|
+
_this.addHandle = null;
|
98
|
+
_this.deleteHandle = null;
|
99
|
+
_this.UpdateStatus = function (state) { return state[_this.Name].UpdateStatus; };
|
100
|
+
_this.AddStatus = function (state) { return state[_this.Name].AddStatus; };
|
101
|
+
_this.DeleteStatus = function (state) { return state[_this.Name].DeleteStatus; };
|
102
|
+
_this.readWriteController = typeof apiPathOrReadWriteController === 'string' ? new ControllerFunctions_1.ReadWriteControllerFunctions(apiPathOrReadWriteController) : apiPathOrReadWriteController;
|
103
|
+
_this.initializeReadWriteSlice();
|
104
|
+
return _this;
|
105
|
+
}
|
106
|
+
ReadWriteGenericSlice.prototype.initializeReadWriteSlice = function () {
|
107
|
+
var _this = this;
|
108
|
+
this.Add = (0, toolkit_1.createAsyncThunk)("".concat(this.Name, "/Add").concat(this.Name), function (record_1, _a) { return __awaiter(_this, [record_1, _a], void 0, function (record, _b) {
|
109
|
+
var _this = this;
|
110
|
+
var _c;
|
111
|
+
var signal = _b.signal;
|
112
|
+
return __generator(this, function (_d) {
|
113
|
+
switch (_d.label) {
|
114
|
+
case 0:
|
115
|
+
if (((_c = this.addHandle) === null || _c === void 0 ? void 0 : _c.abort) != null)
|
116
|
+
this.addHandle.abort('Prev');
|
117
|
+
this.addHandle = this.readWriteController.Add(record);
|
118
|
+
signal.addEventListener('abort', function () {
|
119
|
+
var _a;
|
120
|
+
(_a = _this.addHandle) === null || _a === void 0 ? void 0 : _a.abort();
|
121
|
+
});
|
122
|
+
return [4 /*yield*/, this.addHandle];
|
123
|
+
case 1: return [2 /*return*/, _d.sent()];
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}); });
|
127
|
+
this.Update = (0, toolkit_1.createAsyncThunk)("".concat(this.Name, "/Update").concat(this.Name), function (record_1, _a) { return __awaiter(_this, [record_1, _a], void 0, function (record, _b) {
|
128
|
+
var _this = this;
|
129
|
+
var _c;
|
130
|
+
var signal = _b.signal;
|
131
|
+
return __generator(this, function (_d) {
|
132
|
+
switch (_d.label) {
|
133
|
+
case 0:
|
134
|
+
if (((_c = this.updateHandle) === null || _c === void 0 ? void 0 : _c.abort) != null)
|
135
|
+
this.updateHandle.abort('Prev');
|
136
|
+
this.updateHandle = this.readWriteController.Update(record);
|
137
|
+
signal.addEventListener('abort', function () {
|
138
|
+
var _a;
|
139
|
+
(_a = _this.updateHandle) === null || _a === void 0 ? void 0 : _a.abort();
|
140
|
+
});
|
141
|
+
return [4 /*yield*/, this.updateHandle];
|
142
|
+
case 1: return [2 /*return*/, _d.sent()];
|
143
|
+
}
|
144
|
+
});
|
145
|
+
}); });
|
146
|
+
this.Delete = (0, toolkit_1.createAsyncThunk)("".concat(this.Name, "/Delete").concat(this.Name), function (record_1, _a) { return __awaiter(_this, [record_1, _a], void 0, function (record, _b) {
|
147
|
+
var _this = this;
|
148
|
+
var _c;
|
149
|
+
var signal = _b.signal;
|
150
|
+
return __generator(this, function (_d) {
|
151
|
+
switch (_d.label) {
|
152
|
+
case 0:
|
153
|
+
if (((_c = this.deleteHandle) === null || _c === void 0 ? void 0 : _c.abort) != null)
|
154
|
+
this.deleteHandle.abort('Prev');
|
155
|
+
if (typeof record === 'string' || typeof record === 'number')
|
156
|
+
this.deleteHandle = this.readWriteController.DeleteByID(record);
|
157
|
+
else
|
158
|
+
this.deleteHandle = this.readWriteController.Delete(record);
|
159
|
+
signal.addEventListener('abort', function () {
|
160
|
+
var _a;
|
161
|
+
(_a = _this.deleteHandle) === null || _a === void 0 ? void 0 : _a.abort();
|
162
|
+
});
|
163
|
+
return [4 /*yield*/, this.deleteHandle];
|
164
|
+
case 1: return [2 /*return*/, _d.sent()];
|
165
|
+
}
|
166
|
+
});
|
167
|
+
}); });
|
168
|
+
// Create the slice with extended reducers
|
169
|
+
this.Slice = (0, toolkit_1.createSlice)({
|
170
|
+
name: this.Name,
|
171
|
+
initialState: __assign(__assign({}, this.Slice.getInitialState()), { AddStatus: 'uninitiated', UpdateStatus: 'uninitiated', DeleteStatus: 'uninitiated' }),
|
172
|
+
reducers: {},
|
173
|
+
extraReducers: function (builder) {
|
174
|
+
_this.addExtraReducers(builder);
|
175
|
+
builder.addCase(_this.Add.pending, function (state, action) {
|
176
|
+
state.AddStatus = 'loading';
|
177
|
+
state.ActiveID.push(action.meta.requestId);
|
178
|
+
});
|
179
|
+
builder.addCase(_this.Add.fulfilled, function (state, action) {
|
180
|
+
state.AddStatus = 'changed';
|
181
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
182
|
+
});
|
183
|
+
builder.addCase(_this.Add.rejected, function (state, action) {
|
184
|
+
var _a;
|
185
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
186
|
+
if (state.ActiveID.length > 0)
|
187
|
+
return;
|
188
|
+
state.AddStatus = 'error';
|
189
|
+
state.Error = {
|
190
|
+
Message: (_a = action.error.message) !== null && _a !== void 0 ? _a : '',
|
191
|
+
Action: 'ADD',
|
192
|
+
Time: new Date().toString()
|
193
|
+
};
|
194
|
+
});
|
195
|
+
builder.addCase(_this.Update.pending, function (state, action) {
|
196
|
+
state.UpdateStatus = 'loading';
|
197
|
+
state.ActiveID.push(action.meta.requestId);
|
198
|
+
});
|
199
|
+
builder.addCase(_this.Update.fulfilled, function (state, action) {
|
200
|
+
state.UpdateStatus = 'changed';
|
201
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
202
|
+
});
|
203
|
+
builder.addCase(_this.Update.rejected, function (state, action) {
|
204
|
+
var _a;
|
205
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
206
|
+
if (state.ActiveID.length > 0)
|
207
|
+
return;
|
208
|
+
state.UpdateStatus = 'error';
|
209
|
+
state.Error = {
|
210
|
+
Message: (_a = action.error.message) !== null && _a !== void 0 ? _a : '',
|
211
|
+
Action: 'UPDATE',
|
212
|
+
Time: new Date().toString()
|
213
|
+
};
|
214
|
+
});
|
215
|
+
builder.addCase(_this.Delete.pending, function (state, action) {
|
216
|
+
state.DeleteStatus = 'loading';
|
217
|
+
state.ActiveID.push(action.meta.requestId);
|
218
|
+
});
|
219
|
+
builder.addCase(_this.Delete.fulfilled, function (state, action) {
|
220
|
+
state.DeleteStatus = 'changed';
|
221
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
222
|
+
});
|
223
|
+
builder.addCase(_this.Delete.rejected, function (state, action) {
|
224
|
+
var _a;
|
225
|
+
state.ActiveID = state.ActiveID.filter(function (id) { return id !== action.meta.requestId; });
|
226
|
+
if (state.ActiveID.length > 0)
|
227
|
+
return;
|
228
|
+
state.DeleteStatus = 'error';
|
229
|
+
state.Error = {
|
230
|
+
Message: (_a = action.error.message) !== null && _a !== void 0 ? _a : '',
|
231
|
+
Action: 'DELETE',
|
232
|
+
Time: new Date().toString()
|
233
|
+
};
|
234
|
+
});
|
235
|
+
}
|
236
|
+
});
|
237
|
+
this.Reducer = this.Slice.reducer;
|
238
|
+
};
|
239
|
+
return ReadWriteGenericSlice;
|
240
|
+
}(ReadOnlyGenericSlice_1.default));
|
241
|
+
exports.default = ReadWriteGenericSlice;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import ReadOnlyGenericSlice from './ReadOnlyGenericSlice';
|
2
|
+
/**
|
3
|
+
* Custom hook to initialize data fetching for a read-only generic slice.
|
4
|
+
* @param slice - The read-only generic slice instance.
|
5
|
+
* @param dispatch - The Redux dispatch function.
|
6
|
+
* @param useSelector - The Redux useSelector hook.
|
7
|
+
* @param parentID - The optional parent ID for the data fetch.
|
8
|
+
* @returns The current fetch status.
|
9
|
+
*/
|
10
|
+
export declare function useInitializeWithFetch<T>(slice: ReadOnlyGenericSlice<T>, dispatch: (action: any) => void, useSelector: any, parentID?: string | number): any;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
// ******************************************************************************************************
|
3
|
+
// useInitializeHook.tsx - Gbtc
|
4
|
+
//
|
5
|
+
// Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
|
6
|
+
//
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
11
|
+
//
|
12
|
+
// http://opensource.org/licenses/MIT
|
13
|
+
//
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
16
|
+
// License for the specific language governing permissions and limitations.
|
17
|
+
//
|
18
|
+
// Code Modification History:
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
20
|
+
// 08/13/2024 - Preston Crawford
|
21
|
+
// Generated original version of source code.
|
22
|
+
// ******************************************************************************************************
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
24
|
+
if (k2 === undefined) k2 = k;
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
28
|
+
}
|
29
|
+
Object.defineProperty(o, k2, desc);
|
30
|
+
}) : (function(o, m, k, k2) {
|
31
|
+
if (k2 === undefined) k2 = k;
|
32
|
+
o[k2] = m[k];
|
33
|
+
}));
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
36
|
+
}) : function(o, v) {
|
37
|
+
o["default"] = v;
|
38
|
+
});
|
39
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
40
|
+
if (mod && mod.__esModule) return mod;
|
41
|
+
var result = {};
|
42
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
43
|
+
__setModuleDefault(result, mod);
|
44
|
+
return result;
|
45
|
+
};
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
47
|
+
exports.useInitializeWithFetch = useInitializeWithFetch;
|
48
|
+
var React = __importStar(require("react"));
|
49
|
+
/**
|
50
|
+
* Custom hook to initialize data fetching for a read-only generic slice.
|
51
|
+
* @param slice - The read-only generic slice instance.
|
52
|
+
* @param dispatch - The Redux dispatch function.
|
53
|
+
* @param useSelector - The Redux useSelector hook.
|
54
|
+
* @param parentID - The optional parent ID for the data fetch.
|
55
|
+
* @returns The current fetch status.
|
56
|
+
*/
|
57
|
+
function useInitializeWithFetch(slice, dispatch, useSelector, parentID) {
|
58
|
+
var status = useSelector(slice.FetchStatus);
|
59
|
+
var ParentID = useSelector(slice.ParentID);
|
60
|
+
React.useEffect(function () {
|
61
|
+
if (status === 'uninitiated' || status === 'changed' || ParentID != parentID)
|
62
|
+
dispatch(slice.Fetch({ parentID: parentID }));
|
63
|
+
}, [status, dispatch]);
|
64
|
+
return status;
|
65
|
+
}
|
package/lib/Note.js
CHANGED
@@ -80,7 +80,7 @@ function Note(props) {
|
|
80
80
|
var _c = React.useState(CreateNewNote()), note = _c[0], setNote = _c[1];
|
81
81
|
var _d = React.useState([]), notes = _d[0], setNotes = _d[1];
|
82
82
|
React.useEffect(function () {
|
83
|
-
if (dataStatus === '
|
83
|
+
if (dataStatus === 'uninitiated' || dataStatus === 'changed' || parentID !== props.ReferenceTableID)
|
84
84
|
dispatch(props.NoteSlice.Fetch(props.ReferenceTableID));
|
85
85
|
}, [props.ReferenceTableID, dispatch, dataStatus]);
|
86
86
|
React.useEffect(function () {
|
package/lib/index.d.ts
CHANGED
@@ -12,7 +12,14 @@ import * as TimeWindowUtils from './TimeFilter/TimeWindowUtils';
|
|
12
12
|
import BulkUpload from './BulkUpload';
|
13
13
|
import RoleAccessErrorPage from './RoleAcessErrorPage';
|
14
14
|
import { useCSVFieldEditContext, CSVFieldEditContext } from './Pipelines/CSVPipeline/CSVFieldContext';
|
15
|
+
import { ITimeFilter } from './TimeFilter/TimeFilter';
|
16
|
+
import { IStartDuration, IStartEnd, IEndDuration } from './TimeFilter/TimeWindowUtils';
|
17
|
+
import { Gemstone } from './Gemstone/Gemstone';
|
18
|
+
import ReadOnlyGenericSlice from './Gemstone/GenericSlices/ReadOnlyGenericSlice';
|
19
|
+
import ReadWriteGenericSlice from './Gemstone/GenericSlices/ReadWriteGenericSlice';
|
20
|
+
import { useInitializeWithFetch } from './Gemstone/GenericSlices/useInitializeData';
|
21
|
+
import { ReadOnlyControllerFunctions, ReadWriteControllerFunctions } from './Gemstone/ControllerFunctions';
|
15
22
|
declare const Pipelines: {
|
16
23
|
CSV: typeof useCSVPipeline;
|
17
24
|
};
|
18
|
-
export { TimeFilter, TimeWindowUtils, EventTypeFilter, EventCharacteristicFilter, NavBarFilterButton, Note, DefaultSearch, SelectPopup, DefaultSelects, ErrorBoundary, Pipelines, useCSVFieldEditContext, CSVFieldEditContext, BulkUpload, RoleAccessErrorPage };
|
25
|
+
export { TimeFilter, TimeWindowUtils, EventTypeFilter, EventCharacteristicFilter, NavBarFilterButton, Note, DefaultSearch, SelectPopup, DefaultSelects, ErrorBoundary, Pipelines, useCSVFieldEditContext, CSVFieldEditContext, BulkUpload, RoleAccessErrorPage, ITimeFilter, IStartEnd, IStartDuration, IEndDuration, Gemstone, ReadOnlyGenericSlice as ReadOnlyGenericSlice_Gemstone, ReadWriteGenericSlice as ReadWriteGenericSlice_Gemstone, useInitializeWithFetch as useInitializeWithFetch_Gemstone, ReadOnlyControllerFunctions as ReadOnlyControllerFunctions_Gemstone, ReadWriteControllerFunctions as ReadWriteControllerFunctions_Gemstone };
|
package/lib/index.js
CHANGED
@@ -48,7 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
49
49
|
};
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
51
|
-
exports.RoleAccessErrorPage = exports.BulkUpload = exports.CSVFieldEditContext = exports.useCSVFieldEditContext = exports.Pipelines = exports.ErrorBoundary = exports.DefaultSelects = exports.SelectPopup = exports.DefaultSearch = exports.Note = exports.NavBarFilterButton = exports.EventCharacteristicFilter = exports.EventTypeFilter = exports.TimeWindowUtils = exports.TimeFilter = void 0;
|
51
|
+
exports.ReadWriteControllerFunctions_Gemstone = exports.ReadOnlyControllerFunctions_Gemstone = exports.useInitializeWithFetch_Gemstone = exports.ReadWriteGenericSlice_Gemstone = exports.ReadOnlyGenericSlice_Gemstone = exports.Gemstone = exports.RoleAccessErrorPage = exports.BulkUpload = exports.CSVFieldEditContext = exports.useCSVFieldEditContext = exports.Pipelines = exports.ErrorBoundary = exports.DefaultSelects = exports.SelectPopup = exports.DefaultSearch = exports.Note = exports.NavBarFilterButton = exports.EventCharacteristicFilter = exports.EventTypeFilter = exports.TimeWindowUtils = exports.TimeFilter = void 0;
|
52
52
|
var Note_1 = __importDefault(require("./Note"));
|
53
53
|
exports.Note = Note_1.default;
|
54
54
|
var SearchBar_1 = require("./SearchBar");
|
@@ -77,6 +77,17 @@ exports.RoleAccessErrorPage = RoleAcessErrorPage_1.default;
|
|
77
77
|
var CSVFieldContext_1 = require("./Pipelines/CSVPipeline/CSVFieldContext");
|
78
78
|
Object.defineProperty(exports, "useCSVFieldEditContext", { enumerable: true, get: function () { return CSVFieldContext_1.useCSVFieldEditContext; } });
|
79
79
|
Object.defineProperty(exports, "CSVFieldEditContext", { enumerable: true, get: function () { return CSVFieldContext_1.CSVFieldEditContext; } });
|
80
|
+
var Gemstone_1 = require("./Gemstone/Gemstone");
|
81
|
+
Object.defineProperty(exports, "Gemstone", { enumerable: true, get: function () { return Gemstone_1.Gemstone; } });
|
82
|
+
var ReadOnlyGenericSlice_1 = __importDefault(require("./Gemstone/GenericSlices/ReadOnlyGenericSlice"));
|
83
|
+
exports.ReadOnlyGenericSlice_Gemstone = ReadOnlyGenericSlice_1.default;
|
84
|
+
var ReadWriteGenericSlice_1 = __importDefault(require("./Gemstone/GenericSlices/ReadWriteGenericSlice"));
|
85
|
+
exports.ReadWriteGenericSlice_Gemstone = ReadWriteGenericSlice_1.default;
|
86
|
+
var useInitializeData_1 = require("./Gemstone/GenericSlices/useInitializeData");
|
87
|
+
Object.defineProperty(exports, "useInitializeWithFetch_Gemstone", { enumerable: true, get: function () { return useInitializeData_1.useInitializeWithFetch; } });
|
88
|
+
var ControllerFunctions_1 = require("./Gemstone/ControllerFunctions");
|
89
|
+
Object.defineProperty(exports, "ReadOnlyControllerFunctions_Gemstone", { enumerable: true, get: function () { return ControllerFunctions_1.ReadOnlyControllerFunctions; } });
|
90
|
+
Object.defineProperty(exports, "ReadWriteControllerFunctions_Gemstone", { enumerable: true, get: function () { return ControllerFunctions_1.ReadWriteControllerFunctions; } });
|
80
91
|
var Pipelines = {
|
81
92
|
CSV: CSVPipeline_1.useCSVPipeline
|
82
93
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gpa-gemstone/common-pages",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.152",
|
4
4
|
"description": "Common UI pages for GPA products",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -44,12 +44,12 @@
|
|
44
44
|
"typescript": "5.5.3"
|
45
45
|
},
|
46
46
|
"dependencies": {
|
47
|
-
"@gpa-gemstone/application-typings": "0.0.
|
48
|
-
"@gpa-gemstone/gpa-symbols": "0.0.
|
49
|
-
"@gpa-gemstone/helper-functions": "0.0.
|
50
|
-
"@gpa-gemstone/react-forms": "1.1.
|
51
|
-
"@gpa-gemstone/react-interactive": "1.0.
|
52
|
-
"@gpa-gemstone/react-table": "1.2.
|
47
|
+
"@gpa-gemstone/application-typings": "0.0.89",
|
48
|
+
"@gpa-gemstone/gpa-symbols": "0.0.56",
|
49
|
+
"@gpa-gemstone/helper-functions": "0.0.47",
|
50
|
+
"@gpa-gemstone/react-forms": "1.1.101",
|
51
|
+
"@gpa-gemstone/react-interactive": "1.0.163",
|
52
|
+
"@gpa-gemstone/react-table": "1.2.86",
|
53
53
|
"@reduxjs/toolkit": "1.8.3",
|
54
54
|
"crypto-js": "^4.2.0",
|
55
55
|
"moment": "^2.29.4",
|