Skip to content

Commit

Permalink
Fix playground links making editor un-editable (#134)
Browse files Browse the repository at this point in the history
* Fix links making playground uneditable

The parsed program is now updated only once, when the page loads, rather
than when the component is updated.

* Revert "Fix links making playground uneditable"

This reverts commit 599db0f.

* Standardize parameters for workspace

Now, we can pass in only a value and an optional library number.
This allows the Playground to handle parsing of the library program. If
there is a program passed in via the hash, the parsed program will be
passed. If not, the parsed program will be undefind, causing the redux
store value to be passed (using the `||` operator).

* Add test for playground with link

Also updated the old test snapshot

* Bump version 0.1.1 -> 0.1.2
  • Loading branch information
remo5000 authored and ning-y committed Jun 25, 2018
1 parent 6e93ec9 commit 8cfbcb2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "cadet-frontend",
"version": "0.1.1",
"version": "0.1.2",
"scripts-info": {
"format": "Format source code",
"start": "Start the Webpack development server",
Expand Down
9 changes: 5 additions & 4 deletions src/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Text } from '@blueprintjs/core'
import { IconNames } from '@blueprintjs/icons'
import { decompressFromEncodedURIComponent } from 'lz-string'
import * as qs from 'query-string'
import * as React from 'react'
import { HotKeys } from 'react-hotkeys'
Expand Down Expand Up @@ -36,9 +37,8 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
handlers={this.handlers}
>
<WorkspaceContainer
libQuery={parseLibrary(this.props)}
prgrmQuery={parsePrgrm(this.props)}
editorValue={this.props.editorValue}
library={parseLibrary(this.props)}
editorValue={parsePrgrm(this.props) || this.props.editorValue}
sideContentTabs={[playgroundIntroduction]}
/>
</HotKeys>
Expand All @@ -53,7 +53,8 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
const parsePrgrm = (props: IPlaygroundProps) => {
const qsParsed = qs.parse(props.location.hash)
// legacy support
return qsParsed.lz !== undefined ? qsParsed.lz : qsParsed.prgrm
const program = qsParsed.lz !== undefined ? qsParsed.lz : qsParsed.prgrm
return program !== undefined ? decompressFromEncodedURIComponent(program) : undefined
}

const parseLibrary = (props: IPlaygroundProps) => {
Expand Down
10 changes: 10 additions & 0 deletions src/components/__tests__/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ test('Playground renders correctly', () => {
const tree = shallow(app)
expect(tree.debug()).toMatchSnapshot()
})

test('Playground with link renders correctly', () => {
const props = {
...mockRouterProps('/playground#lib=2&prgrm=CYSwzgDgNghgngCgOQAsCmUoHsCESCUA3EA', {}),
editorValue: 'This should not show up'
}
const app = <Playground {...props} />
const tree = shallow(app)
expect(tree.debug()).toMatchSnapshot()
})
8 changes: 7 additions & 1 deletion src/components/__tests__/__snapshots__/Playground.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

exports[`Playground renders correctly 1`] = `
"<HotKeys className=\\"Playground pt-dark\\" keyMap={{...}} handlers={{...}}>
<Connect(Workspace) libQuery={[undefined]} prgrmQuery={[undefined]} editorValue=\\"Test value\\" sideContentTabs={{...}} />
<Connect(Workspace) library={[undefined]} editorValue=\\"Test value\\" sideContentTabs={{...}} />
</HotKeys>"
`;

exports[`Playground with link renders correctly 1`] = `
"<HotKeys className=\\"Playground pt-dark\\" keyMap={{...}} handlers={{...}}>
<Connect(Workspace) library={2} editorValue=\\"display(\\\\'hello!\\\\');\\" sideContentTabs={{...}} />
</HotKeys>"
`;
15 changes: 1 addition & 14 deletions src/components/workspace/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { decompressFromEncodedURIComponent } from 'lz-string'
import Resizable, { ResizableProps, ResizeCallback } from 're-resizable'
import * as React from 'react'

Expand All @@ -22,8 +21,7 @@ export type DispatchProps = {

export type OwnProps = {
controlBarOptions?: ControlBarOwnProps
libQuery?: number
prgrmQuery?: string
library?: number
editorValue?: string
mcq?: IMCQQuestion
sideContentTabs: SideContentTab[]
Expand All @@ -41,20 +39,9 @@ class Workspace extends React.Component<WorkspaceProps, {}> {
private sideDividerDiv: HTMLDivElement

public componentDidMount() {
this.componentDidUpdate()
this.maxDividerHeight = this.sideDividerDiv.clientHeight
}

public componentDidUpdate() {
if (this.props.prgrmQuery !== undefined) {
const prgrmParsed = decompressFromEncodedURIComponent(this.props.prgrmQuery)
this.props.updateEditorValue(prgrmParsed)
}
if (this.props.libQuery !== undefined) {
this.props.changeChapter(this.props.libQuery)
}
}

/**
* side-content-divider gives the side content a bottom margin. I use a div
* element instead of CSS so that when the user resizes the side-content all
Expand Down

0 comments on commit 8cfbcb2

Please sign in to comment.