Skip to content

Commit ecdec2f

Browse files
refactor: migrate Acl and SchemaViewer to ts (#481)
1 parent 4c4e684 commit ecdec2f

File tree

15 files changed

+347
-336
lines changed

15 files changed

+347
-336
lines changed

src/containers/Tenant/Acl/Acl.js

-153
This file was deleted.

src/containers/Tenant/Acl/Acl.scss

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import '../../../styles/mixins.scss';
22

3-
.kv-acl {
3+
.ydb-acl {
44
display: flex;
55
overflow: auto;
66
flex-grow: 1;
@@ -16,14 +16,6 @@
1616
padding: 0 12px 16px;
1717
}
1818

19-
&__loader-container {
20-
display: flex;
21-
justify-content: center;
22-
align-items: center;
23-
24-
height: 100%;
25-
}
26-
2719
&__owner-container {
2820
position: sticky;
2921
z-index: 2;

src/containers/Tenant/Acl/Acl.tsx

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import {useDispatch} from 'react-redux';
2+
import {useEffect} from 'react';
3+
import cn from 'bem-cn-lite';
4+
5+
import DataTable, {Column} from '@gravity-ui/react-data-table';
6+
7+
import type {TACE} from '../../../types/api/acl';
8+
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
9+
import {useTypedSelector} from '../../../utils/hooks';
10+
import {getSchemaAcl, setAclWasNotLoaded} from '../../../store/reducers/schemaAcl/schemaAcl';
11+
12+
import {ResponseError} from '../../../components/Errors/ResponseError';
13+
import {Loader} from '../../../components/Loader';
14+
15+
import './Acl.scss';
16+
import i18n from '../i18n';
17+
18+
const b = cn('ydb-acl');
19+
20+
const TABLE_SETTINGS = {
21+
...DEFAULT_TABLE_SETTINGS,
22+
dynamicRender: false,
23+
stickyTop: 36,
24+
};
25+
26+
const prepareLogin = (value: string | undefined) => {
27+
if (value && value.endsWith('@staff') && !value.startsWith('svc_')) {
28+
const login = value.split('@')[0];
29+
return login;
30+
}
31+
32+
return value;
33+
};
34+
35+
const columns: Column<TACE>[] = [
36+
{
37+
name: 'AccessType',
38+
header: 'Access Type',
39+
sortable: false,
40+
render: ({row}) => row.AccessType,
41+
},
42+
{
43+
name: 'AccessRights',
44+
header: 'Access Rights',
45+
render: ({row}) => {
46+
return row.AccessRights?.map((item, index) => {
47+
return <div key={index}>{item}</div>;
48+
});
49+
},
50+
sortable: false,
51+
},
52+
{
53+
name: 'Subject',
54+
sortable: false,
55+
render: ({row}) => {
56+
return prepareLogin(row.Subject);
57+
},
58+
width: 140,
59+
},
60+
{
61+
name: 'InheritanceType',
62+
header: 'Inheritance Type',
63+
render: ({row}) => {
64+
return row.InheritanceType?.map((item, index) => {
65+
return <div key={index}>{item}</div>;
66+
});
67+
},
68+
sortable: false,
69+
},
70+
];
71+
72+
export const Acl = () => {
73+
const dispatch = useDispatch();
74+
75+
const {currentSchemaPath} = useTypedSelector((state) => state.schema);
76+
const {loading, error, acl, owner, wasLoaded} = useTypedSelector((state) => state.schemaAcl);
77+
78+
useEffect(() => {
79+
if (currentSchemaPath) {
80+
dispatch(getSchemaAcl({path: currentSchemaPath}));
81+
}
82+
83+
return () => {
84+
// Ensures correct acl on path change
85+
dispatch(setAclWasNotLoaded());
86+
};
87+
}, [currentSchemaPath, dispatch]);
88+
89+
const renderTable = () => {
90+
if (!acl || !acl.length) {
91+
return null;
92+
}
93+
94+
return (
95+
<DataTable
96+
theme="yandex-cloud"
97+
columns={columns}
98+
data={acl}
99+
settings={TABLE_SETTINGS}
100+
/>
101+
);
102+
};
103+
104+
const renderOwner = () => {
105+
if (!owner) {
106+
return null;
107+
}
108+
109+
return (
110+
<div className={b('owner-container')}>
111+
<span className={b('owner-label')}>{`${i18n('acl.owner')}: `}</span>
112+
{prepareLogin(owner)}
113+
</div>
114+
);
115+
};
116+
117+
if (loading && !wasLoaded) {
118+
return <Loader />;
119+
}
120+
121+
if (error) {
122+
return <ResponseError error={error} className={b('message-container')} />;
123+
}
124+
125+
if (!loading && !acl && !owner) {
126+
return <div className={b('message-container')}>{i18n('acl.empty')}</div>;
127+
}
128+
129+
return (
130+
<div className={b()}>
131+
<div className={b('result')}>
132+
{renderOwner()}
133+
{renderTable()}
134+
</div>
135+
</div>
136+
);
137+
};

src/containers/Tenant/ObjectSummary/ObjectSummary.scss

-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
}
3636
}
3737

38-
&__loader {
39-
display: flex;
40-
justify-content: center;
41-
align-items: center;
42-
}
43-
4438
&__tree-wrapper {
4539
display: flex;
4640
flex-direction: column;

0 commit comments

Comments
 (0)