-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transform): initial support for transform display
- Loading branch information
Showing
9 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react' | ||
|
||
interface CodeProps { | ||
data: string | undefined | ||
} | ||
|
||
const Code: React.FunctionComponent<CodeProps> = (props: CodeProps) => { | ||
const { data } = props | ||
|
||
const lines = data.split('\n') | ||
|
||
return ( | ||
<div className="code"> | ||
<pre style={{ float: 'left', margin: '0 20px', color: '#bbb' }}>{lines.map((_, i) => (`${i}\n`))}</pre> | ||
<pre style={{ float: 'left' }}>{data}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export default Code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react' | ||
|
||
import { WorkingDataset } from '../models/store' | ||
import { ApiActionThunk } from '../store/api' | ||
|
||
import Code from './Code' | ||
|
||
export interface TransformProps { | ||
peername: string | ||
name: string | ||
value: string | ||
preview: string | ||
history: boolean | ||
workingDataset: WorkingDataset | ||
write: (peername: string, name: string, dataset: any) => ApiActionThunk | ||
} | ||
|
||
const Transform: React.FunctionComponent<TransformProps> = (props) => { | ||
const { value } = props | ||
|
||
return ( | ||
<Code data={value} /> | ||
) | ||
} | ||
|
||
export default Transform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { connect } from 'react-redux' | ||
import { bindActionCreators, Dispatch } from 'redux' | ||
import Transform, { TransformProps } from '../components/Transform' | ||
import Store from '../models/store' | ||
import { fsiWriteAndFetch } from '../actions/api' | ||
|
||
const mapStateToProps = (state: Store) => { | ||
const { workingDataset, selections } = state | ||
const { value } = workingDataset.components.transform | ||
|
||
const { peername, name } = selections | ||
|
||
// get data for the currently selected component | ||
return { | ||
peername, | ||
name, | ||
value, | ||
history, | ||
workingDataset | ||
} | ||
} | ||
|
||
const mergeProps = (props: any, actions: any): TransformProps => { //eslint-disable-line | ||
return { ...props, ...actions } | ||
} | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => { | ||
return bindActionCreators({ write: fsiWriteAndFetch }, dispatch) | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Transform) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import Code from '../app/components/Code' | ||
|
||
export default { | ||
title: 'Code' | ||
} | ||
|
||
const wrap = (component) => { | ||
return ( | ||
<div style={{ maxWidth: 650, margin: '0 auto' }}> | ||
{component} | ||
</div> | ||
) | ||
} | ||
|
||
const basicTransformText = ` | ||
def transform(ds,ctx): | ||
ds.set_body([[1,2,3,4],[5,6,7,8]]) | ||
` | ||
|
||
export const basicTransform = () => wrap(<Code data={basicTransformText} />) | ||
|
||
basicTransform.story = { | ||
name: 'Transform: Basic Starlark', | ||
parameters: { | ||
notes: `short code viewer` | ||
} | ||
} |