2025-10-08 13:17:07 +00:00
import React from "react" ;
export const ADD_SOFTWARE_ERROR_PREFIX = "Couldn't add." ;
export const DEFAULT_ADD_SOFTWARE_ERROR_MESSAGE = ` ${ ADD_SOFTWARE_ERROR_PREFIX } Please try again. ` ;
export const REQUEST_TIMEOUT_ERROR_MESSAGE = ` ${ ADD_SOFTWARE_ERROR_PREFIX } Request timeout. Please make sure your server and load balancer timeout is long enough. ` ;
/ * *
* Ensures that a string ends with a period .
* If the string is empty or already ends with a period , it is returned unchanged .
* /
export const ensurePeriod = ( str : string ) = > {
if ( str && ! str . endsWith ( "." ) ) {
return ` ${ str } . ` ;
}
return str ;
} ;
/ * *
* Matches API messages after the fixed Couldn ' t add software . prefix ,
* and renders just the part about what is available for install .
* Returns a formatted React element if matched ; otherwise , returns null . * /
export const formatAlreadyAvailableInstallMessage = ( msg : string ) = > {
// Remove prefix (with or without trailing space)
const cleaned = msg . replace ( /^Couldn't add software\.?\s*/ , "" ) ;
2025-12-09 13:48:10 +00:00
// New regex for "<package> already has a package or app available for install on the <team> team."
const installerExistsRegex = /^(.+?) already.+on the (.+?) team\./ ;
let match = cleaned . match ( installerExistsRegex ) ;
2025-10-08 13:17:07 +00:00
if ( match ) {
return (
< >
{ ADD_SOFTWARE_ERROR_PREFIX } < b > { match [ 1 ] } < / b > already has a package or
app available for install on the < b > { match [ 2 ] } < / b > team . { " " }
< / >
) ;
}
2025-12-09 13:48:10 +00:00
// New regex for "SoftwareInstaller <package> already exists with team <team>."
const packageExistsRegex = /^SoftwareInstaller "(.+?)" already.+ team "(.+?)"\./ ;
match = cleaned . match ( packageExistsRegex ) ;
if ( match ) {
return (
< >
{ ADD_SOFTWARE_ERROR_PREFIX } < b > { match [ 1 ] } < / b > already has an installer
available for the < b > { match [ 2 ] } < / b > team . { " " }
< / >
) ;
}
2025-10-08 13:17:07 +00:00
return null ;
} ;