Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
CPAlejandro committed Apr 29, 2021
1 parent a92f99c commit 0040af6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
6 changes: 0 additions & 6 deletions public/controllers/agent/components/agents-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ export class AgentsTable extends Component {
};

addUpgradeStatus(agent) {
//console.log("Entramos en addUpgradeStatus con", agent);
const { managerVersion } = this.state;
return (
<CheckUpgrade
Expand Down Expand Up @@ -375,9 +374,7 @@ export class AgentsTable extends Component {

/* MULTISELECT TABLE */
onSelectionChange = selectedItems => {
console.log("En onSelectionChange obtenemos: ", selectedItems.length);
const { managerVersion, pageSize } = this.state;
// console.log("Entro en onSelectionChange", selectedItems);
selectedItems.forEach(item => {
if (item.version && item.version !== '-' && !ActionAgents.compareVersions('v'+managerVersion, item.version)) {
item.outdated = true;
Expand All @@ -393,7 +390,6 @@ export class AgentsTable extends Component {

renderUpgradeButton() {
const { selectedItems } = this.state;
// console.log("Upgrading es: ", selectedItems);

if (
selectedItems.length === 0 ||
Expand Down Expand Up @@ -434,7 +430,6 @@ export class AgentsTable extends Component {

renderUpgradeButtonAll() {
const { selectedItems, avaibleAgents, managerVersion } = this.state;
// console.log("En renderUpgradeButtonAll: ", selectedItems, avaibleAgents);
if (
selectedItems.length > 0 &&
avaibleAgents &&
Expand Down Expand Up @@ -463,7 +458,6 @@ export class AgentsTable extends Component {
renderRestartButton() {
const { selectedItems } = this.state;

// console.log("Al entrar en renderRestartButton, state es: ", selectedItems.length, "y :", selectedItems);
if (
selectedItems.length === 0 ||
selectedItems.filter(item => item.status === 'active').length === 0
Expand Down
59 changes: 29 additions & 30 deletions public/react-services/action-agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,40 @@ export class ActionAgents {
});
};

/**
/**
* Make the action (upgrade, restart or delete) to a specific group of agents
* @param {Object} filters
*/
static async getAllAgents(filters){
static async getAllAgents(filters){
try{

const params = filters.q ? {q: filters.q, limit: 500} : { limit: 500 };
const output = await WzRequest.apiReq('GET', `/agents`, {params: params});
const totalItems = (((output || {}).data || {}).data || {}).total_affected_items;
let itemsArray = [];
if (totalItems && output.data && output.data.data && totalItems > 500) {
params.offset = 0;
itemsArray.push(...output.data.data.affected_items);
while (itemsArray.length < totalItems && params.offset < totalItems) {
params.offset += params.limit;
const tmpData = await WzRequest.apiReq(
'GET',
`/agents`,
{ params: params },
);
itemsArray.push(...tmpData.data.data.affected_items);
}
const allowedAgents = itemsArray;
return allowedAgents;
}
else{
const allowedAgents = output.data.data.affected_items;
return allowedAgents;
}
}catch(error) {
getToasts().addError(error, {title: `Error getting user authorized agents`});
return Promise.reject();
}
}
const output = await WzRequest.apiReq('GET', `/agents`, {params: params});
const totalItems = (((output || {}).data || {}).data || {}).total_affected_items;
let itemsArray = [];
if (totalItems && output.data && output.data.data && totalItems > 500) {
params.offset = 0;
itemsArray.push(...output.data.data.affected_items);
while (itemsArray.length < totalItems && params.offset < totalItems) {
params.offset += params.limit;
const tmpData = await WzRequest.apiReq(
'GET',
`/agents`,
{ params: params },
);
itemsArray.push(...tmpData.data.data.affected_items);
}
const allowedAgents = itemsArray;
return allowedAgents;
}
else{
const allowedAgents = output.data.data.affected_items;
return allowedAgents;
}
}catch(error) {
getToasts().addError(error, {title: `Error getting user authorized agents`});
return Promise.reject();
}
}

/**
* Make a string of all agents, and do some calls according to the maximum agents permitted in this call
Expand Down

0 comments on commit 0040af6

Please sign in to comment.