mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** For #41031 # Details * Updates server-side error message about software installers to use "fleet" instead of "team". * Update front-end code that rewrites that error text 🤦 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. n/a ## Testing - [X] Added/updated automated tests - [X] QA'd all new/changed functionality manually - [X] Saw correct error banner when trying to add a VPP app that conflicted with an FMA <img width="741" height="67" alt="image" src="https://github.com/user-attachments/assets/d171097c-b165-45f8-bafb-fd6337c94cb9" /> - [X] Saw correct error banner when trying to add a script with the same contents as a another script <img width="765" height="60" alt="image" src="https://github.com/user-attachments/assets/db02b92a-942d-448d-9062-3fca49132a94" /> I haven't tested all the other cases but I think these two cover them; one uses the `CantAddSoftwareConflictMessage` constant on the server and one uses a hard-coded message. Everything else uses the constant. For unreleased bug fixes in a release candidate, one of: - [X] Confirmed that the fix is not expected to adversely impact load test results
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
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*/, "");
|
|
|
|
// New regex for "<package> already has an installer available for the <fleet> fleet."
|
|
const installerExistsRegex = /^(.+?) already.+the (.+?) fleet\./;
|
|
let match = cleaned.match(installerExistsRegex);
|
|
if (match) {
|
|
return (
|
|
<>
|
|
{ADD_SOFTWARE_ERROR_PREFIX} <b>{match[1]}</b> already has an installer
|
|
available for the <b>{match[2]}</b> fleet.{" "}
|
|
</>
|
|
);
|
|
}
|
|
|
|
// New regex for "SoftwareInstaller <package> already exists with fleet <fleet>."
|
|
// or "In-house app <package> already exists with fleet <fleet>."
|
|
const packageExistsRegex = /^(?:SoftwareInstaller|In-house app) "(.+?)" already.+ fleet "(.+?)"\./;
|
|
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> fleet.{" "}
|
|
</>
|
|
);
|
|
}
|
|
return null;
|
|
};
|