Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bulk assignment #21

Merged
merged 91 commits into from
Jun 8, 2023
Merged

Feature/bulk assignment #21

merged 91 commits into from
Jun 8, 2023

Conversation

petrKavulok
Copy link
Contributor

@petrKavulok petrKavulok commented Feb 26, 2023

related MR TeskaLabs/seacat-auth#167, TeskaLabs/seacat-auth#179

Screen.Recording.2023-04-20.at.16.14.24.mov
Screen.Recording.2023-04-20.at.16.18.46.mov

@petrKavulok petrKavulok self-assigned this Feb 26, 2023
@petrKavulok
Copy link
Contributor Author

Screen.Recording.2023-06-01.at.15.09.15.1.mp4

@petrKavulok petrKavulok requested a review from Pe5h4 June 1, 2023 13:17
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok It looks good, however I have some minor change requests

"Add global role(s)": "Přidat globální role",
"Global roles have to be individually specified": "Globální role musí být specifikovány",
"Do you really want to leave this screen? Selected data will be lost": "Přesunem na jinou stránku budou ztracena zvolená data.",
"More":"Více ...",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Missing space between the colon and translation

try {
response = await SeaCatAuthAPI.get(`/role/${id}`, {params: parameters});
let selectedTenantsCopy = [...selectedTenants];
let ten = {...objCopy, roles: response.data};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok use a better naming of ten variable, I suppose its a tenantsRolesObject or something

msg = t("BulkAssignmentContainer|If you wish to assign/unassign global roles, select individual roles. Otherwise leave it as is");
}
} else if (tenantObj?.selectedRole && (tenantObj.selectedRole.length > 0)) {
msg = t("BulkAssignmentContainer|Tenant") + " '" + tenantObj._id + "' " + t("BulkAssignmentContainer|and selected roles will be assigned to/unassigned from selected credentials");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Can you wrap that the dynamic string to {t("BulkAssignmentContainer|Tenant")} '${ tenantObj._id}' ${t("BulkAssignmentContainer|and selected roles will be assigned to/unassigned from selected credentials")}

} else if (tenantObj?.selectedRole && (tenantObj.selectedRole.length > 0)) {
msg = t("BulkAssignmentContainer|Tenant") + " '" + tenantObj._id + "' " + t("BulkAssignmentContainer|and selected roles will be assigned to/unassigned from selected credentials");
} else {
msg = t("BulkAssignmentContainer|Selected credentials will be assigned to/removed from tenant") + " '" + tenantObj._id + "'";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Same here


/* Actual modified data (this data set was compared compared with `selectedCredentials` and `assigned: true` was added to matching credentials. Assigned:true property
disables the "+"" button) to be displayed in Credentials list data table */
const datatableCredentialsData = useMemo(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Since you have duplicit code in datatableCredentialsData and datatableTenantsData, I propose to unify the guts of it:

create a new method, which will return desired result:

const matchAssigned = (data, selectedEvent) => {
	let tableData = [];
	if (data) {
		data.map((dataObj) => {
			let matchedObj = selectedEvent.find(obj => obj._id === dataObj._id);
			if (matchedObj) {
				matchedObj['assigned'] = true;
				tableData.push(matchedObj);
			} else {
				dataObj['assigned'] = false;
				tableData.push(dataObj);
			}
		})
	}
	return tableData;
}

and use it within the memoised function

const datatableCredentialsData = useMemo(() => {
return matchAssigned(data, selectedCredentials);
}, [data, selectedCredentials]);

and repeat for datatableTenantsData

Always think about your code - dont repeat yourself or simplify what can be simplified or done more performant :)

return credentialsTableData
}, [data, selectedCredentials]);

const datatableTenantsData = useMemo(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok as my comment above

Unless we'd like to do bulk *unassignment*, then unassigning from tenant as a whole requires { tenant1: "UNASSIGN-TENANT", tenant2: [role1, role2,..], ...} */
// let globalRoles = [];
selectedTenants.map((obj) => {
console.log('obj: ', obj);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Forgotten console.log

/* adjustments to data structure. selectedTenants is an array of objects. Server expects credential_ids to be an object with
tenants as keys and array of roles as their values { tenant1: [role1, role2], tenant2: [], ...}
Unless we'd like to do bulk *unassignment*, then unassigning from tenant as a whole requires { tenant1: "UNASSIGN-TENANT", tenant2: [role1, role2,..], ...} */
// let globalRoles = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Why is this variable commented?

} else if (actionType === '/tenant_unassign_many') {
roles = "UNASSIGN-TENANT";
};
// here in code, we are using `{_id: Global roles, ...}` which represents global roles, but the api call expects `_id: '*'` as a representation of global roles
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Try to write comments more object based - meaning - its always better not to use any personification, when writing comments about the code - so, not we, I, ... but rather writ about what it does and why it is used. eg.

// This part of the code uses {_id: Global roles, ...}, which is the representation of global roles, however the API call expects _idto be defined as asterisk'*' as a representation of global roles

};

const unselectGlobalRole = (roleIndex) => {
// [{global: false, selectedRole: []}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Remove or add any comment to it

Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Please, use proper constants for styling

}

.credentials-suspended {
color: #73818f!important;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok why??? we have $secondary color for that. also you have wrong indentation here


@media (max-width: 994px) {
.bulk-actions-wraper {
// display: grid;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok If not needed, remove it

}

.selected-row:hover {
background-color: var(--table-bg-color-hover);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok $table-bg-color-hover -- you can load it from table styles (@import "~asab-webui/styles/components/table.scss";) or you can modify ASAB WebUI index.scss file in styles/constants/ and import this (and maybe some other) color in there


.selected-row:hover {
background-color: var(--table-bg-color-hover);
color: var(--text-color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok $text-color

}
}
& .data-table-tbody {
background-color: var(--bg-color) ;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok $bg-color

@petrKavulok petrKavulok requested a review from Pe5h4 June 6, 2023 11:16
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Ok, this looks good. Please read my comment and deliberately update, if you will find it useful

// This part of the code uses {_id: Global roles, ...}, which is the representation of global roles, however the API call expects _id to be defined as an asterisk '*' as a representation of global roles
tenantObj[obj._id] = roles;
})
globalRoles[0].global ? tenantObj['*'] = globalRoles[0].selectedRole : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrKavulok Well, for the sake of readability, I would advise you to rewrite the code to:

if(globalRoles[0].global) { tenantObj['*'] = globalRoles[0].selectedRole }

I dont say your expression is wrong, but I would personally avoid writing ternary operators where not necessary (on the other hand, in conditional rendering you would have to use ternary operators).

@petrKavulok
Copy link
Contributor Author

Ahoj @Pe5h4 ,

  • I refactored the ternary operator. ✔️
  • While testing, I found a bug in the tooltip message, which was showing the same message for globalRoles and the first item in selectedTenants (they were using the same id for tooltip). It's fixed now.

I did not encounter any other issues while testing.

@petrKavulok petrKavulok merged commit b2a9fb2 into main Jun 8, 2023
@petrKavulok petrKavulok deleted the feature/bulk-assignment branch June 8, 2023 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants