@@ -48,7 +48,6 @@ import { getSampleDataModal } from '../common/helpers/add_sample_modal';
48
48
import { pageStyles } from '../../../common/constants/shared' ;
49
49
import { DeleteModal } from '../common/helpers/delete_modal' ;
50
50
import {
51
- clonePanel ,
52
51
createPanel ,
53
52
deletePanels ,
54
53
fetchPanels ,
@@ -57,6 +56,8 @@ import {
57
56
renameCustomPanel ,
58
57
selectPanelList ,
59
58
} from './redux/panel_slice' ;
59
+ import { isNameValid } from './helpers/utils' ;
60
+ import { useToast } from '../common/toast' ;
60
61
61
62
/*
62
63
* "CustomPanelTable" module, used to view all the saved panels
@@ -77,17 +78,13 @@ interface Props {
77
78
loading : boolean ;
78
79
setBreadcrumbs : ( newBreadcrumbs : ChromeBreadcrumb [ ] ) => void ;
79
80
parentBreadcrumbs : EuiBreadcrumb [ ] ;
80
- cloneCustomPanel : ( newCustomPanelName : string , customPanelId : string ) => void ;
81
- deleteCustomPanelList : ( customPanelIdList : string [ ] , toastMessage : string ) => any ;
82
81
addSamplePanels : ( ) => void ;
83
82
}
84
83
85
84
export const CustomPanelTable = ( {
86
85
loading,
87
86
setBreadcrumbs,
88
87
parentBreadcrumbs,
89
- cloneCustomPanel,
90
- deleteCustomPanelList,
91
88
addSamplePanels,
92
89
} : Props ) => {
93
90
const customPanels = useSelector < CustomPanelType [ ] > ( selectPanelList ) ;
@@ -100,16 +97,13 @@ export const CustomPanelTable = ({
100
97
const history = useHistory ( ) ;
101
98
102
99
const dispatch = useDispatch ( ) ;
100
+ const { setToast } = useToast ( ) ;
103
101
104
102
useEffect ( ( ) => {
105
103
setBreadcrumbs ( parentBreadcrumbs ) ;
106
104
dispatch ( fetchPanels ( ) ) ;
107
105
} , [ ] ) ;
108
106
109
- // useEffect(() =>
110
- // console.log({ customPanels, selectedCustomPanels }, [customPanels, selectedCustomPanels])
111
- // );
112
-
113
107
useEffect ( ( ) => {
114
108
const url = window . location . hash . split ( '/' ) ;
115
109
if ( url [ url . length - 1 ] === 'create' ) {
@@ -126,55 +120,58 @@ export const CustomPanelTable = ({
126
120
} ;
127
121
128
122
const onCreate = async ( newCustomPanelName : string ) => {
129
- const newPanel = newPanelTemplate ( newCustomPanelName ) ;
130
- dispatch ( createPanel ( newPanel ) ) ;
123
+ if ( ! isNameValid ( newCustomPanelName ) ) {
124
+ setToast ( 'Invalid Dashboard name' , 'danger' ) ;
125
+ } else {
126
+ const newPanel = newPanelTemplate ( newCustomPanelName ) ;
127
+ dispatch ( createPanel ( newPanel ) ) ;
128
+ }
131
129
closeModal ( ) ;
132
130
} ;
133
131
134
132
const onRename = async ( newCustomPanelName : string ) => {
135
- dispatch ( renameCustomPanel ( newCustomPanelName , selectedCustomPanels [ 0 ] . id ) ) ;
133
+ if ( ! isNameValid ( newCustomPanelName ) ) {
134
+ setToast ( 'Invalid Dashboard name' , 'danger' ) ;
135
+ } else {
136
+ dispatch ( renameCustomPanel ( newCustomPanelName , selectedCustomPanels [ 0 ] . id ) ) ;
137
+ }
136
138
closeModal ( ) ;
137
139
} ;
138
140
139
141
const onClone = async ( newName : string ) => {
140
- let sourcePanel = selectedCustomPanels [ 0 ] ;
141
- try {
142
- if ( ! isUuid ( sourcePanel . id ) ) {
143
- // Observability Panel API returns partial record, so for duplication
144
- // we will retrieve the entire record and allow new process to continue.
145
- const legacyFetchResult = await coreRefs . http ! . get (
146
- `${ CUSTOM_PANELS_API_PREFIX } /panels/${ sourcePanel . id } `
147
- ) ;
148
- sourcePanel = legacyFetchResult . operationalPanel ;
149
- }
142
+ if ( ! isNameValid ( newName ) ) {
143
+ setToast ( 'Invalid Operational Panel name' , 'danger' ) ;
144
+ } else {
145
+ let sourcePanel = selectedCustomPanels [ 0 ] ;
146
+ try {
147
+ if ( ! isUuid ( sourcePanel . id ) ) {
148
+ // Observability Panel API returns partial record, so for duplication
149
+ // we will retrieve the entire record and allow new process to continue.
150
+ const legacyFetchResult = await coreRefs . http ! . get (
151
+ `${ CUSTOM_PANELS_API_PREFIX } /panels/${ sourcePanel . id } `
152
+ ) ;
153
+ sourcePanel = legacyFetchResult . operationalPanel ;
154
+ }
150
155
151
- const { id, ...newPanel } = {
152
- ...sourcePanel ,
153
- title : newName ,
154
- } ;
156
+ const { id, ...newPanel } = {
157
+ ...sourcePanel ,
158
+ title : newName ,
159
+ } ;
155
160
156
- dispatch ( createPanel ( newPanel ) ) ;
157
- } catch ( err ) {
158
- console . log ( err ) ;
161
+ dispatch ( createPanel ( newPanel ) ) ;
162
+ } catch ( err ) {
163
+ setToast (
164
+ 'Error cloning Observability Dashboard, please make sure you have the correct permission.' ,
165
+ 'danger'
166
+ ) ;
167
+ console . error ( err ) ;
168
+ }
159
169
}
160
170
closeModal ( ) ;
161
171
} ;
162
172
163
173
const onDelete = async ( ) => {
164
- const toastMessage = `Observability Dashboards ${
165
- selectedCustomPanels . length > 1 ? 's' : ' ' + selectedCustomPanels [ 0 ] . title
166
- } successfully deleted!`;
167
-
168
- try {
169
- dispatch ( deletePanels ( selectedCustomPanels ) ) ;
170
- } catch ( err ) {
171
- // setToast(
172
- // 'Error deleting Operational Panels, please make sure you have the correct permission.',
173
- // 'danger'
174
- // );
175
- console . error ( err . body ?. message || err ) ;
176
- }
177
-
174
+ dispatch ( deletePanels ( selectedCustomPanels ) ) ;
178
175
closeModal ( ) ;
179
176
} ;
180
177
@@ -337,7 +334,6 @@ export const CustomPanelTable = ({
337
334
} ,
338
335
] as Array < EuiTableFieldDataColumnType < CustomPanelListType > > ;
339
336
340
- // console.log('rendering', { customPanels, selectedCustomPanels });
341
337
return (
342
338
< div style = { pageStyles } >
343
339
< EuiPage >
0 commit comments