From fe3608f6a75e8acdc5de0cd5399063c9cb71aa2d Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Wed, 2 Nov 2022 16:49:41 -0400 Subject: [PATCH] remove dashboard SerializedTarget, move into expandable TargetSelect --- src/app/Dashboard/Dashboard.tsx | 27 +---------- src/app/TargetSelect/TargetSelect.tsx | 44 +++++++++++++----- src/app/TargetView/TargetView.tsx | 2 +- src/test/TargetSelect/TargetSelect.test.tsx | 4 +- .../__snapshots__/TargetSelect.test.tsx.snap | 46 ++++++++++++++++++- 5 files changed, 81 insertions(+), 42 deletions(-) diff --git a/src/app/Dashboard/Dashboard.tsx b/src/app/Dashboard/Dashboard.tsx index a32f1be43..f1d9d9d51 100644 --- a/src/app/Dashboard/Dashboard.tsx +++ b/src/app/Dashboard/Dashboard.tsx @@ -36,37 +36,12 @@ * SOFTWARE. */ import * as React from 'react'; -import { ServiceContext } from '@app/Shared/Services/Services'; -import { useSubscriptions } from '@app/utils/useSubscriptions'; import { TargetView } from '@app/TargetView/TargetView'; -import { NO_TARGET } from '@app/Shared/Services/Target.service'; -import { Card, CardBody, CardTitle, Text, TextVariants } from '@patternfly/react-core'; -import { SerializedTarget } from '../Shared/SerializedTarget'; export interface DashboardProps {} export const Dashboard: React.FunctionComponent = (props) => { - const context = React.useContext(ServiceContext); - const addSubscription = useSubscriptions(); - - const [selectedTarget, setSelectedTarget] = React.useState(NO_TARGET); - - React.useEffect(() => { - addSubscription(context.target.target().subscribe(setSelectedTarget)); - }, [addSubscription, context.target, setSelectedTarget]); - - return ( - - - - Target Details - - - - - - - ); + return ; }; export default Dashboard; diff --git a/src/app/TargetSelect/TargetSelect.tsx b/src/app/TargetSelect/TargetSelect.tsx index a72ae4255..8919e841b 100644 --- a/src/app/TargetSelect/TargetSelect.tsx +++ b/src/app/TargetSelect/TargetSelect.tsx @@ -45,8 +45,10 @@ import { Card, CardActions, CardBody, + CardExpandableContent, CardHeader, CardHeaderMain, + CardTitle, Select, SelectOption, SelectVariant, @@ -60,6 +62,7 @@ import { CreateTargetModal } from './CreateTargetModal'; import { DeleteWarningType } from '@app/Modal/DeleteWarningUtils'; import { DeleteWarningModal } from '@app/Modal/DeleteWarningModal'; import { getFromLocalStorage, removeFromLocalStorage, saveToLocalStorage } from '@app/utils/LocalStorage'; +import { SerializedTarget } from '@app/Shared/SerializedTarget'; export const CUSTOM_TARGETS_REALM = 'Custom Targets'; @@ -70,9 +73,10 @@ export const TargetSelect: React.FunctionComponent = (props) const context = React.useContext(ServiceContext); const addSubscription = useSubscriptions(); + const [isExpanded, setExpanded] = React.useState(false); const [selected, setSelected] = React.useState(NO_TARGET); const [targets, setTargets] = React.useState([] as Target[]); - const [expanded, setExpanded] = React.useState(false); + const [isDropdownOpen, setDropdownOpen] = React.useState(false); const [isLoading, setLoading] = React.useState(false); const [isModalOpen, setModalOpen] = React.useState(false); const [warningModalOpen, setWarningModalOpen] = React.useState(false); @@ -91,6 +95,10 @@ export const TargetSelect: React.FunctionComponent = (props) removeCachedTargetSelection(); }, [context.target, removeCachedTargetSelection]); + const onExpand = React.useCallback(() => { + setExpanded((v) => !v); + }, [setExpanded]); + const onSelect = React.useCallback( // ATTENTION: do not add onSelect as deps for effect hook as it updates with selected states (evt, selection, isPlaceholder) => { @@ -105,9 +113,9 @@ export const TargetSelect: React.FunctionComponent = (props) }); } } - setExpanded(false); + setDropdownOpen(false); }, - [context.target, notifications, setExpanded, setCachedTargetSelection, resetTargetSelection, selected] + [context.target, notifications, setDropdownOpen, setCachedTargetSelection, resetTargetSelection, selected] ); const selectTargetFromCache = React.useCallback( @@ -243,8 +251,8 @@ export const TargetSelect: React.FunctionComponent = (props) targets.map((t: Target) => ( {!t.alias || t.alias === t.connectUrl - ? `${t.connectUrl}: ${t.jvmId}` - : `${t.alias} (${t.connectUrl}): ${t.jvmId}`} + ? `${t.connectUrl}` + : `${t.alias} (${t.connectUrl})`} )) ), @@ -253,11 +261,20 @@ export const TargetSelect: React.FunctionComponent = (props) return ( <> - - - + + + Target JVM - + +
+ +