fleet/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareAppStore/helpers.tsx
Scott Gress 93c75cf1b2
Fix software group dropdown w/ fleet_id (#40079)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40077 

# Details

Fixes an unreleased bug where rewriting the location with `fleet_id` in
the string would not properly set the current team in the useTeamParam
hook. This is because we haven't fully switched over to `fleet_id`
internally yet, so we still need to check for `team_id` until we do.

Also updated a few lingering instances of "team" in the user-facing
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, unreleased bug

## Testing

- [ ] Added/updated automated tests
no tests to speak of
- [X] QA'd all new/changed functionality manually
On main branch, was able to reproduce the issue where selecting an
option from the "All software" dropdown on the Software page caused the
selected fleet to be reset. On this branch, the selected fleet was
maintained after making a selection.

For unreleased bug fixes in a release candidate, one of:

- [X] Confirmed that the fix is not expected to adversely impact load
test results
2026-02-18 17:53:00 -06:00

59 lines
1.6 KiB
TypeScript

import { ReactElement } from "react";
import { getErrorReason } from "interfaces/errors";
import { IMdmVppToken } from "interfaces/mdm";
import {
ADD_SOFTWARE_ERROR_PREFIX,
DEFAULT_ADD_SOFTWARE_ERROR_MESSAGE,
ensurePeriod,
formatAlreadyAvailableInstallMessage,
} from "../helpers";
/**
* Checks if the given team has an available VPP token (either a token
* that's associated with the team, or a token that's available to "All
* teams")
*/
export const teamHasVPPToken = (
currentTeamId: number,
tokens?: IMdmVppToken[]
) => {
if (!tokens || tokens.length === 0) {
return false;
}
return tokens.some((token) => {
// if we've got a non-null, empty array it means the token is available for
// "All teams"
if (token.teams?.length === 0) {
return true;
}
return token.teams?.some((team) => team.team_id === currentTeamId);
});
};
// eslint-disable-next-line import/prefer-default-export
export const getErrorMessage = (e: unknown): string | ReactElement => {
const reason = getErrorReason(e);
// software is already available for install
if (reason.toLowerCase().includes("already")) {
const alreadyAvailableMessage = formatAlreadyAvailableInstallMessage(
reason
);
if (alreadyAvailableMessage) {
return alreadyAvailableMessage;
}
if (reason.includes("VPPApp")) {
return `${ADD_SOFTWARE_ERROR_PREFIX} The software is already available to install in this fleet.`;
}
}
if (reason) {
return `${ADD_SOFTWARE_ERROR_PREFIX} ${ensurePeriod(reason)}`;
}
return DEFAULT_ADD_SOFTWARE_ERROR_MESSAGE;
};