@@ -23,7 +23,12 @@ import {
2323import { TextEditor } from "~/components/code/TextEditor" ;
2424import { Button } from "~/components/primitives/Buttons" ;
2525import { cn } from "~/utils/cn" ;
26- import { ignorePathError , type IgnorePathLimits } from "~/v3/github" ;
26+ import {
27+ ignorePatternError ,
28+ tooManyIgnorePatterns ,
29+ type IgnoreKind ,
30+ type IgnorePatternLimits ,
31+ } from "~/v3/github" ;
2732
2833const FOLDED_LINES = 3 ;
2934const MAX_VISIBLE_LINES = 15 ;
@@ -38,9 +43,31 @@ class MatchedLineMarker extends GutterMarker {
3843const matchedLineMarker = new MatchedLineMarker ( ) ;
3944const matchedLine = Decoration . line ( { class : MATCH_CLASS } ) ;
4045
46+ const copy = {
47+ paths : {
48+ label : "Ignored paths" ,
49+ placeholder : "docs/**" ,
50+ empty : "No paths yet, so every push to a tracked branch deploys." ,
51+ testLabel : "Path to test" ,
52+ testPlaceholder : "apps/web/src/index.ts" ,
53+ test : "Test a path" ,
54+ closeTester : "Close the path tester" ,
55+ noMatch : "no path matches" ,
56+ } ,
57+ branches : {
58+ label : "Ignored branches" ,
59+ placeholder : "dependabot/**" ,
60+ empty : "No branches yet, so every pull request gets a preview." ,
61+ testLabel : "Branch to test" ,
62+ testPlaceholder : "dependabot/npm_and_yarn/react-19.0.0" ,
63+ test : "Test a branch" ,
64+ closeTester : "Close the branch tester" ,
65+ noMatch : "no branch matches" ,
66+ } ,
67+ } satisfies Record < IgnoreKind , unknown > ;
68+
4169const editorExtensions = [
4270 lintGutter ( ) ,
43- placeholder ( "docs/**" ) ,
4471 EditorView . theme ( {
4572 "&.cm-focused" : { outline : "none" } ,
4673 ".cm-line" : { transition : "background-color 150ms ease-out" } ,
@@ -54,26 +81,26 @@ const editorExtensions = [
5481type Line = { pattern : string ; start : number ; error ?: string ; valid : boolean } ;
5582type Heights = { content : number ; folded : number ; max : number } ;
5683
57- function analyze ( text : string , { maxPaths , maxLength } : IgnorePathLimits ) {
84+ function analyze ( kind : IgnoreKind , text : string , { maxPatterns , maxLength } : IgnorePatternLimits ) {
5885 let start = 0 ;
5986 const lines : Line [ ] = text . split ( "\n" ) . map ( ( line ) => {
6087 const pattern = line . trim ( ) ;
61- const error = pattern ? ignorePathError ( pattern , maxLength ) : undefined ;
88+ const error = pattern ? ignorePatternError ( kind , pattern , maxLength ) : undefined ;
6289 const parsed = { pattern, start, error, valid : pattern !== "" && ! error } ;
6390 start += line . length + 1 ;
6491 return parsed ;
6592 } ) ;
6693 const patterns = lines . flatMap ( ( { pattern } ) => ( pattern ? [ pattern ] : [ ] ) ) ;
6794 const errors = [
6895 ...lines . flatMap ( ( { error } , index ) => ( error ? [ `Line ${ index + 1 } : ${ error } ` ] : [ ] ) ) ,
69- ...( patterns . length > maxPaths ? [ `Add at most ${ maxPaths } paths.` ] : [ ] ) ,
96+ ...( patterns . length > maxPatterns ? [ tooManyIgnorePatterns ( kind , maxPatterns ) ] : [ ] ) ,
7097 ] ;
7198 return { lines, patterns, errors } ;
7299}
73100
74- function lintPaths ( limits : IgnorePathLimits ) {
101+ function lintPatterns ( kind : IgnoreKind , limits : IgnorePatternLimits ) {
75102 return ( view : EditorView ) : Diagnostic [ ] =>
76- analyze ( view . state . doc . toString ( ) , limits ) . lines . flatMap ( ( { error } , index ) => {
103+ analyze ( kind , view . state . doc . toString ( ) , limits ) . lines . flatMap ( ( { error } , index ) => {
77104 if ( ! error ) return [ ] ;
78105 const line = view . state . doc . line ( index + 1 ) ;
79106 return [ { from : line . from , to : line . to , severity : "error" , message : error } ] ;
@@ -112,15 +139,17 @@ function plural(count: number, word: string) {
112139 return `${ count } ${ word } ${ count === 1 ? "" : "s" } ` ;
113140}
114141
115- export function IgnoredPathsEditor ( {
142+ export function IgnoredPatternsEditor ( {
143+ kind,
116144 name,
117145 defaultPatterns,
118146 limits,
119147 onChange,
120148} : {
149+ kind : IgnoreKind ;
121150 name : string ;
122151 defaultPatterns : string [ ] ;
123- limits : IgnorePathLimits ;
152+ limits : IgnorePatternLimits ;
124153 onChange ?: ( patterns : string [ ] , valid : boolean ) => void ;
125154} ) {
126155 // TextEditor replaces the document whenever defaultValue changes.
@@ -130,21 +159,22 @@ export function IgnoredPathsEditor({
130159 const [ heights , setHeights ] = useState < Heights > ( ) ;
131160 const [ animating , setAnimating ] = useState ( false ) ;
132161 const [ testing , setTesting ] = useState ( false ) ;
133- const [ testPath , setTestPath ] = useState ( "" ) ;
162+ const [ testInput , setTestInput ] = useState ( "" ) ;
134163 const viewRef = useRef < EditorView > ( ) ;
135164 const scrollRef = useRef < HTMLDivElement > ( null ) ;
136165 const testButtonRef = useRef < HTMLButtonElement > ( null ) ;
137166 const errorsId = useId ( ) ;
138167
139- const { maxPaths, maxLength } = limits ;
168+ const { maxPatterns, maxLength } = limits ;
169+ const labels = copy [ kind ] ;
140170 const { lines, patterns, errors } = useMemo (
141- ( ) => analyze ( text , { maxPaths , maxLength } ) ,
142- [ text , maxPaths , maxLength ]
171+ ( ) => analyze ( kind , text , { maxPatterns , maxLength } ) ,
172+ [ kind , text , maxPatterns , maxLength ]
143173 ) ;
144- const path = testPath . trim ( ) ;
174+ const tested = testInput . trim ( ) ;
145175 const matchedIndex =
146- testing && path
147- ? lines . findIndex ( ( { pattern, valid } ) => valid && picomatch ( pattern , { dot : true } ) ( path ) )
176+ testing && tested
177+ ? lines . findIndex ( ( { pattern, valid } ) => valid && picomatch ( pattern , { dot : true } ) ( tested ) )
148178 : - 1 ;
149179 const canTest = lines . some ( ( { valid } ) => valid ) ;
150180 const canFold = lines . length > FOLDED_LINES ;
@@ -169,9 +199,10 @@ export function IgnoredPathsEditor({
169199 const extensions = useMemo (
170200 ( ) => [
171201 ...editorExtensions ,
172- linter ( lintPaths ( { maxPaths, maxLength } ) , { delay : 100 } ) ,
202+ placeholder ( labels . placeholder ) ,
203+ linter ( lintPatterns ( kind , { maxPatterns, maxLength } ) , { delay : 100 } ) ,
173204 EditorView . contentAttributes . of ( {
174- "aria-label" : "Ignored paths" ,
205+ "aria-label" : labels . label ,
175206 "aria-invalid" : String ( invalid ) ,
176207 ...( invalid ? { "aria-describedby" : errorsId } : { } ) ,
177208 } ) ,
@@ -182,16 +213,16 @@ export function IgnoredPathsEditor({
182213 ]
183214 : [ ] ) ,
184215 ] ,
185- [ maxPaths , maxLength , invalid , errorsId , matchedStart ]
216+ [ kind , labels , maxPatterns , maxLength , invalid , errorsId , matchedStart ]
186217 ) ;
187218
188219 const edit = useCallback (
189220 ( next : string ) => {
190221 setText ( next ) ;
191- const { patterns, errors } = analyze ( next , limits ) ;
222+ const { patterns, errors } = analyze ( kind , next , limits ) ;
192223 onChange ?.( patterns , errors . length === 0 ) ;
193224 } ,
194- [ limits , onChange ]
225+ [ kind , limits , onChange ]
195226 ) ;
196227
197228 const onUpdate = useCallback ( ( update : ViewUpdate ) => {
@@ -222,7 +253,7 @@ export function IgnoredPathsEditor({
222253
223254 const closeTester = ( ) => {
224255 setTesting ( false ) ;
225- setTestPath ( "" ) ;
256+ setTestInput ( "" ) ;
226257 testButtonRef . current ?. focus ( ) ;
227258 } ;
228259
@@ -284,18 +315,18 @@ export function IgnoredPathsEditor({
284315 < div className = "flex min-w-0 flex-1 items-center gap-2 duration-200 animate-in fade-in slide-in-from-right-2" >
285316 < input
286317 autoFocus
287- aria-label = "Path to test"
288- value = { testPath }
289- onChange = { ( event ) => setTestPath ( event . target . value ) }
318+ aria-label = { labels . testLabel }
319+ value = { testInput }
320+ onChange = { ( event ) => setTestInput ( event . target . value ) }
290321 onKeyDown = { onTesterKeyDown }
291- placeholder = "apps/web/src/index.ts"
322+ placeholder = { labels . testPlaceholder }
292323 className = "h-6 min-w-0 flex-1 border-none bg-transparent p-0 font-mono text-xs text-text-bright outline-none placeholder:text-text-dimmed focus:ring-0"
293324 />
294325 < span
295326 role = "status"
296327 className = "flex min-w-0 max-w-[60%] items-center gap-1.5 text-text-dimmed"
297328 >
298- { path && (
329+ { tested && (
299330 < >
300331 < VerdictBadge key = { verdict } verdict = { verdict } />
301332 < span className = "min-w-0 truncate" >
@@ -307,7 +338,7 @@ export function IgnoredPathsEditor({
307338 </ span >
308339 </ >
309340 ) : (
310- "no path matches"
341+ labels . noMatch
311342 ) }
312343 </ span >
313344 </ >
@@ -317,9 +348,7 @@ export function IgnoredPathsEditor({
317348 ) : errors . length > 0 ? (
318349 < span className = "truncate text-error" > { plural ( errors . length , "error" ) } </ span >
319350 ) : patterns . length === 0 ? (
320- < span className = "truncate text-text-dimmed" >
321- No paths yet, so every push to a tracked branch deploys.
322- </ span >
351+ < span className = "truncate text-text-dimmed" > { labels . empty } </ span >
323352 ) : null }
324353 </ div >
325354 { ( testing || canTest ) && (
@@ -330,8 +359,8 @@ export function IgnoredPathsEditor({
330359 LeadingIcon = { FlaskConicalIcon }
331360 leadingIconClassName = "text-indigo-400 transition-transform duration-200 group-hover/button:-rotate-12 light:text-indigo-600"
332361 className = { cn ( testing && "bg-indigo-500/15" ) }
333- tooltip = { testing ? "Close the path tester" : "Test a path" }
334- aria-label = { testing ? "Close the path tester" : "Test a path" }
362+ tooltip = { testing ? labels . closeTester : labels . test }
363+ aria-label = { testing ? labels . closeTester : labels . test }
335364 onClick = { ( ) => ( testing ? closeTester ( ) : setTesting ( true ) ) }
336365 />
337366 ) }
0 commit comments