Fix issue saving labels (#30126)

# Details 
This PR fixes an issue where the user is redirected to a 500 error page
after saving a new label if they were on the All Teams host page before
creating the label. The issue was due to the redirect having
`team_id=-1` in it, and the fix is to detect that All Teams is selected
and, if so, not set `team_id` in the URL at all.

# Checklist
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [X] Manual QA for all new/changed functionality
- [X] For unreleased bug fixes in a release candidate, confirmed that
the fix is not expected to adversely impact load test results or alerted
the release DRI if additional load testing is needed.

# Testing

Tested adding a new and dynamic label from All Teams, No team and a
custom team. Vids below for "All Team":

Before:

![30036-before](https://github.com/user-attachments/assets/f958f31d-9b8d-4a61-8b3d-8d55590628fe)

After:

![30036-after](https://github.com/user-attachments/assets/0b424ed7-9bab-45cd-b4e5-2a6ae4a1309a)
This commit is contained in:
Scott Gress 2025-06-19 11:17:20 -05:00 committed by GitHub
parent 79d5e605ed
commit 7549defa28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import { AppContext } from "context/app";
import { NotificationContext } from "context/notification";
import { getPathWithQueryParams } from "utilities/url";
import { IApiError } from "interfaces/errors";
import { API_ALL_TEAMS_ID, APP_CONTEXT_ALL_TEAMS_ID } from "interfaces/team";
import DynamicLabelForm from "pages/labels/components/DynamicLabelForm";
import { IDynamicLabelFormData } from "pages/labels/components/DynamicLabelForm/DynamicLabelForm";
@ -38,7 +39,10 @@ const DynamicLabel = ({
.then((res) => {
router.push(
getPathWithQueryParams(PATHS.MANAGE_HOSTS_LABEL(res.label.id), {
team_id: currentTeam?.id,
team_id:
currentTeam?.id === APP_CONTEXT_ALL_TEAMS_ID
? API_ALL_TEAMS_ID
: currentTeam?.id,
})
);
renderFlash("success", "Label added successfully.");

View file

@ -7,6 +7,7 @@ import { AppContext } from "context/app";
import { NotificationContext } from "context/notification";
import { getPathWithQueryParams } from "utilities/url";
import { IApiError } from "interfaces/errors";
import { API_ALL_TEAMS_ID, APP_CONTEXT_ALL_TEAMS_ID } from "interfaces/team";
import ManualLabelForm from "pages/labels/components/ManualLabelForm";
import { IManualLabelFormData } from "pages/labels/components/ManualLabelForm/ManualLabelForm";
@ -29,7 +30,10 @@ const ManualLabel = ({ router }: IManualLabelProps) => {
.then((res) => {
router.push(
getPathWithQueryParams(PATHS.MANAGE_HOSTS_LABEL(res.label.id), {
team_id: currentTeam?.id,
team_id:
currentTeam?.id === APP_CONTEXT_ALL_TEAMS_ID
? API_ALL_TEAMS_ID
: currentTeam?.id,
})
);
renderFlash("success", "Label added successfully.");