Skip to content

dbeaver/pro#9798 adds sorting for columns in user tables#4484

Open
sergeyteleshev wants to merge 5 commits into
develfrom
9798-cb-add-ordering-for-administrative-tables
Open

dbeaver/pro#9798 adds sorting for columns in user tables#4484
sergeyteleshev wants to merge 5 commits into
develfrom
9798-cb-add-ordering-for-administrative-tables

Conversation

@sergeyteleshev

Copy link
Copy Markdown
Contributor

@codacy-production

codacy-production Bot commented Jul 22, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 27 complexity

Metric Results
Complexity 27

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

return NEW_USER_SYMBOL in user && user[NEW_USER_SYMBOL] === true && 'createdAt' in user && Boolean(user.createdAt);
}

export function isUser(user: object): user is AdminUser {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should not be here, please move it to the compareGrantSubjects.ts‎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added new file for all of these helpers

Comment on lines +87 to +104
function getTeamRoleRank(user: AdminUser) {
const granted = tabState.state.grantedUsers.find(grantedUser => grantedUser.userId === user.userId);

if (!granted) {
return 0;
}

return granted.teamRole === USER_TEAM_ROLE_SUPERVISOR ? 2 : 1;
}

const columns = [...COLUMNS];

if (teamRolesResource.data.length > 0) {
columns.push(TEAM_ROLE_COLUMN);
columns.push({
key: TEAM_ROLE_COLUMN_KEY,
label: 'plugin_authentication_administration_team_user_team_role_supervisor',
compare: (a, b) => getTeamRoleRank(a) - getTeamRoleRank(b),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so for every single compare we do 2 x O(n) searches among grantedUsers.
It might be a problem on big lists.
Let's optimize it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in data structure & algorithms world 2 * O(N) = O(N) and its fine. computers and browsers can handle that easy peasy
I think this matters only if you develop search engine or computer chip architecture or something like that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

but how the compare function is used?

it's basically O(n) * compare (O(n))

Comment on lines +27 to +37
export function compareUsers<T extends Pick<AdminUser, 'userId'>>(a: T, b: T): number {
return a.userId.localeCompare(b.userId);
}

export function compareUsersByLastLogin<T extends Pick<AdminUser, 'lastLoginTime'>>(a: T, b: T): number {
const aTime = a.lastLoginTime ? new Date(a.lastLoginTime).getTime() : 0;
const bTime = b.lastLoginTime ? new Date(b.lastLoginTime).getTime() : 0;
return aTime - bTime;
}

export function compareNewUsers<T extends AdminUser>(a: T, b: T): number {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

compareUsers and compareNewUsers are really confusing names, because without looking on implementation you can't understand what it does and how to use it.

so it's better to use compareUserById and compareUsersByNewness how you did with compareUsersByLastLogin

import classes from './GrantManagementTable.module.css';

export interface IGrantManagementTableColumn {
export interface IGrantManagementTableColumn<T = any> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we loose all the types because of this any, if we want to use types properly, we have to use unknown here or put some constraint how you did it earlier with extends

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.

3 participants