@@ -47,7 +47,6 @@ import { TableColumn } from '@console/internal/module/k8s';
4747import { GetDataViewRows , ResourceFilters } from '@console/app/src/components/data-view/types' ;
4848import { tableFilters } from '../factory/table-filters' ;
4949import { ButtonBar } from '../utils/button-bar' ;
50- import { Firehose } from '../utils/firehose' ;
5150import { getQueryArgument } from '../utils/router' ;
5251import { kindObj } from '../utils/inject' ;
5352import type { ListDropdownProps } from '../utils/list-dropdown' ;
@@ -57,7 +56,7 @@ import { ResourceName } from '../utils/resource-icon';
5756import { StatusBox , LoadingBox } from '../utils/status-box' ;
5857import { useAccessReview } from '../utils/rbac' ;
5958import { flagPending } from '../../reducers/features' ;
60- import { useK8sWatchResources } from '../utils/k8s-watch-hook' ;
59+ import { useK8sWatchResource , useK8sWatchResources } from '../utils/k8s-watch-hook' ;
6160
6261// Split each binding into one row per subject
6362export const flatten = ( resources ) : BindingKind [ ] =>
@@ -185,18 +184,19 @@ const bindingType = (binding: BindingKind) => {
185184 if ( ! binding ) {
186185 return undefined ;
187186 }
188- if ( binding . roleRef . name . startsWith ( 'system:' ) ) {
187+ if ( binding . roleRef ? .name ? .startsWith ( 'system:' ) ) {
189188 return 'system' ;
190189 }
191- return binding . metadata . namespace ? 'namespace' : 'cluster' ;
190+ return binding . metadata ? .namespace ? 'namespace' : 'cluster' ;
192191} ;
193192
194193const getDataViewRows : GetDataViewRows < BindingKind > = ( data , columns ) => {
195- return data . map ( ( { obj : binding } ) => {
194+ return data . map ( ( row ) => {
195+ const binding = row . obj ;
196196 const rowCells = {
197197 [ tableColumnInfo [ 0 ] . id ] : {
198198 cell : < BindingName binding = { binding } /> ,
199- props : getNameCellProps ( binding . metadata . name ) ,
199+ props : getNameCellProps ( binding . metadata ? .name ) ,
200200 } ,
201201 [ tableColumnInfo [ 1 ] . id ] : {
202202 cell : < RoleLink binding = { binding } /> ,
@@ -208,7 +208,7 @@ const getDataViewRows: GetDataViewRows<BindingKind> = (data, columns) => {
208208 cell : binding . subject . name ,
209209 } ,
210210 [ tableColumnInfo [ 4 ] . id ] : {
211- cell : binding . metadata . namespace ? (
211+ cell : binding . metadata ? .namespace ? (
212212 < ResourceLink kind = "Namespace" name = { binding . metadata . namespace } />
213213 ) : (
214214 i18next . t ( 'public~All namespaces' )
@@ -784,52 +784,79 @@ const getSubjectIndex = () => {
784784} ;
785785
786786const BindingLoadingWrapper : FC < BindingLoadingWrapperProps > = ( props ) => {
787+ const { obj, loaded, loadError, fixedKeys } = props ;
787788 const [ , setActiveNamespace ] = useActiveNamespace ( ) ;
789+
790+ if ( ! loaded ) {
791+ return < LoadingBox /> ;
792+ }
793+
794+ if ( loadError ) {
795+ return < StatusBox data = { obj } loaded = { loaded } loadError = { loadError } /> ;
796+ }
797+
798+ if ( ! obj || _ . isEmpty ( obj ) ) {
799+ return < StatusBox data = { obj } loaded = { loaded } loadError = { loadError } /> ;
800+ }
801+
788802 const fixed : { [ key : string ] : any } = { } ;
789- _ . each ( props . fixedKeys , ( k ) => ( fixed [ k ] = _ . get ( props . obj . data , k ) ) ) ;
803+ fixedKeys . forEach ( ( k ) => ( fixed [ k ] = obj ?. [ k ] ) ) ;
804+
790805 return (
791- < StatusBox { ...props . obj } >
792- < BaseEditRoleBinding
793- { ...props }
794- setActiveNamespace = { setActiveNamespace }
795- fixed = { fixed }
796- obj = { props . obj . data }
797- />
798- </ StatusBox >
806+ < BaseEditRoleBinding
807+ { ...props }
808+ setActiveNamespace = { setActiveNamespace }
809+ fixed = { fixed }
810+ obj = { obj }
811+ />
799812 ) ;
800813} ;
801814
802815export const EditRoleBinding : FC < EditRoleBindingProps > = ( { kind } ) => {
803816 const { t } = useTranslation ( ) ;
804817 const params = useParams ( ) ;
818+
819+ const [ obj , loaded , loadError ] = useK8sWatchResource < RoleBindingKind | ClusterRoleBindingKind > ( {
820+ kind,
821+ name : params . name ,
822+ namespace : params . ns ,
823+ isList : false ,
824+ } ) ;
825+
805826 return (
806- < Firehose
807- resources = { [ { kind, name : params . name , namespace : params . ns , isList : false , prop : 'obj' } ] }
808- >
809- < BindingLoadingWrapper
810- fixedKeys = { [ 'kind' , 'metadata' , 'roleRef' ] }
811- subjectIndex = { getSubjectIndex ( ) }
812- titleVerbAndKind = { t ( 'public~Edit RoleBinding' ) }
813- saveButtonText = { t ( 'public~Save' ) }
814- />
815- </ Firehose >
827+ < BindingLoadingWrapper
828+ obj = { obj }
829+ loaded = { loaded }
830+ loadError = { loadError }
831+ fixedKeys = { [ 'kind' , 'metadata' , 'roleRef' ] }
832+ subjectIndex = { getSubjectIndex ( ) }
833+ titleVerbAndKind = { t ( 'public~Edit RoleBinding' ) }
834+ saveButtonText = { t ( 'public~Save' ) }
835+ />
816836 ) ;
817837} ;
818838
819839export const CopyRoleBinding : FC < EditRoleBindingProps > = ( { kind } ) => {
820840 const { t } = useTranslation ( ) ;
821841 const params = useParams ( ) ;
842+
843+ const [ obj , loaded , loadError ] = useK8sWatchResource < RoleBindingKind | ClusterRoleBindingKind > ( {
844+ kind,
845+ name : params . name ,
846+ namespace : params . ns ,
847+ isList : false ,
848+ } ) ;
849+
822850 return (
823- < Firehose
824- resources = { [ { kind, name : params . name , namespace : params . ns , isList : false , prop : 'obj' } ] }
825- >
826- < BindingLoadingWrapper
827- fixedKeys = { [ 'kind' ] }
828- subjectIndex = { getSubjectIndex ( ) }
829- isCreate = { true }
830- titleVerbAndKind = { t ( 'public~Duplicate RoleBinding' ) }
831- />
832- </ Firehose >
851+ < BindingLoadingWrapper
852+ obj = { obj }
853+ loaded = { loaded }
854+ loadError = { loadError }
855+ fixedKeys = { [ 'kind' ] }
856+ subjectIndex = { getSubjectIndex ( ) }
857+ isCreate = { true }
858+ titleVerbAndKind = { t ( 'public~Duplicate RoleBinding' ) }
859+ />
833860 ) ;
834861} ;
835862
@@ -881,9 +908,9 @@ type BindingLoadingWrapperProps = {
881908 titleVerbAndKind : string ;
882909 saveButtonText ?: string ;
883910 isCreate ?: boolean ;
884- obj ?: {
885- data : RoleBindingKind | ClusterRoleBindingKind ;
886- } ;
911+ obj ?: RoleBindingKind | ClusterRoleBindingKind ;
912+ loaded : boolean ;
913+ loadError : any ;
887914} ;
888915
889916type EditRoleBindingProps = {
0 commit comments