Skip to content

Commit f6b01c3

Browse files
fix: fix copy schema action (#483)
1 parent 1c5adab commit f6b01c3

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

package-lock.json

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@gravity-ui/react-data-table": "^1.0.3",
1818
"axios": "0.19.2",
1919
"bem-cn-lite": "4.0.0",
20+
"copy-to-clipboard": "^3.3.3",
2021
"history": "4.10.1",
2122
"js-cookie": "2.2.1",
2223
"keymaster": "1.6.2",

src/containers/Tenant/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44

55
"summary.navigation": "Navigation",
66
"summary.showPreview": "Show preview",
7-
"summary.copySchemaPath": "Copy schema path"
7+
"summary.copySchemaPath": "Copy schema path",
8+
9+
"actions.copied" : "The path is copied to the clipboard",
10+
"actions.notCopied" : "Couldn’t copy the path"
811
}

src/containers/Tenant/i18n/ru.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44

55
"summary.navigation": "Навигация",
66
"summary.showPreview": "Показать превью",
7-
"summary.copySchemaPath": "Скопировать путь"
7+
"summary.copySchemaPath": "Скопировать путь",
8+
9+
"actions.copied": "Путь успешно скопирован",
10+
"actions.notCopied": "Не получилось скопировать путь"
811
}

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {Dispatch} from 'react';
2+
import copy from 'copy-to-clipboard';
3+
24
import type {NavigationTreeNodeType, NavigationTreeProps} from 'ydb-ui-components';
35

46
import {changeUserInput} from '../../../store/reducers/executeQuery';
@@ -7,6 +9,8 @@ import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant'
79
import {TENANT_QUERY_TABS_ID, TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
810
import createToast from '../../../utils/createToast';
911

12+
import i18n from '../i18n';
13+
1014
const createTableTemplate = (path: string) => {
1115
return `CREATE TABLE \`${path}/my_table\`
1216
(
@@ -48,22 +52,20 @@ const bindActions = (
4852
selectQuery: inputQuery(selectQueryTemplate),
4953
upsertQuery: inputQuery(upsertQueryTemplate),
5054
copyPath: () => {
51-
navigator.clipboard
52-
.writeText(path)
53-
.then(() => {
54-
createToast({
55-
name: 'Copied',
56-
title: 'The path is copied to the clipboard',
57-
type: 'success',
58-
});
59-
})
60-
.catch(() => {
61-
createToast({
62-
name: 'Not copied',
63-
title: 'Couldn’t copy the path',
64-
type: 'error',
65-
});
55+
try {
56+
copy(path);
57+
createToast({
58+
name: 'Copied',
59+
title: i18n('actions.copied'),
60+
type: 'success',
61+
});
62+
} catch {
63+
createToast({
64+
name: 'Not copied',
65+
title: i18n('actions.notCopied'),
66+
type: 'error',
6667
});
68+
}
6769
},
6870
openPreview: () => {
6971
dispatch(setShowPreview(true));

0 commit comments

Comments
 (0)