link to playground in embedded playgrounds
Summary: The "copy share URL" button only works in the standalone playground, not the ones embedded on the landing page or the documentation, because, we don't want people to share a link to a modified documentation page. This diff replaces the share URL button with a link to a standalone playground which then can be shared. Reviewed By: astreet Differential Revision: D8125135 fbshipit-source-id: 8b69b69caeadf5d598ed89b0abd9b742f5f07a9c
This commit is contained in:
committed by
Facebook Github Bot
parent
684dccb7b9
commit
f9df990177
@@ -18,7 +18,7 @@ import {List, setIn} from 'immutable';
|
|||||||
import PositionRecord from './PositionRecord';
|
import PositionRecord from './PositionRecord';
|
||||||
import LayoutRecord from './LayoutRecord';
|
import LayoutRecord from './LayoutRecord';
|
||||||
import Sidebar from './Sidebar';
|
import Sidebar from './Sidebar';
|
||||||
import {Row, Col} from 'antd';
|
import {Row, Col, Button} from 'antd';
|
||||||
import type {LayoutRecordT} from './LayoutRecord';
|
import type {LayoutRecordT} from './LayoutRecord';
|
||||||
import type {Yoga$Direction} from 'yoga-layout';
|
import type {Yoga$Direction} from 'yoga-layout';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
@@ -154,7 +154,7 @@ export default class Playground extends Component<Props, State> {
|
|||||||
modifyAtPath(
|
modifyAtPath(
|
||||||
path: Array<any>,
|
path: Array<any>,
|
||||||
value: any,
|
value: any,
|
||||||
selectedNodePath?: ?Array<number> = this.state.selectedNodePath,
|
selectedNodePath?: ?Array<number> = this.state.selectedNodePath
|
||||||
) {
|
) {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
const layoutDefinition = setIn(this.state.layoutDefinition, path, value);
|
const layoutDefinition = setIn(this.state.layoutDefinition, path, value);
|
||||||
@@ -164,12 +164,15 @@ export default class Playground extends Component<Props, State> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.props.persist) {
|
if (this.props.persist) {
|
||||||
window.location.hash = btoa(
|
window.location.hash = this.getHash(layoutDefinition);
|
||||||
JSON.stringify(this.removeUnchangedProperties(layoutDefinition)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getHash = (
|
||||||
|
layoutDefinition: LayoutRecordT = this.state.layoutDefinition
|
||||||
|
): string =>
|
||||||
|
btoa(JSON.stringify(this.removeUnchangedProperties(layoutDefinition)));
|
||||||
|
|
||||||
removeUnchangedProperties = (node: LayoutRecordT): Object => {
|
removeUnchangedProperties = (node: LayoutRecordT): Object => {
|
||||||
const untouchedLayout = LayoutRecord({});
|
const untouchedLayout = LayoutRecord({});
|
||||||
const untouchedPosition = PositionRecord({});
|
const untouchedPosition = PositionRecord({});
|
||||||
@@ -203,7 +206,7 @@ export default class Playground extends Component<Props, State> {
|
|||||||
this.state.selectedNodePath || []
|
this.state.selectedNodePath || []
|
||||||
).reduce(
|
).reduce(
|
||||||
(node: LayoutRecordT, cv) => node.children.get(cv),
|
(node: LayoutRecordT, cv) => node.children.get(cv),
|
||||||
this.state.layoutDefinition,
|
this.state.layoutDefinition
|
||||||
);
|
);
|
||||||
return selectedNode ? selectedNode.children.size : 0;
|
return selectedNode ? selectedNode.children.size : 0;
|
||||||
};
|
};
|
||||||
@@ -223,7 +226,8 @@ export default class Playground extends Component<Props, State> {
|
|||||||
style={{height, maxHeight: height}}
|
style={{height, maxHeight: height}}
|
||||||
ref={ref => {
|
ref={ref => {
|
||||||
this._containerRef = ref;
|
this._containerRef = ref;
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<YogaNode
|
<YogaNode
|
||||||
layoutDefinition={layoutDefinition}
|
layoutDefinition={layoutDefinition}
|
||||||
selectedNodePath={selectedNodePath}
|
selectedNodePath={selectedNodePath}
|
||||||
@@ -243,7 +247,16 @@ export default class Playground extends Component<Props, State> {
|
|||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
|
{this.props.persist ? (
|
||||||
<URLShortener />
|
<URLShortener />
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
href={`/playground#${this.getHash()}`}
|
||||||
|
type="primary"
|
||||||
|
>
|
||||||
|
Open Playground
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
@@ -284,7 +297,7 @@ export default class Playground extends Component<Props, State> {
|
|||||||
<div>
|
<div>
|
||||||
{this.props.renderSidebar(
|
{this.props.renderSidebar(
|
||||||
layoutDefinition.getIn(getPath(selectedNodePath)),
|
layoutDefinition.getIn(getPath(selectedNodePath)),
|
||||||
this.onChangeLayout,
|
this.onChangeLayout
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{playground}
|
{playground}
|
||||||
|
Reference in New Issue
Block a user