@gpa-gemstone/common-pages 0.0.123 → 0.0.124

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/BulkUpload.js CHANGED
@@ -98,12 +98,14 @@ function BulkUpload(props) {
98
98
  React.useEffect(function () {
99
99
  var pipelineErrs = props.Step == 'Process' ? pipelineErrors : [];
100
100
  var errors = __spreadArray([], pipelineErrs, true);
101
- if (fileName == null)
102
- errors.push('A file must be uploaded to continue');
103
- if (rawFileContent == null || rawFileContent == '')
104
- errors.push('File content is empty');
105
- if (!isFileTypeValid)
106
- errors.push("File must be of type ".concat(props.FileTypeAttribute));
101
+ if (props.Step === 'Upload') {
102
+ if (fileName == null)
103
+ errors.push('A file must be uploaded to continue');
104
+ if (rawFileContent == null || rawFileContent == '')
105
+ errors.push('File content is empty');
106
+ if (!isFileTypeValid)
107
+ errors.push("File must be of type ".concat(props.FileTypeAttribute));
108
+ }
107
109
  props.SetErrors(errors);
108
110
  }, [rawFileContent, fileName, isFileTypeValid, pipelineErrors, props.Step]);
109
111
  React.useEffect(function () {
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "@gpa-gemstone/common-pages",
3
- "version": "0.0.123",
4
- "description": "Common UI pages for GPA products",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": ["lib/**/*"],
8
- "scripts": {
9
- "test": "jest --config jestconfig.json",
10
- "build": "tsc",
11
- "format": "prettier --write \"src/**/*.tsx\"",
12
- "lint": "eslint . --ext .ts,.tsx",
13
- "prepare": "npm run build",
14
- "prepublishOnly": "npm test && npm run lint",
15
- "preversion": "npm run lint",
16
- "version": "npm run format && git add -A src",
17
- "postversion": "git push && git push --tags"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/GridProtectionAlliance/gpa-gemstone.git"
22
- },
23
- "keywords": [
24
- "React",
25
- "Interactive",
26
- "GSF",
27
- "Gemstone",
28
- "GridProtectionAlliance"
29
- ],
30
- "author": "GridProtectionAlliance",
31
- "license": "MIT",
32
- "bugs": {"url": "https://github.com/GridProtectionAlliance/gpa-gemstone/issues"},
33
- "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
34
- "devDependencies": {
35
- "@types/crypto-js": "^4.2.0",
36
- "@types/jest": "^27.0.0",
37
- "@types/jquery": "3.5.6",
38
- "@typescript-eslint/eslint-plugin": "^5.60.0",
39
- "@typescript-eslint/parser": "^5.60.0",
40
- "eslint": "^8.43.0",
41
- "jest": "^29.0.0",
42
- "prettier": "^2.3.2",
43
- "ts-jest": "^29.0.0",
44
- "typescript": "5.5.3"
45
- },
46
- "dependencies": {
47
- "@gpa-gemstone/application-typings": "0.0.78",
48
- "@gpa-gemstone/gpa-symbols": "0.0.45",
49
- "@gpa-gemstone/helper-functions": "0.0.36",
50
- "@gpa-gemstone/react-forms": "1.1.77",
51
- "@gpa-gemstone/react-interactive": "1.0.137",
52
- "@gpa-gemstone/react-table": "1.2.58",
53
- "@reduxjs/toolkit": "1.8.3",
54
- "crypto-js": "^4.2.0",
55
- "moment": "^2.29.4",
56
- "moment-timezone": "0.5.43",
57
- "react": "^18.2.0",
58
- "react-redux": "8.0.2",
59
- "styled-components": "5.3.3"
60
- },
61
- "publishConfig": {"access": "public"}
1
+ {
2
+ "name": "@gpa-gemstone/common-pages",
3
+ "version": "0.0.124",
4
+ "description": "Common UI pages for GPA products",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": ["lib/**/*"],
8
+ "scripts": {
9
+ "test": "jest --config jestconfig.json",
10
+ "build": "tsc",
11
+ "format": "prettier --write \"src/**/*.tsx\"",
12
+ "lint": "eslint . --ext .ts,.tsx",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm test && npm run lint",
15
+ "preversion": "npm run lint",
16
+ "version": "npm run format && git add -A src",
17
+ "postversion": "git push && git push --tags"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/GridProtectionAlliance/gpa-gemstone.git"
22
+ },
23
+ "keywords": [
24
+ "React",
25
+ "Interactive",
26
+ "GSF",
27
+ "Gemstone",
28
+ "GridProtectionAlliance"
29
+ ],
30
+ "author": "GridProtectionAlliance",
31
+ "license": "MIT",
32
+ "bugs": {"url": "https://github.com/GridProtectionAlliance/gpa-gemstone/issues"},
33
+ "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
34
+ "devDependencies": {
35
+ "@types/crypto-js": "^4.2.0",
36
+ "@types/jest": "^27.0.0",
37
+ "@types/jquery": "3.5.6",
38
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
39
+ "@typescript-eslint/parser": "^5.60.0",
40
+ "eslint": "^8.43.0",
41
+ "jest": "^29.0.0",
42
+ "prettier": "^2.3.2",
43
+ "ts-jest": "^29.0.0",
44
+ "typescript": "5.5.3"
45
+ },
46
+ "dependencies": {
47
+ "@gpa-gemstone/application-typings": "0.0.78",
48
+ "@gpa-gemstone/gpa-symbols": "0.0.45",
49
+ "@gpa-gemstone/helper-functions": "0.0.36",
50
+ "@gpa-gemstone/react-forms": "1.1.77",
51
+ "@gpa-gemstone/react-interactive": "1.0.137",
52
+ "@gpa-gemstone/react-table": "1.2.58",
53
+ "@reduxjs/toolkit": "1.8.3",
54
+ "crypto-js": "^4.2.0",
55
+ "moment": "^2.29.4",
56
+ "moment-timezone": "0.5.43",
57
+ "react": "^18.2.0",
58
+ "react-redux": "8.0.2",
59
+ "styled-components": "5.3.3"
60
+ },
61
+ "publishConfig": {"access": "public"}
62
62
  }
package/lib/Setting.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- import { ISearchableSlice } from './SliceInterfaces';
3
- import { SystemCenter } from '@gpa-gemstone/application-typings';
4
- interface IProps {
5
- SettingsSlice: ISearchableSlice<SystemCenter.Types.Setting>;
6
- }
7
- declare function Setting(props: IProps): React.JSX.Element;
8
- export default Setting;
package/lib/Setting.js DELETED
@@ -1,151 +0,0 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // Setting.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
- // 04/28/2021 - C. Lackner
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var React = __importStar(require("react"));
51
- var react_forms_1 = require("@gpa-gemstone/react-forms");
52
- var react_table_1 = __importDefault(require("@gpa-gemstone/react-table"));
53
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
54
- var react_interactive_1 = require("@gpa-gemstone/react-interactive");
55
- var react_redux_1 = require("react-redux");
56
- function Setting(props) {
57
- var dispatch = (0, react_redux_1.useDispatch)();
58
- var search = (0, react_redux_1.useSelector)(props.SettingsSlice.SearchFilters);
59
- var searchStatus = (0, react_redux_1.useSelector)(props.SettingsSlice.SearchStatus);
60
- var data = (0, react_redux_1.useSelector)(props.SettingsSlice.SearchResults);
61
- var allSettings = (0, react_redux_1.useSelector)(props.SettingsSlice.Data);
62
- var status = (0, react_redux_1.useSelector)(props.SettingsSlice.Status);
63
- var _a = React.useState('Name'), sortField = _a[0], setSortField = _a[1];
64
- var _b = React.useState(true), ascending = _b[0], setAscending = _b[1];
65
- var emptySetting = { ID: 0, Name: '', Value: '', DefaultValue: '' };
66
- var _c = React.useState(emptySetting), editnewSetting = _c[0], setEditNewSetting = _c[1];
67
- var _d = React.useState('New'), editNew = _d[0], setEditNew = _d[1];
68
- var _e = React.useState(false), showModal = _e[0], setShowModal = _e[1];
69
- var _f = React.useState(false), showWarning = _f[0], setShowWarning = _f[1];
70
- var _g = React.useState(false), hasChanged = _g[0], setHasChanged = _g[1];
71
- var _h = React.useState([]), errors = _h[0], setErrors = _h[1];
72
- React.useEffect(function () {
73
- if (status === 'unintiated' || status === 'changed')
74
- dispatch(props.SettingsSlice.Fetch());
75
- }, [dispatch, status]);
76
- React.useEffect(function () {
77
- if (searchStatus === 'unintiated' || status === 'changed')
78
- dispatch(props.SettingsSlice.DBSearch({ filter: search, sortField: sortField, ascending: ascending }));
79
- }, [dispatch, searchStatus, ascending, sortField, search]);
80
- React.useEffect(function () { setHasChanged(false); }, [showModal]);
81
- React.useEffect(function () {
82
- var e = [];
83
- if (editnewSetting.Name == null || editnewSetting.Name.length === 0)
84
- e.push('A Name is required');
85
- if (editnewSetting.Name != null && editnewSetting.Name.length > 0 && allSettings.findIndex(function (s) { return s.Name.toLowerCase() === editnewSetting.Name.toLowerCase() && s.ID !== editnewSetting.ID; }) > -1)
86
- e.push('A Settign with this Name already exists.');
87
- if (editnewSetting.Value == null || editnewSetting.Value.length === 0)
88
- e.push('A Value is required');
89
- setErrors(e);
90
- }, [editnewSetting]);
91
- var searchFields = [
92
- { key: 'Name', label: 'Name', type: 'string', isPivotField: false },
93
- { key: 'DefaultValue', label: 'Default Value', type: 'string', isPivotField: false },
94
- { key: 'Value', label: 'Value', type: 'string', isPivotField: false }
95
- ];
96
- if (status === 'error')
97
- return React.createElement("div", { style: { width: '100%', height: '100%' } },
98
- React.createElement(react_interactive_1.ServerErrorIcon, { Show: true, Label: 'A Server Error Occured. Please Reload the Application' }));
99
- return (React.createElement(React.Fragment, null,
100
- React.createElement(react_interactive_1.LoadingScreen, { Show: status === 'loading' }),
101
- React.createElement("div", { style: { width: '100%', height: '100%' } },
102
- React.createElement(react_interactive_1.SearchBar, { CollumnList: searchFields, SetFilter: function (flds) { return dispatch(props.SettingsSlice.DBSearch({ filter: flds, sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: { key: 'Name', label: 'Name', type: 'string', isPivotField: false }, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Settings', GetEnum: function () {
103
- return function () { };
104
- } },
105
- React.createElement("li", { className: "nav-item", style: { width: '15%', paddingRight: 10 } },
106
- React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
107
- React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "Actions:"),
108
- React.createElement("form", null,
109
- React.createElement("button", { className: "btn btn-primary", onClick: function (event) { setEditNewSetting(emptySetting); setEditNew('New'); setShowModal(true); event.preventDefault(); } }, "Add Setting"))))),
110
- React.createElement("div", { style: { width: '100%', height: 'calc( 100% - 136px)' } },
111
- React.createElement(react_table_1.default, { cols: [
112
- { key: 'Name', field: 'Name', label: 'Setting Name', headerStyle: { width: '10%' }, rowStyle: { width: '10%' } },
113
- { key: 'Value', field: 'Value', label: 'Current Value', headerStyle: { width: '10%' }, rowStyle: { width: '10%' } },
114
- { key: 'DefaultValue', field: 'DefaultValue', label: 'Default Value', headerStyle: { width: '20%' }, rowStyle: { width: '20%' } },
115
- { key: 'scroll', label: '', headerStyle: { width: 17, padding: 0 }, rowStyle: { width: 0, padding: 0 } },
116
- ], tableClass: "table table-hover", data: data, sortKey: sortField, ascending: ascending, onSort: function (d) {
117
- if (d.colKey === 'scroll' || d.colField === undefined)
118
- return;
119
- if (d.colField === sortField)
120
- setAscending(!ascending);
121
- else {
122
- setAscending(true);
123
- setSortField(d.colField);
124
- }
125
- if (d.colField === sortField)
126
- dispatch(props.SettingsSlice.DBSearch({ filter: search, sortField: sortField, ascending: true }));
127
- else
128
- dispatch(props.SettingsSlice.DBSearch({ filter: search, sortField: d.colField, ascending: ascending }));
129
- }, onClick: function (item) { setEditNewSetting(item.row); setShowModal(true); setEditNew('Edit'); }, theadStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, tbodyStyle: { display: 'block', overflowY: 'scroll', maxHeight: window.innerHeight - 300, width: '100%' }, rowStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, selected: function () { return false; } }))),
130
- React.createElement(react_interactive_1.Modal, { Title: editNew === 'Edit' ? editnewSetting.Name + ' - Setting' : 'Add New Setting', Show: showModal, ShowX: true, Size: 'lg', ShowCancel: editNew === 'Edit', ConfirmText: 'Save', CancelText: 'Delete', CallBack: function (conf, isBtn) {
131
- if (conf && editNew === 'New')
132
- dispatch(props.SettingsSlice.DBAction({ verb: 'POST', record: editnewSetting }));
133
- if (conf && editNew === 'Edit')
134
- dispatch(props.SettingsSlice.DBAction({ verb: 'PATCH', record: editnewSetting }));
135
- if (!conf && isBtn)
136
- setShowWarning(true);
137
- setShowModal(false);
138
- }, DisableConfirm: (editNew === 'Edit' && !hasChanged) || errors.length > 0, ConfirmShowToolTip: errors.length > 0, ConfirmToolTipContent: errors.map(function (t, i) { return React.createElement("p", { key: i },
139
- gpa_symbols_1.CrossMark,
140
- " ",
141
- t,
142
- " "); }) },
143
- React.createElement("div", { className: "row" },
144
- React.createElement("div", { className: "col" },
145
- React.createElement(react_forms_1.Input, { Record: editnewSetting, Field: 'Name', Label: 'Setting Name', Feedback: 'A unique Name is required.', Valid: function (field) { return editnewSetting.Name != null && editnewSetting.Name.length > 0 && allSettings.findIndex(function (s) { return s.Name === editnewSetting.Name && s.ID !== editnewSetting.ID; }) < 0; }, Setter: function (record) { setEditNewSetting(record); setHasChanged(true); } }),
146
- React.createElement(react_forms_1.Input, { Record: editnewSetting, Field: 'Value', Label: 'Value', Feedback: 'Value is required.', Valid: function (field) { return editnewSetting.Value != null && editnewSetting.Value.length > 0; }, Setter: function (record) { setEditNewSetting(record); setHasChanged(true); } }),
147
- React.createElement(react_forms_1.Input, { Record: editnewSetting, Field: 'DefaultValue', Label: 'Default Value', Valid: function (field) { return true; }, Setter: function (record) { setEditNewSetting(record); setHasChanged(true); } })))),
148
- React.createElement(react_interactive_1.Warning, { Title: 'Delete Setting', Message: 'This will Delete this Setting from the System. This can have unintended consequences and cause the System to crash. Are you sure you want to continue?', Show: showWarning, CallBack: function (conf) { if (conf)
149
- dispatch(props.SettingsSlice.DBAction({ verb: 'DELETE', record: editnewSetting })); setShowWarning(false); } })));
150
- }
151
- exports.default = Setting;
@@ -1,28 +0,0 @@
1
- import * as React from 'react';
2
- import { IStartEnd, IStartDuration, IEndDuration, ICenterDuration, TimeUnit } from './TimeWindowUtils';
3
- import { DateUnit } from './TimeFilter/QuickSelects';
4
- export type ITimeFilter = IStartEnd | IStartDuration | IEndDuration | ICenterDuration;
5
- export declare function getTimeWindow(flt: ITimeFilter, format?: string): {
6
- center: string;
7
- start: string;
8
- end: string;
9
- unit: TimeUnit;
10
- duration: number;
11
- halfDuration: number;
12
- };
13
- /**
14
- * filter: an interface of IStartEnd | IStartDuration | IEndDuration | ICenterDuration
15
- * showQuickSelect: displays Quick Select component
16
- * isHorizontal: displays Quick Selects in horizontal view
17
- */
18
- interface IProps {
19
- filter: ITimeFilter;
20
- setFilter: (center: string, start: string, end: string, unit: TimeUnit, duration: number) => void;
21
- showQuickSelect: boolean;
22
- dateTimeSetting: 'center' | 'startWindow' | 'endWindow' | 'startEnd';
23
- timeZone: string;
24
- isHorizontal: boolean;
25
- format?: DateUnit;
26
- }
27
- declare const TimeFilter: (props: IProps) => React.JSX.Element;
28
- export default TimeFilter;
package/lib/TimeFilter.js DELETED
@@ -1,273 +0,0 @@
1
- "use strict";
2
- //******************************************************************************************************
3
- // TimeFilter.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
- // 09/16/2021 - Christoph Lackner
21
- // Generated original version of source code.
22
- // 06/20/2024 - Ali Karrar
23
- // Moved TimeFilter from SEBrowser to gemstone
24
- //******************************************************************************************************
25
- var __assign = (this && this.__assign) || function () {
26
- __assign = Object.assign || function(t) {
27
- for (var s, i = 1, n = arguments.length; i < n; i++) {
28
- s = arguments[i];
29
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
30
- t[p] = s[p];
31
- }
32
- return t;
33
- };
34
- return __assign.apply(this, arguments);
35
- };
36
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
37
- if (k2 === undefined) k2 = k;
38
- var desc = Object.getOwnPropertyDescriptor(m, k);
39
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
40
- desc = { enumerable: true, get: function() { return m[k]; } };
41
- }
42
- Object.defineProperty(o, k2, desc);
43
- }) : (function(o, m, k, k2) {
44
- if (k2 === undefined) k2 = k;
45
- o[k2] = m[k];
46
- }));
47
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
48
- Object.defineProperty(o, "default", { enumerable: true, value: v });
49
- }) : function(o, v) {
50
- o["default"] = v;
51
- });
52
- var __importStar = (this && this.__importStar) || function (mod) {
53
- if (mod && mod.__esModule) return mod;
54
- var result = {};
55
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
56
- __setModuleDefault(result, mod);
57
- return result;
58
- };
59
- var __importDefault = (this && this.__importDefault) || function (mod) {
60
- return (mod && mod.__esModule) ? mod : { "default": mod };
61
- };
62
- Object.defineProperty(exports, "__esModule", { value: true });
63
- exports.getTimeWindow = getTimeWindow;
64
- var React = __importStar(require("react"));
65
- var moment_1 = __importDefault(require("moment"));
66
- var react_forms_1 = require("@gpa-gemstone/react-forms");
67
- var TimeWindowUtils_1 = require("./TimeWindowUtils");
68
- var QuickSelects_1 = require("./TimeFilter/QuickSelects");
69
- // Converts ITimeFilter to an ITimeWindow filter
70
- function getTimeWindow(flt, format) {
71
- var _a, _b;
72
- var _c, _d, _e;
73
- var center, start, end, unit, duration, halfDuration;
74
- if ('center' in flt && 'halfDuration' in flt) { // type is ICenterDuration
75
- center = (0, TimeWindowUtils_1.getMoment)(flt.center, format);
76
- _a = (0, TimeWindowUtils_1.getStartEndTime)(center, flt.halfDuration, flt.unit), start = _a[0], end = _a[1];
77
- unit = flt.unit;
78
- halfDuration = flt.halfDuration;
79
- duration = halfDuration * 2;
80
- }
81
- else if ('start' in flt && 'duration' in flt) { // type is IStartDuration
82
- start = (0, TimeWindowUtils_1.getMoment)(flt.start, format);
83
- var d = moment_1.default.duration(flt.duration / 2.0, flt.unit);
84
- center = start.clone().add(d);
85
- end = center.clone().add(d);
86
- unit = flt.unit;
87
- duration = flt.duration,
88
- halfDuration = duration / 2.0;
89
- }
90
- else if ('end' in flt && 'duration' in flt) { // type is IEndDuration
91
- end = (0, TimeWindowUtils_1.getMoment)(flt.end, format);
92
- var d = moment_1.default.duration(flt.duration / 2.0, flt.unit);
93
- center = end.clone().subtract(d);
94
- start = center.clone().subtract(d);
95
- unit = flt.unit;
96
- duration = flt.duration,
97
- halfDuration = duration / 2.0;
98
- }
99
- else if ('start' in flt && 'end' in flt) { // type is IStartEnd
100
- start = (0, TimeWindowUtils_1.getMoment)(flt.start, format);
101
- end = (0, TimeWindowUtils_1.getMoment)(flt.end, format);
102
- _b = (0, TimeWindowUtils_1.findAppropriateUnit)(start, end, undefined, true), unit = _b[0], halfDuration = _b[1];
103
- var d = moment_1.default.duration(halfDuration, unit);
104
- center = start.clone().add(d);
105
- duration = halfDuration * 2;
106
- }
107
- return { center: (_c = center === null || center === void 0 ? void 0 : center.format(format)) !== null && _c !== void 0 ? _c : '',
108
- start: (_d = start === null || start === void 0 ? void 0 : start.format(format)) !== null && _d !== void 0 ? _d : '',
109
- end: (_e = end === null || end === void 0 ? void 0 : end.format(format)) !== null && _e !== void 0 ? _e : '',
110
- unit: unit !== null && unit !== void 0 ? unit : 'ms',
111
- duration: duration !== null && duration !== void 0 ? duration : 0,
112
- halfDuration: halfDuration !== null && halfDuration !== void 0 ? halfDuration : 0 };
113
- }
114
- // Returns a row div element with props as children of row
115
- function Row(props) {
116
- var _a;
117
- if (props.addRow) {
118
- return React.createElement("div", { className: "row ".concat((_a = props.class) !== null && _a !== void 0 ? _a : '') }, props.children);
119
- }
120
- return React.createElement(React.Fragment, null, props.children);
121
- }
122
- var TimeFilter = function (props) {
123
- var _a, _b, _c;
124
- var format = (0, QuickSelects_1.getFormat)(props.format);
125
- var QuickSelects = React.useMemo(function () { return QuickSelects_1.AvailableQuickSelects.filter(function (qs) { return !qs.hideQuickPick(props.format); }); }, [props.format]);
126
- var _d = React.useState(-1), activeQP = _d[0], setActiveQP = _d[1];
127
- var _e = React.useState(getTimeWindow(props.filter, format)), filter = _e[0], setFilter = _e[1];
128
- React.useEffect(function () {
129
- if (!isEqual(filter, props.filter))
130
- props.setFilter(filter.center, filter.start, filter.end, filter.unit, filter.duration);
131
- }, [filter]);
132
- //Checks typing of ITimeFilter and then compares to ITimeWindow
133
- function isEqual(flt1, flt2) {
134
- var flt = getTimeWindow(flt2, format);
135
- return flt1.center == flt.center &&
136
- flt1.unit == flt.unit &&
137
- flt1.duration == flt.duration;
138
- }
139
- React.useEffect(function () {
140
- if (!isEqual(filter, props.filter)) {
141
- var flt = getTimeWindow(props.filter, format);
142
- setFilter(flt);
143
- }
144
- }, [props.filter]);
145
- return (React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
146
- React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "Date/Time Filter:"),
147
- React.createElement(Row, { addRow: props.isHorizontal },
148
- props.dateTimeSetting === 'center' ?
149
- React.createElement(Row, { addRow: !props.isHorizontal },
150
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
151
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "center", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
152
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { center: r.center, start: r.start, end: r.end })); });
153
- setActiveQP(-1);
154
- }, Label: 'Time Window Center:', Type: (_a = props.format) !== null && _a !== void 0 ? _a : 'datetime-local', Valid: function () { return true; }, Format: format })))
155
- : null,
156
- props.dateTimeSetting === 'startWindow' || props.dateTimeSetting === 'startEnd' ?
157
- React.createElement(Row, { addRow: !props.isHorizontal },
158
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
159
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "start", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
160
- var _a;
161
- var halfDur = filter.halfDuration;
162
- var unit = filter.unit;
163
- if (props.dateTimeSetting === 'startEnd') {
164
- _a = (0, TimeWindowUtils_1.findAppropriateUnit)((0, TimeWindowUtils_1.getMoment)(r.start, format), (0, TimeWindowUtils_1.getMoment)(filter.end, format), undefined, true), unit = _a[0], halfDur = _a[1];
165
- }
166
- var flt = getTimeWindow({ start: r.start, duration: halfDur * 2, unit: unit }, format);
167
- setFilter(flt);
168
- setActiveQP(-1);
169
- }, Label: 'Start of Time Window:', Type: (_b = props.format) !== null && _b !== void 0 ? _b : 'datetime-local', Valid: function () { return true; }, Format: format })))
170
- : null,
171
- props.dateTimeSetting === 'endWindow' || props.dateTimeSetting === 'startEnd' ?
172
- React.createElement(Row, { addRow: !props.isHorizontal },
173
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
174
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "end", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
175
- var _a;
176
- var halfDur = filter.halfDuration;
177
- var unit = filter.unit;
178
- if (props.dateTimeSetting === 'startEnd') {
179
- _a = (0, TimeWindowUtils_1.findAppropriateUnit)((0, TimeWindowUtils_1.getMoment)(filter.start, format), (0, TimeWindowUtils_1.getMoment)(r.end, format), undefined, true), unit = _a[0], halfDur = _a[1];
180
- }
181
- var flt = getTimeWindow({ end: r.end, duration: halfDur * 2, unit: unit }, format);
182
- setFilter(flt);
183
- setActiveQP(-1);
184
- }, Label: 'End of Time Window :', Type: (_c = props.format) !== null && _c !== void 0 ? _c : 'datetime-local', Valid: function () { return true; }, Format: format })))
185
- : null,
186
- props.dateTimeSetting === 'center' ?
187
- React.createElement(React.Fragment, null,
188
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(+/-): "),
189
- React.createElement(Row, { addRow: !props.isHorizontal },
190
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
191
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'halfDuration', Setter: function (r) {
192
- var flt = getTimeWindow({ center: filter.center, halfDuration: r.halfDuration, unit: filter.unit }, format);
193
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, start: flt.start, end: flt.end })); });
194
- setActiveQP(-1);
195
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
196
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
197
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
198
- var flt = getTimeWindow({ center: filter.center, halfDuration: filter.halfDuration, unit: r.unit }, format);
199
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, start: flt.start, end: flt.end })); });
200
- setActiveQP(-1);
201
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
202
- Value: unit,
203
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
204
- }); }) }))))
205
- : null,
206
- props.dateTimeSetting === 'startWindow' ?
207
- React.createElement(React.Fragment, null,
208
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(+): "),
209
- React.createElement(Row, { addRow: !props.isHorizontal },
210
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
211
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'duration', Setter: function (r) {
212
- var flt = getTimeWindow({ start: filter.start, duration: r.duration, unit: filter.unit }, format);
213
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, center: flt.center, end: flt.end })); });
214
- setActiveQP(-1);
215
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
216
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
217
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
218
- var flt = getTimeWindow({ start: filter.start, duration: filter.duration, unit: r.unit }, format);
219
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, center: flt.center, end: flt.end })); });
220
- setActiveQP(-1);
221
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
222
- Value: unit,
223
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
224
- }); }) }))))
225
- : null,
226
- props.dateTimeSetting === 'endWindow' ?
227
- React.createElement(React.Fragment, null,
228
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(-): "),
229
- React.createElement(Row, { addRow: !props.isHorizontal },
230
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
231
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'duration', Setter: function (r) {
232
- var flt = getTimeWindow({ end: filter.end, duration: r.duration, unit: filter.unit }, format);
233
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, center: flt.center, start: flt.start })); });
234
- setActiveQP(-1);
235
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
236
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
237
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
238
- var flt = getTimeWindow({ end: filter.end, duration: filter.duration, unit: r.unit }, format);
239
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, center: flt.center, start: flt.start })); });
240
- setActiveQP(-1);
241
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
242
- Value: unit,
243
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
244
- }); }) }))))
245
- : null,
246
- props.showQuickSelect ?
247
- React.createElement("div", { className: props.isHorizontal ? 'col-8' : 'row' },
248
- React.createElement(Row, { addRow: props.isHorizontal, class: "justify-content-center" }, QuickSelects.map(function (qs, i) {
249
- if (i % 3 !== 0)
250
- return null;
251
- return (React.createElement("div", { key: i, className: props.isHorizontal ? 'col-2' : "col-4", style: { paddingLeft: (props.isHorizontal ? 0 : (i % 9 == 0 ? 15 : 0)), paddingRight: (props.isHorizontal ? 2 : ((i % 18 == 6 || i % 18 == 15) ? 15 : 2)), marginTop: 10 } },
252
- React.createElement("ul", { className: "list-group", key: i },
253
- React.createElement("li", { key: i, style: { cursor: 'pointer' }, onClick: function () {
254
- var flt = getTimeWindow(QuickSelects[i].createFilter(props.timeZone, props.format), format);
255
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
256
- setActiveQP(i);
257
- }, className: "item badge badge-" + (i == activeQP ? "primary" : "secondary") }, QuickSelects[i].label),
258
- i + 1 < QuickSelects.length ?
259
- React.createElement("li", { key: i + 1, style: { marginTop: 3, cursor: 'pointer' }, className: "item badge badge-" + (i + 1 == activeQP ? "primary" : "secondary"), onClick: function () {
260
- var flt = getTimeWindow(QuickSelects[i + 1].createFilter(props.timeZone, props.format), format);
261
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
262
- setActiveQP(i + 1);
263
- } }, QuickSelects[i + 1].label) : null,
264
- i + 2 < QuickSelects.length ?
265
- React.createElement("li", { key: i + 2, style: { marginTop: 3, cursor: 'pointer' }, className: "item badge badge-" + (i + 2 == activeQP ? "primary" : "secondary"), onClick: function () {
266
- var flt = getTimeWindow(QuickSelects[i + 2].createFilter(props.timeZone, props.format), format);
267
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
268
- setActiveQP(i + 2);
269
- } }, QuickSelects[i + 2].label) : null)));
270
- })))
271
- : null)));
272
- };
273
- exports.default = TimeFilter;