@atlaskit/editor-plugin-card
Version:
Card plugin for @atlaskit/editor-core
79 lines • 3.46 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/* eslint-disable @repo/internal/react/no-class-components */
import React from 'react';
import { isSafeUrl } from '@atlaskit/adf-schema';
import { LazyLoadedDatasourceRenderFailedAnalyticsWrapper } from '@atlaskit/link-datasource';
import { setSelectedCardAppearance } from '../pm-plugins/doc';
export var DatasourceErrorBoundary = /*#__PURE__*/function (_React$Component) {
function DatasourceErrorBoundary() {
var _this;
_classCallCheck(this, DatasourceErrorBoundary);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, DatasourceErrorBoundary, [].concat(args));
_defineProperty(_this, "state", {
isError: false,
error: null
});
return _this;
}
_inherits(DatasourceErrorBoundary, _React$Component);
return _createClass(DatasourceErrorBoundary, [{
key: "componentDidCatch",
value: function componentDidCatch(error) {
if (this.props.handleError) {
this.props.handleError();
}
// prevent re-render children with error
if (this.state.isError) {
this.setState({
isError: true,
error: error
});
}
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
url = _this$props.url,
UnsupportedComponent = _this$props.unsupportedComponent,
view = _this$props.view,
datasourceModalType = _this$props.datasourceModalType,
datasourceId = _this$props.datasourceId;
if (this.state.isError) {
if (url && isSafeUrl(url)) {
return /*#__PURE__*/React.createElement(LazyLoadedDatasourceRenderFailedAnalyticsWrapper, {
datasourceId: datasourceId,
error: this.state.error
}, setSelectedCardAppearance('inline', undefined)(view.state, view.dispatch));
} else {
var unsupportedComponent = UnsupportedComponent ? /*#__PURE__*/React.createElement(UnsupportedComponent, null) : null;
return /*#__PURE__*/React.createElement(LazyLoadedDatasourceRenderFailedAnalyticsWrapper, {
datasourceModalType: datasourceModalType,
datasourceId: datasourceId,
error: this.state.error
}, unsupportedComponent);
}
} else {
return this.props.children;
}
}
}], [{
key: "getDerivedStateFromError",
value: function getDerivedStateFromError(error) {
return {
isError: true,
error: error
};
}
}]);
}(React.Component);