-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(report): support ability to export to CodePen (#2252)
#### Description of changes These changes add the option to export reports to CodePen in addition to an HTML file. There is a [relevant open issue](#1739) detailing a need for this type of functionality. I wasn't quite sure what the design should look like for this so I've went ahead and used a split `PrimaryButton` from `office-ui-fabric-react` in the `ExportDialog ` component but I'm definitely open to alternative approaches! ![a11y-report-export](https://user-images.githubusercontent.com/8262156/75588928-d8c8e600-5a36-11ea-930e-155c459a8bae.gif) I was also considering splitting out the HTML and CSS before sending the payload to CodePen but I figured I'd get some feedback on the changes within this PR before moving forward with more in-depth functionality. <!-- A great PR description includes: * A high level overview (usually a sentence or two) describing what the PR changes * What is the motivation for the change? This can be as simple as "addresses issue #123" * Were there any alternative approaches you considered? What tradeoffs did you consider? * What **doesn't** the change try to do? Are there any parts that you've intentionally left out-of-scope for a later PR to handle? What are the issues/work items tracking that later work? * Is there any other context that reviewers should consider? For example, other related issues/PRs, or any particularly tricky/subtle bits of implementation that need closer-than-normal review? --> #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [x] Addresses an existing issue: #1739 - [x] Ran `yarn fastpass` - [x] Added/updated relevant unit test(s) (and ran `yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). Check workflow guide at: `<rootDir>/docs/workflow.md` - [x] (UI changes only) Added screenshots/GIFs to description above - [x] (UI changes only) Verified usability with NVDA/JAWS
- Loading branch information
1 parent
10096c7
commit 1c8ff9b
Showing
26 changed files
with
568 additions
and
40 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
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
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,8 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { ReportExportServiceProvider } from 'report-export/report-export-service-provider'; | ||
import { CodePenReportExportService } from 'report-export/services/codepen-report-export-service'; | ||
|
||
export const ReportExportServiceProviderImpl = new ReportExportServiceProvider([ | ||
CodePenReportExportService, | ||
]); |
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,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { ExportFormat, ReportExportService } from 'report-export/types/report-export-service'; | ||
|
||
export class ReportExportServiceProvider { | ||
constructor(private readonly services: ReportExportService[]) {} | ||
|
||
public all(): ReportExportService[] { | ||
return this.services; | ||
} | ||
|
||
public forKey(key: ExportFormat): ReportExportService { | ||
return this.services.find(service => service.key === key); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/report-export/services/codepen-report-export-service.tsx
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,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import * as React from 'react'; | ||
|
||
import { | ||
ExportFormat, | ||
ExportFormProps, | ||
ReportExportService, | ||
} from 'report-export/types/report-export-service'; | ||
|
||
const CodePenReportExportServiceKey: ExportFormat = 'codepen'; | ||
|
||
class ExportForm extends React.Component<ExportFormProps> { | ||
private buttonRef: React.RefObject<HTMLButtonElement>; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.buttonRef = React.createRef(); | ||
} | ||
|
||
public componentDidMount(): void { | ||
if (this.buttonRef.current) { | ||
this.buttonRef.current.click(); | ||
this.props.onSubmit(); | ||
} | ||
} | ||
|
||
public render(): JSX.Element { | ||
return ( | ||
<form | ||
action="https://codepen.io/pen/define" | ||
method="POST" | ||
target="_blank" | ||
rel="noopener" | ||
style={{ visibility: 'hidden' }} | ||
> | ||
<input | ||
name="data" | ||
type="hidden" | ||
value={JSON.stringify({ | ||
title: this.props.fileName, | ||
description: this.props.description, | ||
html: this.props.html, | ||
editors: '100', // collapse CSS and JS editors | ||
})} | ||
/> | ||
<button type="submit" ref={this.buttonRef} /> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
export const CodePenReportExportService: ReportExportService = { | ||
key: CodePenReportExportServiceKey, | ||
displayName: 'CodePen', | ||
exportForm: ExportForm, | ||
}; |
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,18 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
export type ExportFormat = 'download' | 'codepen'; | ||
|
||
export type ExportFormProps = ExportProps & { onSubmit: () => void }; | ||
|
||
export interface ExportProps { | ||
html: string; | ||
fileName: string; | ||
description: string; | ||
} | ||
|
||
export interface ReportExportService { | ||
key: ExportFormat; | ||
displayName: string; | ||
exportForm: React.ComponentType<ExportFormProps> | null; | ||
} |
Oops, something went wrong.