-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
Screen.Recording.2023-06-01.at.15.09.15.1.mp4 |
There was a problem hiding this 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
public/locales/cs/translation.json
Outdated
"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 ...", |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 + "'"; |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: []}] |
There was a problem hiding this comment.
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petrKavulok $bg-color
There was a problem hiding this 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; |
There was a problem hiding this comment.
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).
Ahoj @Pe5h4 ,
I did not encounter any other issues while testing. |
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