#1269 fixed routing to label after team change (#1500)

* #1269 fixed routing to label after team change

* #1269 added changelog

* #1269 better implementation

* #1269 fixed option defaults for typing
This commit is contained in:
Martavis Parker 2021-07-28 18:15:36 -07:00 committed by GitHub
parent da46ecc002
commit 1d6572488b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 24 deletions

View File

@ -0,0 +1 @@
* Fixed refreshing manage hosts table to include current label and query after changing a host's team.

View File

@ -46,7 +46,13 @@ describe("Kolide - API client (hosts)", () => {
Fleet.setBearerToken(bearerToken); Fleet.setBearerToken(bearerToken);
return Fleet.hosts return Fleet.hosts
.loadAll(page, perPage, selectedFilter, query, sortBy) .loadAll({
page,
perPage,
selectedLabel: selectedFilter,
globalFilter: query,
sortBy,
})
.then(() => { .then(() => {
expect(request.isDone()).toEqual(true); expect(request.isDone()).toEqual(true);
}); });
@ -61,9 +67,15 @@ describe("Kolide - API client (hosts)", () => {
}); });
Fleet.setBearerToken(bearerToken); Fleet.setBearerToken(bearerToken);
return Fleet.hosts.loadAll(2, 50, "labels/6").then(() => { return Fleet.hosts
expect(request.isDone()).toEqual(true); .loadAll({
}); page: 2,
perPage: 50,
selectedLabel: "labels/6",
})
.then(() => {
expect(request.isDone()).toEqual(true);
});
}); });
}); });
}); });

View File

@ -6,6 +6,14 @@ interface ISortOption {
direction: string; direction: string;
} }
interface IHostLoadOptions {
page: number;
perPage: number;
selectedLabel: string;
globalFilter: string;
sortBy: ISortOption[];
}
export default (client: any) => { export default (client: any) => {
return { return {
destroy: (host: IHost) => { destroy: (host: IHost) => {
@ -30,14 +38,13 @@ export default (client: any) => {
.authenticatedGet(endpoint) .authenticatedGet(endpoint)
.then((response: any) => response.host); .then((response: any) => response.host);
}, },
loadAll: ( loadAll: (options: IHostLoadOptions | undefined) => {
page = 0,
perPage = 100,
selected = "",
globalFilter = "",
sortBy: ISortOption[] = []
) => {
const { HOSTS, LABEL_HOSTS } = endpoints; const { HOSTS, LABEL_HOSTS } = endpoints;
const page = options?.page || 0;
const perPage = options?.perPage || 100;
const selectedLabel = options?.selectedLabel || "";
const globalFilter = options?.globalFilter || "";
const sortBy = options?.sortBy || [];
// TODO: add this query param logic to client class // TODO: add this query param logic to client class
const pagination = `page=${page}&per_page=${perPage}`; const pagination = `page=${page}&per_page=${perPage}`;
@ -57,20 +64,20 @@ export default (client: any) => {
let endpoint = ""; let endpoint = "";
const labelPrefix = "labels/"; const labelPrefix = "labels/";
if (selected.startsWith(labelPrefix)) { if (selectedLabel.startsWith(labelPrefix)) {
const lid = selected.substr(labelPrefix.length); const lid = selectedLabel.substr(labelPrefix.length);
endpoint = `${LABEL_HOSTS( endpoint = `${LABEL_HOSTS(
parseInt(lid, 10) parseInt(lid, 10)
)}?${pagination}${searchQuery}${orderKeyParam}${orderDirection}`; )}?${pagination}${searchQuery}${orderKeyParam}${orderDirection}`;
} else { } else {
let selectedFilter = ""; let selectedFilter = "";
if ( if (
selected === "new" || selectedLabel === "new" ||
selected === "online" || selectedLabel === "online" ||
selected === "offline" || selectedLabel === "offline" ||
selected === "mia" selectedLabel === "mia"
) { ) {
selectedFilter = `&status=${selected}`; selectedFilter = `&status=${selectedLabel}`;
} }
endpoint = `${HOSTS}?${pagination}${selectedFilter}${searchQuery}${orderKeyParam}${orderDirection}`; endpoint = `${HOSTS}?${pagination}${selectedFilter}${searchQuery}${orderKeyParam}${orderDirection}`;
} }

View File

@ -198,7 +198,13 @@ export class ManageHostsPage extends PureComponent {
this.setState({ searchQuery }); this.setState({ searchQuery });
dispatch( dispatch(
getHosts(pageIndex, pageSize, selectedFilter, searchQuery, sortBy) getHosts({
page: pageIndex,
perPage: pageSize,
selectedLabel: selectedFilter,
globalFilter: searchQuery,
sortBy,
})
); );
}; };
@ -309,7 +315,7 @@ export class ManageHostsPage extends PureComponent {
? `Hosts successfully removed from teams.` ? `Hosts successfully removed from teams.`
: `Hosts successfully transferred to ${team.name}.`; : `Hosts successfully transferred to ${team.name}.`;
dispatch(renderFlash("success", successMessage)); dispatch(renderFlash("success", successMessage));
dispatch(getHosts()); dispatch(getHosts({ selectedLabel: selectedFilter, searchQuery }));
}) })
.catch(() => { .catch(() => {
dispatch( dispatch(

View File

@ -66,15 +66,15 @@ export const getLabels = () => (dispatch) => {
dispatch(silentGetStatusLabelCounts); dispatch(silentGetStatusLabelCounts);
}; };
export const getHosts = ( export const getHosts = ({
page, page,
perPage, perPage,
selectedLabel, selectedLabel,
globalFilter, globalFilter,
sortBy sortBy,
) => (dispatch) => { }) => (dispatch) => {
dispatch( dispatch(
hostActions.loadAll(page, perPage, selectedLabel, globalFilter, sortBy) hostActions.loadAll({ page, perPage, selectedLabel, globalFilter, sortBy })
); );
}; };