-
Notifications
You must be signed in to change notification settings - Fork 680
Report a crate with a form #9496
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,19 @@ | ||
| <button | ||
| type="button" | ||
| ...attributes | ||
| {{on "click" (fn this.toggleDialog true)}} | ||
| > | ||
| {{ @text }} | ||
| </button> | ||
|
|
||
| <div | ||
| local-class="dialog {{ if this.isOpen 'open' }}" | ||
| role="dialog" | ||
| aria-label="dialog" | ||
| > | ||
| {{#if this.isOpen}} | ||
| <div local-class="dialog__content" data-test-dialog-content> | ||
| {{yield this.toggleDialog this.isOpen}} | ||
| </div> | ||
| {{/if}} | ||
| </div> |
This file contains hidden or 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,11 @@ | ||
| import { action } from '@ember/object'; | ||
| import Component from '@glimmer/component'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
|
|
||
| export default class ButtonWithConfirmationDialog extends Component { | ||
| @tracked isOpen = false; | ||
|
|
||
| @action toggleDialog(state) { | ||
| this.isOpen = state === undefined ? !this.isOpen : !!state; | ||
| } | ||
| } |
This file contains hidden or 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,24 @@ | ||
| .dialog { | ||
| inset: 0px; | ||
| overflow-y: auto; | ||
| display: flex; | ||
| justify-content: center; | ||
| z-index: 20; | ||
| transition: all var(--transition-fast) ease-in; | ||
| opacity: 0; | ||
|
|
||
| &.open { | ||
| position: fixed; | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| .dialog__content { | ||
| --shadow: 0 25px 50px light-dark(hsla(51, 50%, 44%, 0.35), #232321); | ||
|
|
||
| height: min-content; | ||
| border-radius: var(--space-3xs); | ||
| box-shadow: var(--shadow); | ||
| outline: 1px solid var(--gray-border); | ||
| margin-top: 12.5vh; | ||
| } |
This file contains hidden or 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,66 @@ | ||
| <form local-class="report-form" {{on "submit" (prevent-default this.submit)}}> | ||
| <h3>Report Crate "{{@crate}}"</h3> | ||
|
|
||
| <fieldset local-class="form-group" data-test-reasons-group> | ||
| <div local-class="form-group-name">Reasons</div> | ||
| <ul role="list" local-class="reasons-list {{if this.reasonsInvalid "invalid"}}"> | ||
| {{#each this.reasons as |option|}} | ||
| <li> | ||
| <label data-test-reason={{ option.reason }}> | ||
| <Input | ||
| @type="checkbox" | ||
| @checked={{this.isReasonSelected option.reason}} | ||
| {{on "change" (fn this.toggleReason option.reason)}} | ||
| /> | ||
| {{option.description}} | ||
| </label> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| {{#if this.reasonsInvalid}} | ||
| <div local-class="form-group-error" data-test-error> | ||
| Please choose reasons to report. | ||
| </div> | ||
| {{/if}} | ||
| </fieldset> | ||
|
|
||
| <fieldset local-class="form-group" data-test-detail-group> | ||
| {{#let (unique-id) as |id|}} | ||
| <label for={{id}} local-class="form-group-name">Detail</label> | ||
| <textarea | ||
| id={{id}} | ||
| local-class="detail {{if this.detailInvalid "invalid"}}" | ||
| aria-required={{if this.detailInvalid "true" "false" }} | ||
| aria-invalid={{if this.detailInvalid "true" "false"}} | ||
| rows="5" | ||
| data-test-detail | ||
| {{on "change" this.updateDetail}} | ||
| {{on "input" this.resetDetailValidation}} | ||
| /> | ||
| {{#if this.detailInvalid}} | ||
| <div local-class="form-group-error" data-test-error> | ||
| Please provide some detail. | ||
| </div> | ||
| {{/if}} | ||
| {{/let}} | ||
| </fieldset> | ||
|
|
||
| <div local-class="buttons"> | ||
| <button | ||
| type="button" | ||
| local-class="cancel-button" | ||
| data-test-cancel | ||
| {{on "click" this.cancel}} | ||
| > | ||
| Cancel | ||
| </button> | ||
|
|
||
| <button | ||
| type="submit" | ||
| local-class="report-button" | ||
| data-test-report | ||
| > | ||
| Report | ||
| </button> | ||
| </div> | ||
| </form> |
This file contains hidden or 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,105 @@ | ||
| import { action } from '@ember/object'; | ||
| import Component from '@glimmer/component'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
|
|
||
| export default class CrateReportForm extends Component { | ||
| @tracked selectedReasons = []; | ||
| @tracked detail = ''; | ||
| @tracked reasonsInvalid; | ||
| @tracked detailInvalid; | ||
|
|
||
| reasons = [ | ||
| { | ||
| reason: 'spam', | ||
| description: 'it contains spam', | ||
| }, | ||
| { | ||
| reason: 'name-squatting', | ||
| description: 'it is name-squatting (reserving a crate name without content)', | ||
| }, | ||
| { | ||
| reason: 'abuse', | ||
| description: 'it is abusive or otherwise harmful', | ||
| }, | ||
| { | ||
| reason: 'security', | ||
| description: 'it contains a vulnerability (please try to contact the crate author first)', | ||
| }, | ||
| { | ||
| reason: 'other', | ||
| description: 'it is violating the usage policy in some other way (please specify below)', | ||
| }, | ||
| ]; | ||
|
|
||
| constructor() { | ||
| super(...arguments); | ||
| this.reset(); | ||
| } | ||
|
|
||
| reset() { | ||
| this.reasonsInvalid = false; | ||
| this.detailInvalid = false; | ||
| } | ||
|
|
||
| validate() { | ||
| this.reasonsInvalid = this.selectedReasons.length === 0; | ||
| this.detailInvalid = this.selectedReasons.includes('other') && !this.detail?.trim(); | ||
| return !this.reasonsInvalid && !this.detailInvalid; | ||
| } | ||
|
|
||
| @action resetDetailValidation() { | ||
| this.detailInvalid = false; | ||
| } | ||
|
|
||
| @action isReasonSelected(reason) { | ||
| return this.selectedReasons.includes(reason); | ||
| } | ||
|
|
||
| @action toggleReason(reason) { | ||
| this.selectedReasons = this.selectedReasons.includes(reason) | ||
| ? this.selectedReasons.filter(it => it !== reason) | ||
| : [...this.selectedReasons, reason]; | ||
| this.reasonsInvalid = false; | ||
| } | ||
|
|
||
| @action updateDetail(event) { | ||
| let { value } = event?.target ?? {}; | ||
| this.detail = value ?? ''; | ||
| } | ||
|
|
||
| @action cancel() { | ||
| this.args.close?.(); | ||
| } | ||
|
|
||
| @action submit() { | ||
| if (!this.validate()) { | ||
| return; | ||
| } | ||
|
|
||
| let mailto = this.composeMail(); | ||
| window.open(mailto, '_self'); | ||
| this.args.close?.(); | ||
| } | ||
|
|
||
| composeMail() { | ||
| let name = this.args.crate ?? ''; | ||
| let reasons = this.reasons | ||
| .map(({ reason, description }) => { | ||
| let selected = this.isReasonSelected(reason); | ||
| return `${selected ? '- [x]' : '- [ ]'} ${description}`; | ||
| }) | ||
| .join('\n'); | ||
| let body = `I'm reporting the https://crates.io/crates/${name} crate because: | ||
|
|
||
| ${reasons} | ||
|
|
||
| Additional details: | ||
|
|
||
| ${this.detail} | ||
| `; | ||
| let subject = `The "${name}" crate`; | ||
| let address = 'help@crates.io'; | ||
| let mailto = `mailto:${address}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; | ||
| return mailto; | ||
| } | ||
| } |
This file contains hidden or 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,69 @@ | ||
| .report-form { | ||
| background-color: var(--main-bg); | ||
| padding: 0.5rem 1rem; | ||
| } | ||
|
|
||
| .form-group { | ||
| border: none; | ||
| margin: 0; | ||
| padding: 0; | ||
|
|
||
| & + & { | ||
| margin-top: 1rem; | ||
| } | ||
| } | ||
|
|
||
| .form-group-name { | ||
| composes: form-group-name from '../styles/settings/tokens/new.module.css'; | ||
| } | ||
|
|
||
| .reasons-list { | ||
| composes: scopes-list from '../styles/settings/tokens/new.module.css'; | ||
| label { | ||
| flex-wrap: nowrap; | ||
| } | ||
| input { | ||
| align-self: center; | ||
| } | ||
| } | ||
|
|
||
| .detail { | ||
| border: 1px solid var(--gray-border); | ||
| border-radius: var(--space-3xs); | ||
| resize: vertical; | ||
| width: 100%; | ||
|
|
||
| &.invalid { | ||
| background: light-dark(#fff2f2, #170808); | ||
| border-color: red; | ||
| } | ||
| } | ||
|
|
||
| .form-group-error { | ||
| composes: form-group-error from '../styles/settings/tokens/new.module.css'; | ||
| } | ||
|
|
||
| .buttons { | ||
| composes: buttons from '../styles/settings/tokens/new.module.css'; | ||
| justify-content: end; | ||
| gap: 2rem; | ||
| } | ||
|
|
||
| .button { | ||
| &:focus { | ||
| outline: 1px solid var(--bg-color-top-dark); | ||
| outline-offset: 2px; | ||
| } | ||
| } | ||
|
|
||
| .report-button { | ||
| composes: button; | ||
| composes: button small from '../styles/shared/buttons.module.css'; | ||
| border-radius: var(--space-3xs); | ||
| } | ||
|
|
||
| .cancel-button { | ||
| composes: button; | ||
| composes: tan-button small from '../styles/shared/buttons.module.css'; | ||
| border-radius: var(--space-3xs); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.