From 676a8457983ed1660493f747cc4bb506c8ddbe9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Tue, 2 Feb 2021 23:33:48 +0100 Subject: [PATCH] 17205: Created new renderer for owner name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- .../owner-name-uuid-enhancer-actions.ts | 52 ------------------- .../owner-name-uuid-enhancer-reducer.ts | 11 ---- src/store/resources/resources-actions.ts | 4 +- src/store/store.ts | 2 - .../data-explorer/renderers.tsx | 48 +++++++++++++---- .../details-panel/process-details.tsx | 4 +- .../details-panel/project-details.tsx | 4 +- .../owner-name-uuid-enhancer.test.tsx | 46 ---------------- .../owner-name-uuid-enhancer.tsx | 46 ---------------- .../collection-panel/collection-panel.tsx | 4 +- 10 files changed, 47 insertions(+), 174 deletions(-) delete mode 100644 src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions.ts delete mode 100644 src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-reducer.ts delete mode 100644 src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.test.tsx delete mode 100644 src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.tsx diff --git a/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions.ts b/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions.ts deleted file mode 100644 index cb95c12c..00000000 --- a/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions.ts +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import { Dispatch } from 'redux'; -import { unionize, ofType, UnionOf } from '~/common/unionize'; -import { extractUuidObjectType, ResourceObjectType } from '~/models/resource'; -import { ServiceRepository } from '~/services/services'; -import { RootState } from '../store'; - -export type OwnerNameUuidEnhancerAction = UnionOf; - -export interface OwnerNameState { - name: string; - uuid: string; -} - -export const ownerNameUuidEnhancerActions = unionize({ - SET_OWNER_NAME_BY_UUID: ofType() -}); - -export const fetchOwnerNameByUuid = (uuid: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const objectType = extractUuidObjectType(uuid); - - switch (objectType) { - case ResourceObjectType.USER: - services.userService.get(uuid, false) - .then((data) => - dispatch( - ownerNameUuidEnhancerActions.SET_OWNER_NAME_BY_UUID({ - uuid, - name: (data as any).fullName, - }) - ) - ); - break; - case ResourceObjectType.GROUP: - services.groupsService.get(uuid, false) - .then((data) => - dispatch( - ownerNameUuidEnhancerActions.SET_OWNER_NAME_BY_UUID({ - uuid, - name: (data as any).name, - }) - ) - ); - break; - default: - break; - } - }; \ No newline at end of file diff --git a/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-reducer.ts b/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-reducer.ts deleted file mode 100644 index 39707928..00000000 --- a/src/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-reducer.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import { ownerNameUuidEnhancerActions, OwnerNameUuidEnhancerAction, OwnerNameState } from './owner-name-uuid-enhancer-actions'; - -export const ownerNameUuidEnhancerReducer = (state = {}, action: OwnerNameUuidEnhancerAction) => - ownerNameUuidEnhancerActions.match(action, { - SET_OWNER_NAME_BY_UUID: (data: OwnerNameState) => ({...state, [data.uuid]: data.name }), - default: () => state, - }); \ No newline at end of file diff --git a/src/store/resources/resources-actions.ts b/src/store/resources/resources-actions.ts index 1de2feff..5465db62 100644 --- a/src/store/resources/resources-actions.ts +++ b/src/store/resources/resources-actions.ts @@ -18,13 +18,13 @@ export type ResourcesAction = UnionOf; export const updateResources = (resources: Resource[]) => resourcesActions.SET_RESOURCES(resources); -export const loadResource = (uuid: string) => +export const loadResource = (uuid: string, showErrors?: boolean) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { try { const kind = extractUuidKind(uuid); const service = getResourceService(kind)(services); if (service) { - const resource = await service.get(uuid); + const resource = await service.get(uuid, showErrors); dispatch(updateResources([resource])); return resource; } diff --git a/src/store/store.ts b/src/store/store.ts index 929ca616..517368aa 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -66,7 +66,6 @@ import { linkAccountPanelReducer } from './link-account-panel/link-account-panel import { CollectionsWithSameContentAddressMiddlewareService } from '~/store/collections-content-address-panel/collections-content-address-middleware-service'; import { COLLECTIONS_CONTENT_ADDRESS_PANEL_ID } from '~/store/collections-content-address-panel/collections-content-address-panel-actions'; import { ownerNameReducer } from '~/store/owner-name/owner-name-reducer'; -import { ownerNameUuidEnhancerReducer } from './owner-name-uuid-enhancer/owner-name-uuid-enhancer-reducer'; import { SubprocessMiddlewareService } from '~/store/subprocess-panel/subprocess-panel-middleware-service'; import { SUBPROCESS_PANEL_ID } from '~/store/subprocess-panel/subprocess-panel-actions'; import { ALL_PROCESSES_PANEL_ID } from './all-processes-panel/all-processes-panel-action'; @@ -179,7 +178,6 @@ const createRootReducer = (services: ServiceRepository) => combineReducers({ dialog: dialogReducer, favorites: favoritesReducer, ownerName: ownerNameReducer, - ownerNameUuidEnhancer: ownerNameUuidEnhancerReducer, publicFavorites: publicFavoritesReducer, form: formReducer, processLogsPanel: processLogsPanelReducer, diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx index 6d95196d..7d870bc1 100644 --- a/src/views-components/data-explorer/renderers.tsx +++ b/src/views-components/data-explorer/renderers.tsx @@ -27,6 +27,7 @@ import { navigateTo } from '~/store/navigation/navigation-action'; import { withResourceData } from '~/views-components/data-explorer/with-resources'; import { CollectionResource } from '~/models/collection'; import { IllegalNamingWarning } from '~/components/warning/warning'; +import { loadResource } from '~/store/resources/resources-actions'; const renderName = (dispatch: Dispatch, item: GroupContentsResource) => @@ -434,6 +435,35 @@ export const ResourceOwnerName = connect( return { owner: ownerName ? ownerName!.name : resource!.ownerUuid }; })((props: { owner: string }) => renderOwner(props.owner)); +export const ResourceOwnerWithName = + compose( + connect( + (state: RootState, props: { uuid: string }) => { + let ownerName = ''; + const resource = getResource(props.uuid)(state.resources); + + if (resource) { + ownerName = (resource as any).fullName || resource.name; + } + + return { uuid: props.uuid, ownerName }; + }), + withStyles({}, { withTheme: true })) + ((props: { uuid: string, ownerName: string, dispatch: Dispatch, theme: ArvadosTheme }) => { + const { uuid, ownerName, dispatch, theme } = props; + + if (ownerName === '') { + dispatch(loadResource(uuid, false)); + return + {uuid} + ; + } + + return + {uuid} ({ownerName}) + ; + }); + const renderType = (type: string) => {resourceLabel(type)} @@ -446,20 +476,20 @@ export const ResourceType = connect( })((props: { type: string }) => renderType(props.type)); export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => { - return { resource: getResource(props.uuid)(state.resources) }; - })((props: { resource: GroupContentsResource }) => - (props.resource && props.resource.kind === ResourceKind.COLLECTION) + return { resource: getResource(props.uuid)(state.resources) }; +})((props: { resource: GroupContentsResource }) => + (props.resource && props.resource.kind === ResourceKind.COLLECTION) ? : - ); +); export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => { - return { collection: getResource(props.uuid)(state.resources) }; - })((props: { collection: CollectionResource }) => - (props.collection.uuid !== props.collection.currentVersionUuid) + return { collection: getResource(props.uuid)(state.resources) }; +})((props: { collection: CollectionResource }) => + (props.collection.uuid !== props.collection.currentVersionUuid) ? version {props.collection.version} : head version - ); +); export const ProcessStatus = compose( connect((state: RootState, props: { uuid: string }) => { @@ -478,7 +508,7 @@ export const ProcessStatus = compose( export const ProcessStartDate = connect( (state: RootState, props: { uuid: string }) => { const process = getProcess(props.uuid)(state.resources); - return { date: ( process && process.container ) ? process.container.startedAt : '' }; + return { date: (process && process.container) ? process.container.startedAt : '' }; })((props: { date: string }) => renderDate(props.date)); export const renderRunTime = (time: number) => diff --git a/src/views-components/details-panel/process-details.tsx b/src/views-components/details-panel/process-details.tsx index a065d91e..0867f92d 100644 --- a/src/views-components/details-panel/process-details.tsx +++ b/src/views-components/details-panel/process-details.tsx @@ -10,7 +10,7 @@ import { ResourceKind } from '~/models/resource'; import { resourceLabel } from '~/common/labels'; import { DetailsData } from "./details-data"; import { DetailsAttribute } from "~/components/details-attribute/details-attribute"; -import OwnerNameUuidEnhancer from '../owner-name-uuid-enhancer/owner-name-uuid-enhancer'; +import { ResourceOwnerWithName } from '../data-explorer/renderers'; export class ProcessDetails extends DetailsData { @@ -22,7 +22,7 @@ export class ProcessDetails extends DetailsData { return
} /> + uuidEnhancer={(uuid: string) => } /> diff --git a/src/views-components/details-panel/project-details.tsx b/src/views-components/details-panel/project-details.tsx index eb613bf2..34a372c9 100644 --- a/src/views-components/details-panel/project-details.tsx +++ b/src/views-components/details-panel/project-details.tsx @@ -17,7 +17,7 @@ import { withStyles, StyleRulesCallback, WithStyles } from '@material-ui/core'; import { ArvadosTheme } from '~/common/custom-theme'; import { Dispatch } from 'redux'; import { getPropertyChip } from '../resource-properties-form/property-chip'; -import OwnerNameUuidEnhancer from '../owner-name-uuid-enhancer/owner-name-uuid-enhancer'; +import { ResourceOwnerWithName } from '../data-explorer/renderers'; export class ProjectDetails extends DetailsData { getIcon(className?: string) { @@ -61,7 +61,7 @@ const ProjectDetailsComponent = connect(null, mapDispatchToProps)( ({ classes, project, onClick }: ProjectDetailsComponentProps) =>
} lowercaseValue={true} /> + uuidEnhancer={(uuid: string) => } lowercaseValue={true} /> diff --git a/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.test.tsx b/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.test.tsx deleted file mode 100644 index 1df5fafa..00000000 --- a/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.test.tsx +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import * as React from 'react'; -import { mount, configure } from 'enzyme'; -import * as Adapter from "enzyme-adapter-react-16"; -import { OwnerNameUuidEnhancer, OwnerNameUuidEnhancerProps } from './owner-name-uuid-enhancer'; - -configure({ adapter: new Adapter() }); - -describe('NotFoundPanelRoot', () => { - let props: OwnerNameUuidEnhancerProps; - - beforeEach(() => { - props = { - ownerNamesMap: {}, - fetchOwner: () => {}, - uuid: 'zzzz-tpzed-xxxxxxxxxxxxxxx', - }; - }); - - it('should render uuid without name', () => { - // when - const wrapper = mount(); - - // then - expect(wrapper.html()).toBe('zzzz-tpzed-xxxxxxxxxxxxxxx'); - }); - - it('should render uuid with name', () => { - // given - const fullName = 'John Doe'; - - // setup - props.ownerNamesMap = { - [props.uuid]: fullName - }; - - // when - const wrapper = mount(); - - // then - expect(wrapper.html()).toBe('zzzz-tpzed-xxxxxxxxxxxxxxx (John Doe)'); - }); -}); \ No newline at end of file diff --git a/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.tsx b/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.tsx deleted file mode 100644 index b4431fa4..00000000 --- a/src/views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer.tsx +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import * as React from 'react'; -import { Dispatch } from 'redux'; -import { RootState } from '~/store/store'; -import { connect } from 'react-redux'; -import { fetchOwnerNameByUuid } from '~/store/owner-name-uuid-enhancer/owner-name-uuid-enhancer-actions'; - -export interface OwnerNameUuidEnhancerOwnProps { - uuid: string; -} - -export interface OwnerNameUuidEnhancerRootDataProps { - ownerNamesMap: any; -} - -export interface OwnerNameUuidEnhancerDispatchProps { - fetchOwner: Function; -} - -export type OwnerNameUuidEnhancerProps = OwnerNameUuidEnhancerOwnProps & OwnerNameUuidEnhancerRootDataProps & OwnerNameUuidEnhancerDispatchProps; - -export const OwnerNameUuidEnhancer = ({ uuid, ownerNamesMap, fetchOwner }: OwnerNameUuidEnhancerProps) => { - React.useEffect(() => { - if (!ownerNamesMap[uuid]) { - fetchOwner(uuid); - } - }, [uuid, ownerNamesMap, fetchOwner]); - - return {uuid}{ownerNamesMap[uuid] ? ` (${ownerNamesMap[uuid]})` : ''}; -}; - -const mapStateToProps = (state: RootState): OwnerNameUuidEnhancerRootDataProps => { - return { - ownerNamesMap: state.ownerNameUuidEnhancer, - }; -}; - -const mapDispatchToProps = (dispatch: Dispatch): OwnerNameUuidEnhancerDispatchProps => ({ - fetchOwner: (uuid: string) => dispatch(fetchOwnerNameByUuid(uuid)) -}); - -export default connect(mapStateToProps, mapDispatchToProps) - (OwnerNameUuidEnhancer); diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index e75073ae..32e37d46 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -30,9 +30,9 @@ import { UserResource } from '~/models/user'; import { getUserUuid } from '~/common/getuser'; import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer'; import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions'; -import OwnerNameUuidEnhancer from '../../views-components/owner-name-uuid-enhancer/owner-name-uuid-enhancer'; import { Link } from 'react-router-dom'; import { Link as ButtonLink } from '@material-ui/core'; +import { ResourceOwnerWithName } from '~/views-components/data-explorer/renderers'; type CssRules = 'root' | 'button' @@ -299,7 +299,7 @@ export const CollectionDetailsAttributes = (props: { item: CollectionResource, t } /> + uuidEnhancer={(uuid: string) => } />