-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathDatasetPanel.tsx
More file actions
171 lines (155 loc) · 5.83 KB
/
DatasetPanel.tsx
File metadata and controls
171 lines (155 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React from 'react';
import {ArrowsRotateRight, Plus} from '@gravity-ui/icons';
import {
Button,
HelpMark,
Icon,
SegmentedRadioGroup as RadioButton,
TextInput,
} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {I18n} from 'i18n';
import {connect, useDispatch} from 'react-redux';
import type {DatasetOptions} from 'shared';
import {DatasetPanelQA} from 'shared';
import type {DatalensGlobalState} from 'ui';
import type {DatasetTab} from '../../constants';
import {TAB_DATASET, TAB_SOURCES} from '../../constants';
import {editorSetFilter} from '../../store/actions/creators';
import {UISelector, optionsSelector} from '../../store/selectors';
import {getDatasetTabs} from './helpers';
import './DatasetPanel.scss';
const b = block('dataset-panel');
const i18n = I18n.keyset('dataset.dataset-editor.modify');
type TabSwitchProps = Pick<DatasetPanelProps, 'isCreationProcess' | 'tab' | 'switchTab'>;
function TabSwitch(props: TabSwitchProps) {
const {tab, switchTab, isCreationProcess} = props;
const tabs = getDatasetTabs(isCreationProcess);
return (
<RadioButton
qa={DatasetPanelQA.TabRadio}
value={tab}
onChange={(e) => switchTab(e.target.value as DatasetTab)}
>
{tabs.map(({value, label, disabled}) => (
<RadioButton.Option
key={value}
content={i18n(label)}
value={value}
disabled={disabled}
/>
))}
</RadioButton>
);
}
type StateProps = ReturnType<typeof mapStateToProps>;
type DatasetPanelProps = StateProps & {
isCreationProcess: boolean;
previewEnabled: boolean;
tab: DatasetTab;
switchTab: (tab: DatasetTab) => void;
refreshSources: () => void;
openDialogFieldEditor: () => void;
togglePreview: () => void;
};
const DatasetPanel = (props: DatasetPanelProps) => {
const {
tab,
options,
filter,
previewEnabled,
isCreationProcess,
ui: {isFieldEditorModuleLoading},
switchTab,
openDialogFieldEditor,
togglePreview,
refreshSources,
} = props;
const dispatch = useDispatch();
const handleFilterUpdate = React.useCallback(
(nextFilter: string) => {
dispatch(editorSetFilter(nextFilter));
},
[dispatch],
);
const isDatasetTab = tab === TAB_DATASET;
const isSourceTab = tab === TAB_SOURCES;
return (
<div className={b()}>
<TabSwitch tab={tab} switchTab={switchTab} isCreationProcess={isCreationProcess} />
<React.Fragment>
{isDatasetTab && (
<Button
className={b('btn-update-fields')}
disabled={!(options as DatasetOptions).schema_update_enabled}
onClick={refreshSources}
>
<Icon
className={b('ic-sync')}
data={ArrowsRotateRight}
width="16"
height="16"
/>
<span>{i18n('button_update-fields')}</span>
</Button>
)}
{(isDatasetTab || isSourceTab) && (
<div className={b('preview-btn', {tab}, b('item'))}>
<Button disabled={!previewEnabled} onClick={togglePreview}>
<span>{i18n('button_preview')}</span>
{/* Omit the empty div in order to reserve a place for the tooltip icon */}
{previewEnabled ? null : (
<div className={b('preview-btn-tooltip-margin')} />
)}
</Button>
{!previewEnabled && (
<div className={b('preview-btn-tooltip')}>
<HelpMark
popoverProps={{
placement: ['right', 'left'],
}}
>
<div className={b('preview-btn-tooltip-content')}>
<span>{i18n('label_preview-not-supported')}</span>
</div>
</HelpMark>
</div>
)}
</div>
)}
{isDatasetTab && (
<Button
className={b('add-field-btn', b('item'))}
loading={isFieldEditorModuleLoading}
onClick={openDialogFieldEditor}
>
<Icon
className={b('add-field-btn-ic')}
data={Plus}
width="18"
height="18"
/>
<span>{i18n('button_add-field')}</span>
</Button>
)}
{isDatasetTab && (
<TextInput
className={b('find-field', b('item'))}
placeholder={i18n('field_find-field')}
value={filter}
hasClear={true}
onUpdate={handleFilterUpdate}
/>
)}
</React.Fragment>
</div>
);
};
const mapStateToProps = (state: DatalensGlobalState) => {
return {
ui: UISelector(state), // eslint-disable-line new-cap
options: optionsSelector(state),
filter: state.dataset.editor.filter,
};
};
export default connect(mapStateToProps)(DatasetPanel);