mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Fleet UI: Various team users save inherited queries to current team (#14695)
This commit is contained in:
parent
06ae87c2cf
commit
66a982a9ae
6 changed files with 20 additions and 7 deletions
1
changes/14620-save-inherited-query
Normal file
1
changes/14620-save-inherited-query
Normal file
|
|
@ -0,0 +1 @@
|
|||
- Fix bug where save as new for an inherited query will correctly save on the currently selected team
|
||||
|
|
@ -341,6 +341,7 @@ const ManageQueriesPage = ({
|
|||
router={router}
|
||||
queryParams={queryParams}
|
||||
isInherited
|
||||
currentTeamId={currentTeamId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ interface IQueriesTableProps {
|
|||
inherited_page?: string;
|
||||
};
|
||||
isInherited?: boolean;
|
||||
currentTeamId?: number;
|
||||
}
|
||||
|
||||
const DEFAULT_SORT_DIRECTION = "asc";
|
||||
|
|
@ -96,6 +97,7 @@ const QueriesTable = ({
|
|||
router,
|
||||
queryParams,
|
||||
isInherited = false,
|
||||
currentTeamId,
|
||||
}: IQueriesTableProps): JSX.Element | null => {
|
||||
const { currentUser } = useContext(AppContext);
|
||||
|
||||
|
|
@ -277,8 +279,10 @@ const QueriesTable = ({
|
|||
};
|
||||
|
||||
const tableHeaders = useMemo(
|
||||
() => currentUser && generateTableHeaders({ currentUser, isInherited }),
|
||||
[currentUser, isInherited]
|
||||
() =>
|
||||
currentUser &&
|
||||
generateTableHeaders({ currentUser, isInherited, currentTeamId }),
|
||||
[currentUser, isInherited, currentTeamId]
|
||||
);
|
||||
|
||||
const searchable =
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ interface IDataColumn {
|
|||
interface IGenerateTableHeaders {
|
||||
currentUser: IUser;
|
||||
isInherited?: boolean;
|
||||
currentTeamId?: number;
|
||||
}
|
||||
|
||||
// NOTE: cellProps come from react-table
|
||||
|
|
@ -109,6 +110,7 @@ interface IGenerateTableHeaders {
|
|||
const generateTableHeaders = ({
|
||||
currentUser,
|
||||
isInherited = false,
|
||||
currentTeamId,
|
||||
}: IGenerateTableHeaders): IDataColumn[] => {
|
||||
const isOnlyObserver = permissionsUtils.isOnlyObserver(currentUser);
|
||||
|
||||
|
|
@ -154,7 +156,7 @@ const generateTableHeaders = ({
|
|||
}
|
||||
path={PATHS.QUERY(
|
||||
cellProps.row.original.id,
|
||||
cellProps.row.original.team_id ?? undefined
|
||||
cellProps.row.original.team_id ?? currentTeamId
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -49,12 +49,14 @@ const baseClass = "query-details-page";
|
|||
|
||||
const QueryDetailsPage = ({
|
||||
router,
|
||||
params: { id: paramsQueryId, team_id: paramsTeamId },
|
||||
params: { id: paramsQueryId },
|
||||
location,
|
||||
}: IQueryDetailsPageProps): JSX.Element => {
|
||||
const queryId = parseInt(paramsQueryId, 10);
|
||||
const queryParams = location.query;
|
||||
const teamId = parseInt(paramsTeamId, 10);
|
||||
const teamId = location.query.team_id
|
||||
? parseInt(location.query.team_id, 10)
|
||||
: undefined;
|
||||
|
||||
// Functions to avoid race conditions
|
||||
const serverSortBy: ISortOption[] = (() => {
|
||||
|
|
@ -77,6 +79,7 @@ const QueryDetailsPage = ({
|
|||
filteredQueriesPath,
|
||||
availableTeams,
|
||||
setCurrentTeam,
|
||||
currentTeam,
|
||||
} = useContext(AppContext);
|
||||
const {
|
||||
lastEditedQueryName,
|
||||
|
|
@ -198,7 +201,7 @@ const QueryDetailsPage = ({
|
|||
{canEditQuery && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
queryId && router.push(PATHS.EDIT_QUERY(queryId));
|
||||
queryId && router.push(PATHS.EDIT_QUERY(queryId, teamId));
|
||||
}}
|
||||
className={`${baseClass}__manage-automations button`}
|
||||
variant="brand"
|
||||
|
|
|
|||
|
|
@ -328,7 +328,9 @@ const EditQueryForm = ({
|
|||
})
|
||||
.then((response: { query: ISchedulableQuery }) => {
|
||||
setIsSaveAsNewLoading(false);
|
||||
router.push(PATHS.EDIT_QUERY(response.query.id));
|
||||
router.push(
|
||||
PATHS.QUERY(response.query.id, response.query.team_id ?? undefined)
|
||||
);
|
||||
renderFlash("success", `Successfully added query.`);
|
||||
})
|
||||
.catch((createError: { data: IApiError }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue