Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1663 from nteract/nteract-outputs-upgrade
Upgrade @nteract/outputs
- Loading branch information
Showing
9 changed files
with
137 additions
and
82 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
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,61 @@ | ||
/* @flow */ | ||
|
||
import React from "react"; | ||
import { toJS } from "mobx"; | ||
import { | ||
DisplayData, | ||
ExecuteResult, | ||
StreamText, | ||
KernelOutputError, | ||
Output, | ||
Media, | ||
RichMedia | ||
} from "@nteract/outputs"; | ||
import PlotlyTransform from "@nteract/transform-plotly"; | ||
import { VegaLite1, VegaLite2, Vega2, Vega3 } from "@nteract/transform-vega"; | ||
|
||
type Props = { output: any }; | ||
|
||
// All supported media types for output go here | ||
export const supportedMediaTypes = ( | ||
<RichMedia> | ||
<Vega3 /> | ||
<Vega2 /> | ||
<PlotlyTransform /> | ||
<VegaLite2 /> | ||
<VegaLite1 /> | ||
<Media.Json /> | ||
<Media.JavaScript /> | ||
<Media.HTML /> | ||
<Media.Markdown /> | ||
<Media.LaTeX /> | ||
<Media.SVG /> | ||
<Media.Image /> | ||
<Media.Plain /> | ||
</RichMedia> | ||
); | ||
|
||
export function isTextOutputOnly(data: Object) { | ||
const supported = React.Children.map( | ||
supportedMediaTypes.props.children, | ||
mediaComponent => mediaComponent.props.mediaType | ||
); | ||
const bundleMediaTypes = [...Object.keys(data)].filter(mediaType => | ||
supported.includes(mediaType) | ||
); | ||
|
||
return bundleMediaTypes.length === 1 && bundleMediaTypes[0] === "text/plain" | ||
? true | ||
: false; | ||
} | ||
|
||
export default function Display(props: Props) { | ||
return ( | ||
<Output output={toJS(props.output)}> | ||
<ExecuteResult expanded>{supportedMediaTypes}</ExecuteResult> | ||
<DisplayData expanded>{supportedMediaTypes}</DisplayData> | ||
<StreamText expanded /> | ||
<KernelOutputError expanded /> | ||
</Output> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,44 @@ | ||
"use babel"; | ||
|
||
import React from "react"; | ||
import Enzyme, { mount } from "enzyme"; | ||
import Adapter from "enzyme-adapter-react-16"; | ||
|
||
import Display, { | ||
isTextOutputOnly, | ||
supportedMediaTypes | ||
} from "../../lib/components/result-view/display"; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
const testOutput = { | ||
output_type: "display_data", | ||
data: { | ||
"text/html": "<p>This is some HTML that <b>WILL</b> render</p>", | ||
"text/plain": "This is some plain text that WILL NOT render" | ||
}, | ||
metadata: {} | ||
}; | ||
|
||
describe("Display output", () => { | ||
const wrapper = mount(<Display output={testOutput} />); | ||
it("renders the richest supported output", () => { | ||
expect(wrapper.find("Plain").exists()).toEqual(false); | ||
expect(wrapper.find("HTML").exists()).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe("textOutputOnly", () => { | ||
let plainBundle = { | ||
"text/plain": "I'm very plain", | ||
"text/output-not-supported": "This should be ignored" | ||
}; | ||
let richerBundle = { | ||
"text/plain": "I'm very plain", | ||
"text/html": "<div>I am a little <b>richer</b>!</div>" | ||
}; | ||
it("should return true if text is the richest supported output", () => { | ||
expect(isTextOutputOnly(plainBundle)).toEqual(true); | ||
expect(isTextOutputOnly(richerBundle)).toEqual(false); | ||
}); | ||
}); |