client/components/pages/parts/admin-panel-search-results.js

"use strict";

require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.reflect.construct.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.function.name.js");
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var bootstrap = _interopRequireWildcard(require("react-bootstrap"));
var _privilegeBadges = _interopRequireDefault(require("./privilege-badges"));
var _privsEditModal = _interopRequireDefault(require("./privs-edit-modal"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _privilegesUtils = require("../../../../common/helpers/privileges-utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /*
                                                                                                                                                                                                                                                                                                                                           * Copyright (C) 2023 Shivam Awasthi
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * This program is free software; you can redistribute it and/or modify
                                                                                                                                                                                                                                                                                                                                           * it under the terms of the GNU General Public License as published by
                                                                                                                                                                                                                                                                                                                                           * the Free Software Foundation; either version 2 of the License, or
                                                                                                                                                                                                                                                                                                                                           * (at your option) any later version.
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * This program is distributed in the hope that it will be useful,
                                                                                                                                                                                                                                                                                                                                           * but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                                                                                                                                                                                                                                                                                                           * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                                                                                                                                                                                                                                                                                                                                           * GNU General Public License for more details.
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * You should have received a copy of the GNU General Public License along
                                                                                                                                                                                                                                                                                                                                           * with this program; if not, write to the Free Software Foundation, Inc.,
                                                                                                                                                                                                                                                                                                                                           * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
                                                                                                                                                                                                                                                                                                                                           */
var Button = bootstrap.Button,
  Table = bootstrap.Table;
/**
 * Renders the document and displays the 'AdminPanelSearchResults' page.
 * @returns {ReactElement} a HTML document which displays the AdminPanelSearchResults.
 * @param {object} props - Properties passed to the component.
 */
var AdminPanelSearchResults = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2.default)(AdminPanelSearchResults, _React$Component);
  var _super = _createSuper(AdminPanelSearchResults);
  function AdminPanelSearchResults(props) {
    var _this;
    (0, _classCallCheck2.default)(this, AdminPanelSearchResults);
    _this = _super.call(this, props);
    _this.state = {
      selectedUser: null,
      showModal: false
    };
    _this.onCloseModal = _this.onCloseModal.bind((0, _assertThisInitialized2.default)(_this));
    return _this;
  }
  (0, _createClass2.default)(AdminPanelSearchResults, [{
    key: "onCloseModal",
    value: function onCloseModal() {
      this.setState({
        showModal: false
      });
    }
  }, {
    key: "openPrivsEditModal",
    value: function openPrivsEditModal(user) {
      this.setState({
        selectedUser: user,
        showModal: true
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var noResults = !this.props.results || this.props.results.length === 0;
      var results = this.props.results.map(function (result) {
        if (!result) {
          return null;
        }
        var name = result.defaultAlias ? result.defaultAlias.name : '(unnamed)';
        var link = "/editor/".concat(result.bbid);

        /* eslint-disable react/jsx-no-bind */
        return /*#__PURE__*/_react.default.createElement("tr", {
          key: result.bbid
        }, /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement("a", {
          href: link
        }, /*#__PURE__*/_react.default.createElement("img", {
          className: "margin-right-0-3",
          height: "15",
          src: (0, _privilegesUtils.getPrivilegeShieldIcon)(result.privs)
        }), name)), /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement(_privilegeBadges.default, {
          privs: result.privs
        })), /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement(Button, {
          className: "btn btn-sm",
          variant: "outline-info",
          onClick: function onClick() {
            return _this2.openPrivsEditModal(result);
          }
        }, "Edit")));
      });
      var tableCssClasses = 'table table-striped';
      if (noResults) {
        return null;
      }
      return /*#__PURE__*/_react.default.createElement("div", null, this.state.showModal && /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_privsEditModal.default, {
        adminId: this.props.user.id,
        handleCloseModal: this.onCloseModal,
        show: this.state.showModal,
        targetUser: this.state.selectedUser,
        updateResultsOnPrivsChange: this.props.updateResultsOnPrivsChange
      })), /*#__PURE__*/_react.default.createElement("h3", {
        className: "search-results-heading"
      }, "Search Results"), /*#__PURE__*/_react.default.createElement("hr", {
        className: "thin"
      }), /*#__PURE__*/_react.default.createElement(Table, {
        responsive: true,
        className: tableCssClasses
      }, /*#__PURE__*/_react.default.createElement("thead", null, /*#__PURE__*/_react.default.createElement("tr", null, /*#__PURE__*/_react.default.createElement("th", {
        width: "42%"
      }, "Name"), /*#__PURE__*/_react.default.createElement("th", {
        width: "42%"
      }, "Privileges"), /*#__PURE__*/_react.default.createElement("th", {
        width: "16%"
      }))), /*#__PURE__*/_react.default.createElement("tbody", null, results)));
    }
  }]);
  return AdminPanelSearchResults;
}(_react.default.Component);
(0, _defineProperty2.default)(AdminPanelSearchResults, "displayName", 'AdminPanelSearchResults');
(0, _defineProperty2.default)(AdminPanelSearchResults, "propTypes", {
  results: _propTypes.default.array,
  updateResultsOnPrivsChange: _propTypes.default.func.isRequired,
  user: _propTypes.default.object.isRequired
});
(0, _defineProperty2.default)(AdminPanelSearchResults, "defaultProps", {
  results: null
});
var _default = AdminPanelSearchResults;
exports.default = _default;
//# sourceMappingURL=admin-panel-search-results.js.map