@gpa-gemstone/common-pages
Version:
Common UI pages for GPA products
198 lines (197 loc) • 15.7 kB
JavaScript
;
// ******************************************************************************************************
// SearchBar.tsx - Gbtc
//
// Copyright © 2021, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 12/17/2021 - Samuel Robinson
// Generated original version of source code.
// 12/19/2021 - C. Lackner
// Cleaned up code.
// ******************************************************************************************************
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultSearch = void 0;
var React = __importStar(require("react"));
var react_interactive_1 = require("@gpa-gemstone/react-interactive");
var react_redux_1 = require("react-redux");
/** This Implements a few standardized SearchBars */
var DefaultSearch;
(function (DefaultSearch) {
/** This Implements a standard Meter Search */
DefaultSearch.Meter = function (props) {
var defaultSearchcols = [
{ label: 'Key', key: 'AssetKey', type: 'string', isPivotField: false },
{ label: 'Name', key: 'Name', type: 'string', isPivotField: false },
{ label: 'Substation Name', key: 'Location', type: 'string', isPivotField: false },
{ label: 'Make', key: 'Make', type: 'string', isPivotField: false },
{ label: 'Model', key: 'Model', type: 'string', isPivotField: false },
{ label: 'Number of Assets', key: 'MappedAssets', type: 'number', isPivotField: false },
{ label: 'Description', key: 'Description', type: 'string', isPivotField: false },
];
var dispatch = (0, react_redux_1.useDispatch)();
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
var standardSearch = { label: 'Name', key: 'Name', type: 'string', isPivotField: false };
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Meter(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
/** This Implements a standard Substation Search */
DefaultSearch.Location = function (props) {
var standardSearch = { label: 'Name', key: 'Name', type: 'string', isPivotField: false };
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var dispatch = (0, react_redux_1.useDispatch)();
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
var defaultSearchcols = [
{ label: 'Name', key: 'Name', type: 'string', isPivotField: false },
{ label: 'Key', key: 'LocationKey', type: 'string', isPivotField: false },
{ label: 'Asset Key', key: 'Asset', type: 'string', isPivotField: false },
{ label: 'Meter Key', key: 'Meter', type: 'string', isPivotField: false },
{ label: 'Number of Assets', key: 'Assets', type: 'integer', isPivotField: false },
{ label: 'Number of Meters', key: 'Meters', type: 'integer', isPivotField: false },
{ label: 'Description', key: 'Description', type: 'string', isPivotField: false },
];
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Substation(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
/** This Implements a standard Transmission Asset Search */
DefaultSearch.Asset = function (props) {
var standardSearch = { label: 'Name', key: 'AssetName', type: 'string', isPivotField: false };
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var dispatch = (0, react_redux_1.useDispatch)();
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
var defaultSearchcols = [
{ label: 'Key', key: 'AssetKey', type: 'string', isPivotField: false },
{ label: 'Name', key: 'AssetName', type: 'string', isPivotField: false },
{ label: 'Nominal Voltage (L-L kV)', key: 'VoltageKV', type: 'number', isPivotField: false },
{ label: 'Type', key: 'AssetType', type: 'enum', isPivotField: false },
{ label: 'Meter Key', key: 'Meter', type: 'string', isPivotField: false },
{ label: 'Substation Key', key: 'Location', type: 'string', isPivotField: false },
{ label: 'Number of Meters', key: 'Meters', type: 'integer', isPivotField: false },
{ label: 'Number of Substations', key: 'Locations', type: 'integer', isPivotField: false },
{ label: 'Description', key: 'Description', type: 'string', isPivotField: false },
];
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Transmission Asset(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
/** This Implements a standard AssetGroup Search */
DefaultSearch.AssetGroup = function (props) {
var standardSearch = { label: 'Name', key: 'Name', type: 'string', isPivotField: false };
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var dispatch = (0, react_redux_1.useDispatch)();
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
var defaultSearchcols = [
{ label: 'Name', key: 'Name', type: 'string', isPivotField: false },
{ label: 'Number of Meters', key: 'Meters', type: 'integer', isPivotField: false },
{ label: 'Number of Transmission Assets', key: 'Assets', type: 'integer', isPivotField: false },
{ label: 'Number of Asset Groups', key: 'AssetGroups', type: 'integer', isPivotField: false },
{ label: 'Show in PQ Dashboard', key: 'DisplayDashboard', type: 'boolean', isPivotField: false },
{ label: 'Show in Email Subscription', key: 'DisplayEmail', type: 'boolean', isPivotField: false },
];
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Asset Group(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
/** This Implements a standard User Search */
DefaultSearch.User = function (props) {
var standardSearch = { label: 'Username', key: 'Name', type: 'string', isPivotField: false };
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var dispatch = (0, react_redux_1.useDispatch)();
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
var defaultSearchcols = [
{ label: 'Username', key: 'Name', type: 'string', isPivotField: false },
{ label: 'Email', key: 'Email', type: 'string', isPivotField: false },
{ label: 'Account Locked', key: 'LockedOut', type: 'boolean', isPivotField: false },
];
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' User(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
/** This Implements a standard Customer Search */
DefaultSearch.Customer = function (props) {
var defaultSearchcols = [
{ label: 'Name', key: 'Name', type: 'string', isPivotField: false },
{ label: 'Account Name', key: 'CustomerKey', type: 'string', isPivotField: false },
{ label: 'Phone', key: 'Phone', type: 'string', isPivotField: false },
{ label: 'Description', key: 'Description', type: 'string', isPivotField: false },
];
var standardSearch = { label: 'Name', key: 'Name', type: 'string', isPivotField: false };
var _a = React.useState([]), addlFieldCols = _a[0], setAddlFieldCols = _a[1];
var dispatch = (0, react_redux_1.useDispatch)();
var searchStatus = (0, react_redux_1.useSelector)(props.Slice.SearchStatus);
var sortField = (0, react_redux_1.useSelector)(props.Slice.SortField);
var ascending = (0, react_redux_1.useSelector)(props.Slice.Ascending);
var data = (0, react_redux_1.useSelector)(props.Slice.SearchResults);
React.useEffect(function () {
return props.GetAddlFields(setAddlFieldCols);
}, []);
return React.createElement(react_interactive_1.SearchBar, { CollumnList: __spreadArray(__spreadArray([], defaultSearchcols, true), addlFieldCols, true), SetFilter: function (flds) { return dispatch(props.Slice.DBSearch({ filter: (props.AddlFilters === undefined ? flds : __spreadArray(__spreadArray([], flds, true), props.AddlFilters, true)), sortField: sortField, ascending: ascending })); }, Direction: 'left', defaultCollumn: standardSearch, Width: '50%', Label: 'Search', ShowLoading: searchStatus === 'loading', ResultNote: searchStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Customer(s)', GetEnum: props.GetEnum, StorageID: props.StorageID }, props.children);
};
})(DefaultSearch || (exports.DefaultSearch = DefaultSearch = {}));