Skip to content

Commit 03f238e

Browse files
authored
fix(AccessRights): no need in forms (#2457)
1 parent ac5f23a commit 03f238e

File tree

4 files changed

+122
-134
lines changed

4 files changed

+122
-134
lines changed

src/containers/Tenant/Diagnostics/AccessRights/AccessRights.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function AccessRights() {
2222
const {path, database} = useCurrentSchema();
2323
const editable = useEditAccessAvailable();
2424
const [autoRefreshInterval] = useAutoRefreshInterval();
25-
const {currentData, isFetching, error} = schemaAclApi.useGetSchemaAclQuery(
25+
const {isLoading, error} = schemaAclApi.useGetSchemaAclQuery(
2626
{path, database},
2727
{
2828
pollingInterval: autoRefreshInterval,
@@ -31,8 +31,6 @@ export function AccessRights() {
3131

3232
const {handleShowGrantAccessChange} = useTenantQueryParams();
3333

34-
const loading = isFetching && !currentData;
35-
3634
const renderContent = () => {
3735
if (error) {
3836
return <ResponseError error={error} />;
@@ -64,5 +62,5 @@ export function AccessRights() {
6462
);
6563
};
6664

67-
return <LoaderWrapper loading={loading}>{renderContent()}</LoaderWrapper>;
65+
return <LoaderWrapper loading={isLoading}>{renderContent()}</LoaderWrapper>;
6866
}

src/containers/Tenant/Diagnostics/AccessRights/components/ChangeOwnerDialog.tsx

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -66,60 +66,56 @@ function ChangeOwnerDialog({open, onClose, path, database}: ChangeOwnerDialogPro
6666
setNewOwner(value);
6767
setRequestErrorMessage('');
6868
};
69+
const onApply = () => {
70+
updateOwner({path, database, rights: {ChangeOwnership: {Subject: newOwner}}})
71+
.unwrap()
72+
.then(() => {
73+
onClose();
74+
createToast({
75+
name: 'updateOwner',
76+
content: i18n('title_owner-changed'),
77+
autoHiding: 3000,
78+
});
79+
})
80+
.catch((error) => {
81+
setRequestErrorMessage(prepareErrorMessage(error));
82+
});
83+
};
6984
return (
70-
<Dialog open={open} size="s" onClose={onClose}>
85+
<Dialog open={open} size="s" onClose={onClose} onEnterKeyDown={onApply}>
7186
<Dialog.Header caption={i18n('action_change-owner')} />
72-
<form
73-
onSubmit={(e) => {
74-
e.preventDefault();
75-
updateOwner({path, database, rights: {ChangeOwnership: {Subject: newOwner}}})
76-
.unwrap()
77-
.then(() => {
78-
onClose();
79-
createToast({
80-
name: 'updateOwner',
81-
content: i18n('title_owner-changed'),
82-
autoHiding: 3000,
83-
});
84-
})
85-
.catch((error) => {
86-
setRequestErrorMessage(prepareErrorMessage(error));
87-
});
87+
<Dialog.Body>
88+
<div className={block('dialog-content-wrapper')}>
89+
<TextInput
90+
id="queryName"
91+
placeholder={i18n('decription_enter-subject')}
92+
value={newOwner}
93+
onUpdate={handleTyping}
94+
hasClear
95+
autoFocus
96+
autoComplete={false}
97+
/>
98+
{requestErrorMessage && (
99+
<Text
100+
color="danger"
101+
className={block('dialog-error')}
102+
title={requestErrorMessage}
103+
>
104+
{requestErrorMessage}
105+
</Text>
106+
)}
107+
</div>
108+
</Dialog.Body>
109+
<Dialog.Footer
110+
onClickButtonApply={onApply}
111+
textButtonCancel={i18n('action_cancel')}
112+
textButtonApply={i18n('action_apply')}
113+
onClickButtonCancel={onClose}
114+
propsButtonApply={{
115+
loading: updateOwnerResponse.isLoading,
116+
disabled: !newOwner.length,
88117
}}
89-
>
90-
<Dialog.Body>
91-
<div className={block('dialog-content-wrapper')}>
92-
<TextInput
93-
id="queryName"
94-
placeholder={i18n('decription_enter-subject')}
95-
value={newOwner}
96-
onUpdate={handleTyping}
97-
hasClear
98-
autoFocus
99-
autoComplete={false}
100-
/>
101-
{requestErrorMessage && (
102-
<Text
103-
color="danger"
104-
className={block('dialog-error')}
105-
title={requestErrorMessage}
106-
>
107-
{requestErrorMessage}
108-
</Text>
109-
)}
110-
</div>
111-
</Dialog.Body>
112-
<Dialog.Footer
113-
textButtonCancel={i18n('action_cancel')}
114-
textButtonApply={i18n('action_apply')}
115-
onClickButtonCancel={onClose}
116-
propsButtonApply={{
117-
type: 'submit',
118-
loading: updateOwnerResponse.isLoading,
119-
disabled: !newOwner.length,
120-
}}
121-
/>
122-
</form>
118+
/>
123119
</Dialog>
124120
);
125121
}

src/containers/Tenant/Diagnostics/AccessRights/components/RightsTable/RevokeAllRightsDialog.tsx

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -79,62 +79,59 @@ function RevokeAllRightsDialog({
7979
const [requestErrorMessage, setRequestErrorMessage] = React.useState('');
8080
const [removeAccess, removeAccessResponse] = schemaAclApi.useUpdateAccessMutation();
8181

82+
const onApply = () => {
83+
removeAccess({
84+
path,
85+
database,
86+
rights: {
87+
RemoveAccess: [
88+
{
89+
Subject: subject,
90+
AccessRights: Array.from(subjectExplicitRights),
91+
AccessType: 'Allow',
92+
},
93+
],
94+
},
95+
})
96+
.unwrap()
97+
.then(() => {
98+
onClose();
99+
createToast({
100+
name: 'revokeAllRights',
101+
content: i18n('description_rights-revoked'),
102+
autoHiding: 3000,
103+
});
104+
})
105+
.catch((error) => {
106+
setRequestErrorMessage(prepareErrorMessage(error));
107+
});
108+
};
109+
82110
return (
83111
<Dialog open={open} size="s" onClose={onClose}>
84112
<Dialog.Header caption={i18n('label_revoke-all-rights')} />
85-
<form
86-
onSubmit={(e) => {
87-
e.preventDefault();
88-
removeAccess({
89-
path,
90-
database,
91-
rights: {
92-
RemoveAccess: [
93-
{
94-
Subject: subject,
95-
AccessRights: Array.from(subjectExplicitRights),
96-
AccessType: 'Allow',
97-
},
98-
],
99-
},
100-
})
101-
.unwrap()
102-
.then(() => {
103-
onClose();
104-
createToast({
105-
name: 'revokeAllRights',
106-
content: i18n('description_rights-revoked'),
107-
autoHiding: 3000,
108-
});
109-
})
110-
.catch((error) => {
111-
setRequestErrorMessage(prepareErrorMessage(error));
112-
});
113+
<Dialog.Body>
114+
<Flex direction="column" gap={5}>
115+
<Text variant="body-2">{i18n('description_revoke-all-rights')}</Text>
116+
<SubjectWithAvatar subject={subject} />
117+
</Flex>
118+
</Dialog.Body>
119+
<Dialog.Footer
120+
onClickButtonApply={onApply}
121+
textButtonCancel={i18n('action_cancel')}
122+
textButtonApply={i18n('action_revoke')}
123+
onClickButtonCancel={onClose}
124+
propsButtonApply={{
125+
loading: removeAccessResponse.isLoading,
126+
view: 'outlined-danger',
113127
}}
114128
>
115-
<Dialog.Body>
116-
<Flex direction="column" gap={5}>
117-
<Text variant="body-2">{i18n('description_revoke-all-rights')}</Text>
118-
<SubjectWithAvatar subject={subject} />
119-
</Flex>
120-
</Dialog.Body>
121-
<Dialog.Footer
122-
textButtonCancel={i18n('action_cancel')}
123-
textButtonApply={i18n('action_revoke')}
124-
onClickButtonCancel={onClose}
125-
propsButtonApply={{
126-
type: 'submit',
127-
loading: removeAccessResponse.isLoading,
128-
view: 'outlined-danger',
129-
}}
130-
>
131-
{requestErrorMessage && (
132-
<Text color="danger" title={requestErrorMessage}>
133-
{requestErrorMessage}
134-
</Text>
135-
)}
136-
</Dialog.Footer>
137-
</form>
129+
{requestErrorMessage && (
130+
<Text color="danger" title={requestErrorMessage}>
131+
{requestErrorMessage}
132+
</Text>
133+
)}
134+
</Dialog.Footer>
138135
</Dialog>
139136
);
140137
}

src/containers/Tenant/GrantAccess/shared.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import i18n from './i18n';
44

55
export const block = cn('ydb-grant-access');
66

7-
export const HumanReadableRights: Record<string, number> = {
7+
export const RightsCodes: Record<string, number> = {
88
selectRow: 1,
99
updateRow: 2,
1010
eraseRow: 4,
@@ -31,36 +31,33 @@ export const HumanReadableRights: Record<string, number> = {
3131
};
3232

3333
export const RightsDescription: Record<number, string> = {
34-
[HumanReadableRights.selectRow]: i18n('description_select-row'),
35-
[HumanReadableRights.updateRow]: i18n('description_update-row'),
36-
[HumanReadableRights.eraseRow]: i18n('description_erase-row'),
37-
[HumanReadableRights.writeAttributes]: i18n('description_write-attributes'),
38-
[HumanReadableRights.createDirectory]: i18n('description_create-directory'),
39-
[HumanReadableRights.createTable]: i18n('description_create-table'),
40-
[HumanReadableRights.createQueue]: i18n('description_create-queue'),
41-
[HumanReadableRights.removeSchema]: i18n('description_remove-schema'),
42-
[HumanReadableRights.alterSchema]: i18n('description_alter-schema'),
43-
[HumanReadableRights.createDatabase]: i18n('description_create-database'),
44-
[HumanReadableRights.dropDatabase]: i18n('description_drop-database'),
45-
[HumanReadableRights.readAttributes]: i18n('description_read-attributes'),
46-
[HumanReadableRights.describeSchema]: i18n('description_describe-schema'),
47-
[HumanReadableRights.connectDatabase]: i18n('description_connect-database'),
48-
[HumanReadableRights.grantAccessRights]: i18n('description_grant-access-rights'),
49-
[HumanReadableRights.genericRead]: i18n('description_generic-read'),
50-
[HumanReadableRights.genericWrite]: i18n('description_generic-write'),
51-
[HumanReadableRights.genericManage]: i18n('description_generic-manage'),
52-
[HumanReadableRights.genericList]: i18n('description_generic-list'),
53-
[HumanReadableRights.genericUse]: i18n('description_generic-use'),
54-
[HumanReadableRights.genericUseLegacy]: i18n('description_generic-use-legacy'),
55-
[HumanReadableRights.genericFull]: i18n('description_generic-full'),
56-
[HumanReadableRights.genericFullLegacy]: i18n('description_generic-full-legacy'),
34+
[RightsCodes.selectRow]: i18n('description_select-row'),
35+
[RightsCodes.updateRow]: i18n('description_update-row'),
36+
[RightsCodes.eraseRow]: i18n('description_erase-row'),
37+
[RightsCodes.writeAttributes]: i18n('description_write-attributes'),
38+
[RightsCodes.createDirectory]: i18n('description_create-directory'),
39+
[RightsCodes.createTable]: i18n('description_create-table'),
40+
[RightsCodes.createQueue]: i18n('description_create-queue'),
41+
[RightsCodes.removeSchema]: i18n('description_remove-schema'),
42+
[RightsCodes.alterSchema]: i18n('description_alter-schema'),
43+
[RightsCodes.createDatabase]: i18n('description_create-database'),
44+
[RightsCodes.dropDatabase]: i18n('description_drop-database'),
45+
[RightsCodes.readAttributes]: i18n('description_read-attributes'),
46+
[RightsCodes.describeSchema]: i18n('description_describe-schema'),
47+
[RightsCodes.connectDatabase]: i18n('description_connect-database'),
48+
[RightsCodes.grantAccessRights]: i18n('description_grant-access-rights'),
49+
[RightsCodes.genericRead]: i18n('description_generic-read'),
50+
[RightsCodes.genericWrite]: i18n('description_generic-write'),
51+
[RightsCodes.genericManage]: i18n('description_generic-manage'),
52+
[RightsCodes.genericList]: i18n('description_generic-list'),
53+
[RightsCodes.genericUse]: i18n('description_generic-use'),
54+
[RightsCodes.genericUseLegacy]: i18n('description_generic-use-legacy'),
55+
[RightsCodes.genericFull]: i18n('description_generic-full'),
56+
[RightsCodes.genericFullLegacy]: i18n('description_generic-full-legacy'),
5757
};
5858

5959
export function isLegacyRight(right: number) {
60-
return (
61-
right === HumanReadableRights.genericFullLegacy ||
62-
right === HumanReadableRights.genericUseLegacy
63-
);
60+
return right === RightsCodes.genericFullLegacy || right === RightsCodes.genericUseLegacy;
6461
}
6562

6663
export interface CommonRightsProps {

0 commit comments

Comments
 (0)