Skip to content

Commit

Permalink
feat(Acl): improve view
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug committed Jun 27, 2024
1 parent 524e815 commit 5795cd9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 62 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@bem-react/classname": "^1.6.0",
"@gravity-ui/axios-wrapper": "^1.4.1",
"@gravity-ui/chartkit": "^5.5.0",
"@gravity-ui/components": "^3.6.2",
"@gravity-ui/components": "^3.7.0",
"@gravity-ui/date-utils": "^2.4.0",
"@gravity-ui/i18n": "^1.5.0",
"@gravity-ui/icons": "^2.9.1",
Expand Down
8 changes: 7 additions & 1 deletion src/containers/Tenant/Acl/Acl.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
@import '../../../styles/mixins.scss';

.ydb-acl {
width: 100%;
&__result {
align-self: flex-start;
padding-bottom: 16px;
}

&__owner-container {
position: sticky;
z-index: 2;
top: 0;

width: 100%;
padding-bottom: 16px;

background-color: var(--g-color-base-background);
}
&__definition-content {
display: flex;
flex-direction: column;
}
}
117 changes: 62 additions & 55 deletions src/containers/Tenant/Acl/Acl.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import React from 'react';

import type {Column} from '@gravity-ui/react-data-table';
import type {DefinitionListItem} from '@gravity-ui/components';
import {DefinitionList} from '@gravity-ui/components';

import {ResponseError} from '../../../components/Errors/ResponseError';
import {Loader} from '../../../components/Loader';
import {ResizeableDataTable} from '../../../components/ResizeableDataTable/ResizeableDataTable';
import {schemaAclApi} from '../../../store/reducers/schemaAcl/schemaAcl';
import type {TACE} from '../../../types/api/acl';
import {cn} from '../../../utils/cn';
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
import i18n from '../i18n';

import './Acl.scss';

const b = cn('ydb-acl');

const ACL_COLUMNS_WIDTH_LS_KEY = 'aclTableColumnsWidth';

const TABLE_SETTINGS = {
...DEFAULT_TABLE_SETTINGS,
dynamicRender: false,
stickyTop: 36,
};

const prepareLogin = (value: string | undefined) => {
if (value && value.endsWith('@staff') && !value.startsWith('svc_')) {
const login = value.split('@')[0];
Expand All @@ -32,42 +23,38 @@ const prepareLogin = (value: string | undefined) => {
return value;
};

const columns: Column<TACE>[] = [
{
name: 'AccessType',
header: 'Access Type',
sortable: false,
render: ({row}) => row.AccessType,
},
{
name: 'AccessRights',
header: 'Access Rights',
render: ({row}) => {
return row.AccessRights?.map((item, index) => {
return <div key={index}>{item}</div>;
});
},
sortable: false,
},
{
name: 'Subject',
sortable: false,
render: ({row}) => {
return prepareLogin(row.Subject);
},
width: 140,
},
{
name: 'InheritanceType',
header: 'Inheritance Type',
render: ({row}) => {
return row.InheritanceType?.map((item, index) => {
return <div key={index}>{item}</div>;
});
},
sortable: false,
},
];
const aclParams = ['access', 'type', 'inheritance'] as const;

const aclParamToName: Record<(typeof aclParams)[number], string> = {
access: 'Access',
type: 'Access type',
inheritance: 'Inheritance type',
};

const defaultInheritanceType = new Set(['Object', 'Container']);

function normalizeAcl(acl: TACE[]) {
return acl.map((ace) => {
const {AccessRules = [], AccessRights = [], AccessType, InheritanceType, Subject} = ace;
const access = AccessRules.concat(AccessRights);
//"Allow" is default access type. We want to show it only if it isn't default
const type = AccessType === 'Allow' ? undefined : AccessType;
let inheritance;
// ['Object', 'Container'] - is default inheritance type. We want to show it only if it isn't default
if (
InheritanceType?.length !== defaultInheritanceType.size ||
InheritanceType.some((t) => !defaultInheritanceType.has(t))
) {
inheritance = InheritanceType;
}
return {
access,
type,
inheritance,
Subject,
};
});
}

export const Acl = ({path}: {path: string}) => {
const {currentData, isFetching, error} = schemaAclApi.useGetSchemaAclQuery({path});
Expand All @@ -80,14 +67,34 @@ export const Acl = ({path}: {path: string}) => {
return null;
}

return (
<ResizeableDataTable
columnsWidthLSKey={ACL_COLUMNS_WIDTH_LS_KEY}
columns={columns}
data={acl}
settings={TABLE_SETTINGS}
/>
);
const normalizedAcl = normalizeAcl(acl);

const items = normalizedAcl.map(({Subject, ...data}) => {
return {
label: Subject,
items: aclParams
.map((key) => {
const value = data[key];
if (!value) {
return undefined;
}
const normalizedValue = typeof value === 'string' ? [value] : value;
return {
name: aclParamToName[key],
content: (
<div className={b('definition-content')}>
{normalizedValue.map((el) => (
<span key={el}>{el}</span>
))}
</div>
),
};
})
.filter(Boolean),
};
}) as DefinitionListItem[];

return <DefinitionList items={items} nameMaxWidth={200} />;
};

const renderOwner = () => {
Expand Down
1 change: 1 addition & 0 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
this.getPath('/viewer/json/acl'),
{
path,
merge_rules: true,
},
{concurrentId: concurrentId || `getSchemaAcl`, requestConfig: {signal}},
);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

.g-root {
--g-text-header-font-weight: 500;
--g-text-subheader-font-weight: 500;
--g-text-subheader-font-weight: 600;
--g-text-display-font-weight: 500;
--g-text-accent-font-weight: 500;

Expand Down
1 change: 1 addition & 0 deletions src/types/api/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TMetaCommonInfo {
export interface TACE {
AccessType: string;
AccessRights?: string[];
AccessRules?: string[];
Subject: string;
InheritanceType?: string[];
AccessRule: string;
Expand Down

0 comments on commit 5795cd9

Please sign in to comment.