@@ -26,76 +26,95 @@ class CatalogPage extends React.Component {
2626 {
2727 key : 'action' ,
2828 width : "100px" ,
29+ className : 'text-right' ,
2930 onCellClick : ( record , event ) => {
3031 if (
31- event . target . matches ( '.anticon-edit' ) ||
32- ( event . target . firstElementChild &&
33- event . target . firstElementChild . matches ( '.anticon-edit' ) )
32+ ( event . target . matches ( '#view' ) ||
33+ ( event . target . firstElementChild && event . target . firstElementChild . matches ( '#view' ) ) ) ||
34+ ( event . target . matches ( '#edit' ) ||
35+ ( event . target . firstElementChild && event . target . firstElementChild . matches ( '#edit' ) ) )
3436 ) {
35- this . edit ( record ) ;
36-
37- } else if (
38- event . target . matches ( '.anticon-delete' ) ||
39- ( event . target . firstElementChild &&
40- event . target . firstElementChild . matches ( '.anticon-delete' ) )
37+ this . open ( record ) ;
38+ }
39+ else if (
40+ event . target . matches ( '#delete' ) ||
41+ ( event . target . firstElementChild && event . target . firstElementChild . matches ( '#delete' ) )
4142 ) {
4243 this . remove ( record ) ;
4344 }
4445 } ,
4546 render : ( text , record ) => (
4647 < span >
47- < Button type = "primary" icon = "edit" style = { { margin : "0 5px" } } />
48- < Button type = "danger" icon = "delete" style = { { margin : "0 5px" } } />
48+ { this . state . catalog . objpermissions . includes ( 'U' ) &&
49+ < Button type = "primary" id = "edit" icon = "edit" style = { { margin : "0 5px" } } />
50+ }
51+
52+ { ! this . state . catalog . objpermissions . includes ( 'U' ) &&
53+ this . state . catalog . objpermissions . includes ( 'R' ) &&
54+ < Button type = "primary" id = "view" icon = "search" style = { { margin : "0 5px" } } />
55+ }
56+
57+ { this . state . catalog . objpermissions . includes ( 'D' ) &&
58+ < Button type = "danger" icon = "delete" style = { { margin : "0 5px" } } />
59+ }
4960 </ span >
5061 )
5162 }
5263 ] ;
5364
5465 this . state = {
55- catalog : { } ,
66+ catalog : {
67+ name : '' ,
68+ objpermissions : ''
69+ } ,
5670 extent : [ ]
5771 } ;
5872 }
5973
6074 componentDidMount ( ) {
6175 const name = this . props . match . params . name ;
6276
63- let promise = CatalogApi . getCatalogInfo ( name ) ;
64- promise = promise . then ( ( response ) => {
65- this . setState ( { catalog : response . data } ) ;
66- return this . loadCatalogExtent ( name , promise ) ;
67- } ) ;
77+ CatalogApi . getCatalogInfo ( name )
78+ . then ( ( response ) => {
79+ this . setState ( ( state ) => ( { catalog : response . data } ) ) ;
80+
81+ // Load catalog data only if we have permission for that
82+ if ( response . data . objpermissions . includes ( 'R' ) ) {
83+ return this . loadCatalogExtent ( name ) ;
84+ }
85+ } )
86+ . catch ( ( error ) => {
87+ const summary = ( error && error . response && error . response . data && error . response . data . summary ) ;
6888
69- promise . catch ( ( error ) => {
7089 notification . error ( {
71- message : 'An error has occurred: ' + error . summary
90+ message : 'An error has occurred: ' + summary
7291 } ) ;
7392 } ) ;
7493 }
7594
76- loadCatalogExtent = ( name , promise ) => {
77- if ( promise ) {
78- promise = promise . then ( ( ) => {
79- return CatalogApi . getCatalogExtent ( name ) ;
95+ loadCatalogExtent = ( name ) => {
96+ return CatalogApi . getCatalogExtent ( name )
97+ . then ( ( response ) => {
98+ this . setState ( { extent : response . data . children } ) ;
99+ } )
100+ . catch ( ( error ) => {
101+ const summary = ( error && error . response && error . response . data && error . response . data . summary ) ;
102+
103+ notification . error ( {
104+ message : 'An error has occurred: ' + summary
105+ } ) ;
80106 } ) ;
81- }
82- else {
83- promise = CatalogApi . getCatalogExtent ( name ) ;
84- }
85107
86- promise = promise . then ( ( response ) => {
87- this . setState ( { extent : response . data . children } ) ;
88- } ) ;
89108 } ;
90109
91110 add = ( ) => {
92111 const path = this . props . location . pathname ;
93- this . props . history . replace ( `${ path } /object` ) ;
112+ this . props . history . push ( `${ path } /object` ) ;
94113 } ;
95114
96- edit = ( record ) => {
115+ open = ( record ) => {
97116 const path = this . props . location . pathname ;
98- this . props . history . replace ( `${ path } /object/${ record . _id } ` ) ;
117+ this . props . history . push ( `${ path } /object/${ record . _id } ` ) ;
99118 } ;
100119
101120 remove = ( record ) => {
@@ -128,29 +147,40 @@ class CatalogPage extends React.Component {
128147
129148 < div style = { { background : '#fff' , padding : 24 , minHeight : 280 } } >
130149
131- < div className = "clearfix" style = { { width : "100%" } } >
150+ < div className = "clearfix" style = { { width : "100%" , marginBottom : '20px' } } >
132151 < h2 style = { { display : "inline" } } >
133152 { this . state . catalog . name || '...' }
134153 </ h2 >
135- < Button type = "primary"
136- style = { { float : 'right' , marginBottom : 8 } }
137- size = "small"
138- onClick = { this . add }
139- className = "clearfix"
140- >
141- Add
142- </ Button >
154+
155+ { ( this . state . catalog . objpermissions . includes ( 'C' ) ) &&
156+ < Button type = "primary"
157+ style = { { float : 'right' , marginBottom : 8 } }
158+ size = "small"
159+ onClick = { this . add }
160+ className = "clearfix"
161+ >
162+ Add
163+ </ Button >
164+ }
165+
143166 </ div >
144167
145- < Table
146- rowKey = "_id"
147- dataSource = { this . state . extent }
148- columns = { this . columns }
149- showHeader = { false }
150- bordered
151- size = "middle"
152- pagination = { { showSizeChanger : true } }
153- />
168+ { this . state . catalog . objpermissions . includes ( 'R' ) &&
169+ < Table
170+ rowKey = "_id"
171+ dataSource = { this . state . extent }
172+ columns = { this . columns }
173+ showHeader = { false }
174+ size = "middle"
175+ pagination = { { showSizeChanger : true } }
176+ />
177+ }
178+
179+ { this . state . catalog . name && ! this . state . catalog . objpermissions . includes ( 'R' ) &&
180+ < div style = { { textAlign : 'center' , padding : '20px' } } >
181+ < h3 > You have no permissions to view this catalog.</ h3 >
182+ </ div >
183+ }
154184 </ div >
155185 </ div >
156186 ) ;
0 commit comments