calcite-react
Version:
Calcite components for React
227 lines (175 loc) • 10.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ArcgisShareStyled = require("./ArcgisShare-styled");
var _Checkbox = _interopRequireDefault(require("../Checkbox"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// Third-party components (buttons, icons, etc.)
// JSON
// CSS
var ArcgisShare =
/*#__PURE__*/
function (_Component) {
_inherits(ArcgisShare, _Component);
function ArcgisShare(props) {
var _this;
_classCallCheck(this, ArcgisShare);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ArcgisShare).call(this, props));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "initGroupsState", function (groups) {
var groubsObj = {};
groups.forEach(function (group) {
var sharing = _this.props.sharing;
var isShared = sharing && sharing.groups && sharing.groups.indexOf(group.id) > -1;
groubsObj[group.id] = isShared;
});
_this.setState({
groups: groubsObj
});
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "getGroupCheckboxes", function (groups, noGroupsLabel) {
var _groups = _toConsumableArray(groups);
if (_groups.length) {
if (_this.props.promoteFavorites) {
_groups.sort(function (a, b) {
return b.isFav - a.isFav;
});
}
return _groups.map(function (group) {
var favIcon;
if (group.isFav && _this.props.promoteFavorites) {
favIcon = _react.default.createElement(_ArcgisShareStyled.StyledStarIcon, {
filled: true,
size: 16
});
}
return _react.default.createElement(_Checkbox.default, {
key: group.id,
id: group.id,
labelStyle: _objectSpread({}, _ArcgisShareStyled.GroupCheckboxLabelStyles),
checked: _this.state.groups[group.id] || false,
onChange: _this.groupChange
}, group.title, " ", favIcon);
});
}
return _react.default.createElement(_ArcgisShareStyled.StyledNoGroups, null, noGroupsLabel);
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "publicChange", function (e) {
_this.setState({
public: e.target.checked
}, function () {
_this.props.onChange(_this.state);
});
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "orgChange", function (e) {
_this.setState({
org: e.target.checked
}, function () {
_this.props.onChange(_this.state);
});
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "groupChange", function (e) {
var groupsObj = _this.state.groups;
groupsObj[e.target.id] = e.target.checked;
_this.setState({
groups: groupsObj
}, _this.changed);
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "changed", function () {
_this.props.onChange(_this.state);
});
var _sharing = _this.props.sharing;
var isPublic = _sharing && _sharing.access === 'public';
var isOrg = _sharing && _sharing.access === 'org';
_this.state = {
public: isPublic,
org: isOrg,
groups: {}
};
return _this;
}
_createClass(ArcgisShare, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.user && this.initGroupsState(this.props.user.groups);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
publicLabel = _this$props.publicLabel,
groupsLabel = _this$props.groupsLabel,
noGroupsLabel = _this$props.noGroupsLabel,
hidePublicSharing = _this$props.hidePublicSharing,
hideOrganizationSharing = _this$props.hideOrganizationSharing,
hideGroupsSharing = _this$props.hideGroupsSharing,
portal = _this$props.portal,
user = _this$props.user;
return _react.default.createElement(_ArcgisShareStyled.StyledArcgisShare, null, !hidePublicSharing ? _react.default.createElement(_Checkbox.default, {
labelStyle: _objectSpread({}, _ArcgisShareStyled.PrimaryCheckboxLabelStyles),
checked: this.state.public || false,
onChange: this.publicChange
}, publicLabel) : null, !hideOrganizationSharing ? _react.default.createElement(_Checkbox.default, {
labelStyle: _objectSpread({}, _ArcgisShareStyled.PrimaryCheckboxLabelStyles),
checked: this.state.org || this.state.public || false,
onChange: this.orgChange,
disabled: this.state.public || false
}, portal && portal.name) : null, !hideGroupsSharing ? _react.default.createElement(_ArcgisShareStyled.StyledGroupFieldset, {
name: "shareGroups"
}, _react.default.createElement(_ArcgisShareStyled.StyledLegend, null, groupsLabel, ":"), _react.default.createElement(_ArcgisShareStyled.StyledGroupContainer, null, user && this.getGroupCheckboxes(user.groups, noGroupsLabel))) : null);
}
}]);
return ArcgisShare;
}(_react.Component);
ArcgisShare.propTypes = {
/** AGOL user object. */
user: _propTypes.default.object.isRequired,
/** AGOL portal object. */
portal: _propTypes.default.object.isRequired,
/** AGOL sharing object. */
sharing: _propTypes.default.object,
/** Hide the option to share publically. */
hidePublicSharing: _propTypes.default.bool,
/** Hide the option to share to your organization. */
hideOrganizationSharing: _propTypes.default.bool,
/** Hide the option to share with your groups. */
hideGroupsSharing: _propTypes.default.bool,
/** Text label for the Public group. */
publicLabel: _propTypes.default.string,
/** Text label for the Groups header. */
groupsLabel: _propTypes.default.string,
/** Boolean toggle for highlighting favorited groups. */
promoteFavorites: _propTypes.default.bool,
/** Text label used inside the groups list when the user is not assigned to any groups */
noGroupsLabel: _propTypes.default.string
};
ArcgisShare.defaultProps = {
publicLabel: 'Everyone (public)',
groupsLabel: 'These groups',
noGroupsLabel: 'No groups for this user',
hidePublicSharing: false,
hideOrganizationSharing: false,
hideGroupsSharing: false
};
ArcgisShare.displayName = 'ArcgisShare';
var _default = ArcgisShare;
exports.default = _default;