File tree Expand file tree Collapse file tree 5 files changed +37
-28
lines changed
controllers/settings/tokens
templates/settings/tokens Expand file tree Collapse file tree 5 files changed +37
-28
lines changed Original file line number Diff line number Diff line change @@ -14,19 +14,19 @@ import or from 'ember-truth-helpers/helpers/or';
1414
1515import CopyButton from ' crates-io/components/copy-button' ;
1616import LoadingSpinner from ' crates-io/components/loading-spinner' ;
17+ import PatternDescription from ' crates-io/components/token-scopes/pattern-description' ;
1718import Tooltip from ' crates-io/components/tooltip' ;
1819import dateFormatDistanceToNow from ' crates-io/helpers/date-format-distance-to-now' ;
1920import isClipboardSupported from ' crates-io/helpers/is-clipboard-supported' ;
2021
21- import { patternDescription , scopeDescription } from ' ../../utils/token-scopes' ;
22+ import { scopeDescription } from ' ../../utils/token-scopes' ;
2223
2324export default class ApiTokens extends Component {
2425 @service store;
2526 @service notifications;
2627 @service router;
2728
2829 scopeDescription = scopeDescription;
29- patternDescription = patternDescription;
3030
3131 get sortedTokens () {
3232 return this .args .tokens
@@ -136,7 +136,7 @@ export default class ApiTokens extends Component {
136136
137137 {{#each ( this.listToParts token.crate_scopes ) as | part | ~}}
138138 {{#if ( eq part.type ' element' ) }}
139- <strong >{{part.value }} <Tooltip @ text ={{this .patternDescription part.value }} /></strong >
139+ <strong >{{part.value }} <Tooltip >< PatternDescription @ pattern ={{part.value }} /></ Tooltip ></strong >
140140 {{~else ~}}
141141 {{part.value }}
142142 {{/if }}
Original file line number Diff line number Diff line change 1+ import Component from ' @glimmer/component' ;
2+
3+ import { eq } from ' ember-truth-helpers' ;
4+
5+ export default class PatternDescription extends Component {
6+ get prefix () {
7+ if (this .args .pattern .endsWith (' *' )) {
8+ return this .args .pattern .slice (0 , - 1 );
9+ }
10+ }
11+
12+ <template >
13+ {{#if ( eq @ pattern ' *' ) }}
14+ Matches all crates on crates.io
15+ {{else if this . prefix }}
16+ Matches all crates starting with
17+ <strong >{{this .prefix }} </strong >
18+ {{else }}
19+ Matches only the
20+ <strong >{{@ pattern }} </strong >
21+ crate
22+ {{/if }}
23+ </template >
24+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { tracked } from '@glimmer/tracking';
66import { task } from 'ember-concurrency' ;
77import { TrackedArray } from 'tracked-built-ins' ;
88
9- import { patternDescription , scopeDescription } from '../../../utils/token-scopes' ;
9+ import { scopeDescription } from '../../../utils/token-scopes' ;
1010
1111export default class NewTokenController extends Controller {
1212 @service notifications ;
@@ -157,16 +157,6 @@ class CratePattern {
157157 return this . pattern . endsWith ( '*' ) ;
158158 }
159159
160- get description ( ) {
161- if ( ! this . pattern ) {
162- return 'Please enter a crate name pattern' ;
163- } else if ( this . isValid ) {
164- return patternDescription ( this . pattern ) ;
165- } else {
166- return 'Invalid crate name pattern' ;
167- }
168- }
169-
170160 @action resetValidation ( ) {
171161 this . showAsInvalid = false ;
172162 }
Original file line number Diff line number Diff line change @@ -7,9 +7,10 @@ import autoFocus from '@zestia/ember-auto-focus/modifiers/auto-focus';
77import perform from ' ember-concurrency/helpers/perform' ;
88import preventDefault from ' ember-event-helpers/helpers/prevent-default' ;
99import svgJar from ' ember-svg-jar/helpers/svg-jar' ;
10- import eq from ' ember-truth-helpers/helpers/eq ' ;
10+ import { eq , not } from ' ember-truth-helpers' ;
1111
1212import LoadingSpinner from ' crates-io/components/loading-spinner' ;
13+ import PatternDescription from ' crates-io/components/token-scopes/pattern-description' ;
1314
1415<template >
1516 <h2 >New API Token</h2 >
@@ -152,7 +153,13 @@ import LoadingSpinner from 'crates-io/components/loading-spinner';
152153 />
153154
154155 <span class =' pattern-description' data-test-description >
155- {{pattern.description }}
156+ {{#if ( not pattern.pattern ) }}
157+ Please enter a crate name pattern
158+ {{else if pattern.isValid }}
159+ <PatternDescription @ pattern ={{pattern.pattern }} />
160+ {{else }}
161+ Invalid crate name pattern
162+ {{/if }}
156163 </span >
157164 </div >
158165
Original file line number Diff line number Diff line change 1- import { htmlSafe } from '@ember/template' ;
2-
31const DESCRIPTIONS = {
42 'change-owners' : 'Invite new crate owners or remove existing ones' ,
53 'publish-new' : 'Publish new crates' ,
@@ -10,13 +8,3 @@ const DESCRIPTIONS = {
108export function scopeDescription ( scope ) {
119 return DESCRIPTIONS [ scope ] ;
1210}
13-
14- export function patternDescription ( pattern ) {
15- if ( pattern === '*' ) {
16- return 'Matches all crates on crates.io' ;
17- } else if ( pattern . endsWith ( '*' ) ) {
18- return htmlSafe ( `Matches all crates starting with <strong>${ pattern . slice ( 0 , - 1 ) } </strong>` ) ;
19- } else {
20- return htmlSafe ( `Matches only the <strong>${ pattern } </strong> crate` ) ;
21- }
22- }
You can’t perform that action at this time.
0 commit comments