1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Dispatch } from 'redux';
7 import { RootState } from '~/store/store';
8 import { connect } from 'react-redux';
9 import { fetchOwnerNameByUuid } from '~/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions';
11 export interface OwnerNameUuidEnhancerOwnProps {
15 export interface OwnerNameUuidEnhancerRootDataProps {
19 export interface OwnerNameUuidEnhancerDispatchProps {
23 export type OwnerNameUuidEnhancerProps = OwnerNameUuidEnhancerOwnProps & OwnerNameUuidEnhancerRootDataProps & OwnerNameUuidEnhancerDispatchProps;
25 export const OwnerNameUuidEnhancer = ({ uuid, ownerNamesMap, fetchOwner }: OwnerNameUuidEnhancerProps) => {
26 React.useEffect(() => {
27 if (!ownerNamesMap[uuid]) {
30 }, [uuid, ownerNamesMap, fetchOwner]);
32 return <span>{uuid}{ownerNamesMap[uuid] ? ` (${ownerNamesMap[uuid]})` : ''}</span>;
35 const mapStateToProps = (state: RootState): OwnerNameUuidEnhancerRootDataProps => {
37 ownerNamesMap: state.ownerNameUuidEnhancer,
41 const mapDispatchToProps = (dispatch: Dispatch): OwnerNameUuidEnhancerDispatchProps => ({
42 fetchOwner: (uuid: string) => dispatch<any>(fetchOwnerNameByUuid(uuid))
45 export default connect<OwnerNameUuidEnhancerRootDataProps, OwnerNameUuidEnhancerDispatchProps, OwnerNameUuidEnhancerOwnProps>(mapStateToProps, mapDispatchToProps)
46 (OwnerNameUuidEnhancer);