fix: change getAsset to not return a promise (#3232)

* fix: change getAsset to not return a promise

* fix: update markdown widget per getAsset changes

* test: fix editor component image test

* docs: update getAsset docs
This commit is contained in:
Erez Rokah
2020-02-13 02:12:36 +02:00
committed by GitHub
parent 2457c29baf
commit ab685e8594
30 changed files with 317 additions and 355 deletions

View File

@ -1,50 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
class Asset extends React.Component {
static propTypes = {
path: PropTypes.string.isRequired,
getAsset: PropTypes.func.isRequired,
component: PropTypes.elementType.isRequired,
folder: PropTypes.string,
};
subscribed = true;
state = {
value: null,
};
async _fetchAsset() {
const { getAsset, path, folder } = this.props;
const value = await getAsset(path, folder);
if (this.subscribed) {
this.setState({ value });
}
}
componentDidMount() {
this._fetchAsset();
}
componentWillUnmount() {
this.subscribed = false;
}
componentDidUpdate(prevProps) {
if (
prevProps.path !== this.props.path ||
prevProps.getAsset !== this.props.getAsset ||
prevProps.folder !== this.props.folder
) {
this._fetchAsset();
}
}
render() {
const { component, ...props } = this.props;
return React.createElement(component, { ...props, value: this.state.value });
}
}
export default Asset;

View File

@ -9,7 +9,6 @@ import AuthenticationPage from './AuthenticationPage';
import WidgetPreviewContainer from './WidgetPreviewContainer';
import ObjectWidgetTopBar from './ObjectWidgetTopBar';
import GoBackButton from './GoBackButton';
import Asset from './Asset';
import {
fonts,
colorsRaw,
@ -56,7 +55,6 @@ export const NetlifyCmsUiDefault = {
effects,
reactSelectStyles,
GlobalStyles,
Asset,
};
export {
Dropdown,
@ -89,5 +87,4 @@ export {
reactSelectStyles,
GlobalStyles,
GoBackButton,
Asset,
};