Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add report an issue button #616

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/assets/scss/components/playground-configuration.scss
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@
}
}

.report-issue-btn {
width: 100%;
margin-top: 20px;
}

.playground__config-options__section--rules {
font-size: 0.875rem;
}
Expand Down
1 change: 1 addition & 0 deletions src/playground/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const App = () => {
data-open={isConfigHidden ? true : showConfigMenu}
>
<Configuration
errors={messages}
initialOptions={fillOptionsDefaults(
getDefaultOptions(),
)}
Expand Down
7 changes: 6 additions & 1 deletion src/playground/components/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function Configuration({
initialOptions,
rulesMeta,
eslintVersion,
errors,
onUpdate,
options,
ruleNames,
Expand Down Expand Up @@ -232,7 +233,11 @@ export default function Configuration({
return (
<div className="playground__config-options__sections">
<div className="playground__config-options__section">
<ShareURL url={window.location} />
<ShareURL
errors={errors}
url={window.location}
config={configFileContent}
/>
</div>
<div className="playground__config-options__section">
<button
Expand Down
48 changes: 46 additions & 2 deletions src/playground/components/ShareURL.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useState } from "react";

export default function ShareURL({ url }) {
const getTemplate = code => `\`\`\`js
${code}
\`\`\``;

export default function ShareURL({ url, errors, config }) {
const [isDataCopied, setIsDataCopied] = useState(false);
const [showShareURL, setShowShareURL] = useState(false);

Expand All @@ -10,7 +14,7 @@ export default function ShareURL({ url }) {
className="playground-toggle c-btn c-btn--ghost"
onClick={() => setShowShareURL(currentValue => !currentValue)}
>
<h2 data-config-section-title>Share URL</h2>
<h2 data-config-section-title>Share</h2>
<svg
height="20"
width="20"
Expand Down Expand Up @@ -89,6 +93,46 @@ export default function ShareURL({ url }) {
</span>
)}
</div>

<button
onClick={() => {
const reportUrl = new URL(
"https://github.com/eslint/eslint/issues/new",
);
const params = {
labels: "bug,repro:yes",
template: "bug-report.yml",
"repro-url": window.location.href,
"lint-output": errors
.map(
({ line, column, message, ruleId }) =>
`${line}:${column} ${message} (${ruleId})`,
)
.join("\n"),
description: getTemplate(config),
};

Object.entries(params).forEach(([key, value]) => {
reportUrl.searchParams.append(key, value);
});

if (reportUrl.search.length > 8148) {
reportUrl.searchParams.set(
"description",
"<!-- The configuration has been saved to clipboard. Please paste it here 👇🏻 -->",
);

navigator?.clipboard.writeText(
getTemplate(config),
);
}

window.open(reportUrl, "_blank");
}}
className="c-btn c-btn--secondary report-issue-btn"
>
Report an issue
</button>
</div>
)}
</div>
Expand Down
Loading