mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
* #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:
parent
da46ecc002
commit
1d6572488b
1
changes/1269-refresh-matching-hosts
Normal file
1
changes/1269-refresh-matching-hosts
Normal file
@ -0,0 +1 @@
|
||||
* Fixed refreshing manage hosts table to include current label and query after changing a host's team.
|
@ -46,7 +46,13 @@ describe("Kolide - API client (hosts)", () => {
|
||||
|
||||
Fleet.setBearerToken(bearerToken);
|
||||
return Fleet.hosts
|
||||
.loadAll(page, perPage, selectedFilter, query, sortBy)
|
||||
.loadAll({
|
||||
page,
|
||||
perPage,
|
||||
selectedLabel: selectedFilter,
|
||||
globalFilter: query,
|
||||
sortBy,
|
||||
})
|
||||
.then(() => {
|
||||
expect(request.isDone()).toEqual(true);
|
||||
});
|
||||
@ -61,9 +67,15 @@ describe("Kolide - API client (hosts)", () => {
|
||||
});
|
||||
|
||||
Fleet.setBearerToken(bearerToken);
|
||||
return Fleet.hosts.loadAll(2, 50, "labels/6").then(() => {
|
||||
expect(request.isDone()).toEqual(true);
|
||||
});
|
||||
return Fleet.hosts
|
||||
.loadAll({
|
||||
page: 2,
|
||||
perPage: 50,
|
||||
selectedLabel: "labels/6",
|
||||
})
|
||||
.then(() => {
|
||||
expect(request.isDone()).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,6 +6,14 @@ interface ISortOption {
|
||||
direction: string;
|
||||
}
|
||||
|
||||
interface IHostLoadOptions {
|
||||
page: number;
|
||||
perPage: number;
|
||||
selectedLabel: string;
|
||||
globalFilter: string;
|
||||
sortBy: ISortOption[];
|
||||
}
|
||||
|
||||
export default (client: any) => {
|
||||
return {
|
||||
destroy: (host: IHost) => {
|
||||
@ -30,14 +38,13 @@ export default (client: any) => {
|
||||
.authenticatedGet(endpoint)
|
||||
.then((response: any) => response.host);
|
||||
},
|
||||
loadAll: (
|
||||
page = 0,
|
||||
perPage = 100,
|
||||
selected = "",
|
||||
globalFilter = "",
|
||||
sortBy: ISortOption[] = []
|
||||
) => {
|
||||
loadAll: (options: IHostLoadOptions | undefined) => {
|
||||
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
|
||||
const pagination = `page=${page}&per_page=${perPage}`;
|
||||
@ -57,20 +64,20 @@ export default (client: any) => {
|
||||
|
||||
let endpoint = "";
|
||||
const labelPrefix = "labels/";
|
||||
if (selected.startsWith(labelPrefix)) {
|
||||
const lid = selected.substr(labelPrefix.length);
|
||||
if (selectedLabel.startsWith(labelPrefix)) {
|
||||
const lid = selectedLabel.substr(labelPrefix.length);
|
||||
endpoint = `${LABEL_HOSTS(
|
||||
parseInt(lid, 10)
|
||||
)}?${pagination}${searchQuery}${orderKeyParam}${orderDirection}`;
|
||||
} else {
|
||||
let selectedFilter = "";
|
||||
if (
|
||||
selected === "new" ||
|
||||
selected === "online" ||
|
||||
selected === "offline" ||
|
||||
selected === "mia"
|
||||
selectedLabel === "new" ||
|
||||
selectedLabel === "online" ||
|
||||
selectedLabel === "offline" ||
|
||||
selectedLabel === "mia"
|
||||
) {
|
||||
selectedFilter = `&status=${selected}`;
|
||||
selectedFilter = `&status=${selectedLabel}`;
|
||||
}
|
||||
endpoint = `${HOSTS}?${pagination}${selectedFilter}${searchQuery}${orderKeyParam}${orderDirection}`;
|
||||
}
|
||||
|
@ -198,7 +198,13 @@ export class ManageHostsPage extends PureComponent {
|
||||
this.setState({ searchQuery });
|
||||
|
||||
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 transferred to ${team.name}.`;
|
||||
dispatch(renderFlash("success", successMessage));
|
||||
dispatch(getHosts());
|
||||
dispatch(getHosts({ selectedLabel: selectedFilter, searchQuery }));
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch(
|
||||
|
@ -66,15 +66,15 @@ export const getLabels = () => (dispatch) => {
|
||||
dispatch(silentGetStatusLabelCounts);
|
||||
};
|
||||
|
||||
export const getHosts = (
|
||||
export const getHosts = ({
|
||||
page,
|
||||
perPage,
|
||||
selectedLabel,
|
||||
globalFilter,
|
||||
sortBy
|
||||
) => (dispatch) => {
|
||||
sortBy,
|
||||
}) => (dispatch) => {
|
||||
dispatch(
|
||||
hostActions.loadAll(page, perPage, selectedLabel, globalFilter, sortBy)
|
||||
hostActions.loadAll({ page, perPage, selectedLabel, globalFilter, sortBy })
|
||||
);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user