-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RegisterModel): 9914 autofill connection (#3084)
* feat(RegisterModel): 9914 autofill connection Signed-off-by: gitdallas <[email protected]> squash me Signed-off-by: gitdallas <[email protected]> squashme Signed-off-by: gitdallas <[email protected]> * pull radio body out of radiobody prop Signed-off-by: gitdallas <[email protected]> * fixed lint Signed-off-by: gitdallas <[email protected]> --------- Signed-off-by: gitdallas <[email protected]>
- Loading branch information
Showing
6 changed files
with
408 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
frontend/src/pages/modelRegistry/screens/RegisterModel/ConnectionDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
Menu, | ||
MenuContent, | ||
MenuItem, | ||
Dropdown, | ||
MenuList, | ||
MenuToggle, | ||
Spinner, | ||
} from '@patternfly/react-core'; | ||
import React from 'react'; | ||
import { DataConnection } from '~/pages/projects/types'; | ||
import { getDataConnectionDisplayName } from '~/pages/projects/screens/detail/data-connections/utils'; | ||
// TODO: temporarily importing across pages so not to interfere with ongoing dataconnection work | ||
import useDataConnections from '~/pages/projects/screens/detail/data-connections/useDataConnections'; | ||
|
||
type ConnectionDropdownProps = { | ||
onSelect: (connectionInfo: DataConnection) => void; | ||
project?: string; | ||
selectedConnection?: DataConnection; | ||
}; | ||
export const ConnectionDropdown = ({ | ||
onSelect, | ||
project, | ||
selectedConnection, | ||
}: ConnectionDropdownProps): React.JSX.Element => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [connections, connectionsLoaded, connectionsLoadError] = useDataConnections(project); | ||
|
||
const onToggle = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const filteredConnections = connections.filter((c) => c.data.data?.AWS_S3_BUCKET); | ||
|
||
const getToggleContent = () => { | ||
if (!project) { | ||
return 'Select a project to view its available data connections'; | ||
} | ||
if (connectionsLoadError) { | ||
return 'Error loading connections'; | ||
} | ||
if (!connectionsLoaded) { | ||
return ( | ||
<> | ||
<Spinner size="sm" /> Loading Data Connections for the selected project... | ||
</> | ||
); | ||
} | ||
if (!filteredConnections.length) { | ||
return 'No available data connections'; | ||
} | ||
if (selectedConnection) { | ||
return getDataConnectionDisplayName(selectedConnection); | ||
} | ||
return 'Select data connection'; | ||
}; | ||
|
||
const onSelectConnection = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
option?: string | number | null, | ||
) => { | ||
setIsOpen(false); | ||
if (typeof option === 'string') { | ||
const value = connections.find((d) => d.data.metadata.name === option); | ||
if (!value) { | ||
return; | ||
} | ||
onSelect(value); | ||
} | ||
}; | ||
return ( | ||
<Dropdown | ||
onOpenChange={(isOpened) => setIsOpen(isOpened)} | ||
toggle={(toggleRef) => ( | ||
<MenuToggle | ||
isDisabled={!filteredConnections.length} | ||
isFullWidth | ||
data-testid="select-data-connection" | ||
ref={toggleRef} | ||
onClick={onToggle} | ||
isExpanded={isOpen} | ||
> | ||
{getToggleContent()} | ||
</MenuToggle> | ||
)} | ||
isOpen={isOpen} | ||
> | ||
<Menu onSelect={onSelectConnection} isScrollable isPlain> | ||
<MenuContent> | ||
<MenuList> | ||
{filteredConnections.map((dataItem) => ( | ||
<MenuItem key={dataItem.data.metadata.name} itemId={dataItem.data.metadata.name}> | ||
{getDataConnectionDisplayName(dataItem)} | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</MenuContent> | ||
</Menu> | ||
</Dropdown> | ||
); | ||
}; |
72 changes: 72 additions & 0 deletions
72
frontend/src/pages/modelRegistry/screens/RegisterModel/ConnectionModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { Modal, Button, FormGroup, HelperText, Form, FormHelperText } from '@patternfly/react-core'; | ||
import ProjectSelector from '~/concepts/projects/ProjectSelector'; | ||
import { DataConnection } from '~/pages/projects/types'; | ||
import { ConnectionDropdown } from './ConnectionDropdown'; | ||
|
||
export const ConnectionModal: React.FC<{ | ||
isOpen: boolean; | ||
onClose: () => void; | ||
onSubmit: (connection: DataConnection) => void; | ||
}> = ({ isOpen = false, onClose, onSubmit }) => { | ||
const [project, setProject] = React.useState<string | undefined>(undefined); | ||
const [connection, setConnection] = React.useState<DataConnection | undefined>(undefined); | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
data-testid="connection-autofill-modal" | ||
variant="medium" | ||
title="Autofill from data connection" | ||
description="Select a project to list its object storage data connections. Select a data connection to autofill the model location." | ||
onClose={() => { | ||
setProject(undefined); | ||
setConnection(undefined); | ||
onClose(); | ||
}} | ||
actions={[ | ||
<Button | ||
isDisabled={!connection} | ||
data-testid="autofill-modal-button" | ||
key="confirm" | ||
onClick={() => { | ||
if (connection) { | ||
onSubmit(connection); | ||
} | ||
}} | ||
> | ||
Autofill | ||
</Button>, | ||
<Button key="cancel" variant="link" onClick={onClose}> | ||
Cancel | ||
</Button>, | ||
]} | ||
> | ||
<Form> | ||
<FormGroup label="Project" isRequired fieldId="autofillProject"> | ||
<ProjectSelector | ||
isFullWidth | ||
onSelection={(projectName: string) => { | ||
setProject(projectName); | ||
setConnection(undefined); | ||
}} | ||
namespace={project || ''} | ||
invalidDropdownPlaceholder="Select project" | ||
/> | ||
</FormGroup> | ||
<FormGroup label="Data connection name" isRequired fieldId="autofillConnection"> | ||
<ConnectionDropdown | ||
onSelect={setConnection} | ||
selectedConnection={connection} | ||
project={project} | ||
/> | ||
<FormHelperText> | ||
<HelperText> | ||
Data connection list includes only object storage types that contain a bucket. | ||
</HelperText> | ||
</FormHelperText> | ||
</FormGroup> | ||
</Form> | ||
</Modal> | ||
); | ||
}; |
Oops, something went wrong.