generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Create MCP - Components Selection #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
24b3a83
init
lucasgoral ad61a55
fixes
lucasgoral 2612811
refactor
lucasgoral ae5640b
refactor
lucasgoral 8a3ddc6
fixes
lucasgoral 87bc6f8
refactor
lucasgoral d5fe887
refactor
lucasgoral 6678290
refactor
lucasgoral 5386419
Update ComponentsSelection.tsx
lucasgoral beca37c
Update ComponentsSelection.tsx
lucasgoral ca3981c
fixes
lucasgoral 8be43e6
refactor
lucasgoral 1581782
Revert "refactor"
lucasgoral 9688b98
Update CreateManagedControlPlaneWizardContainer.tsx
lucasgoral fd53f32
refactor
lucasgoral ce59fc5
Update ComponentsSelectionContainer.tsx
lucasgoral faca8de
Merge branch 'main' into feat/components-selection-for-mcp
lucasgoral dbf592d
Update CreateManagedControlPlaneWizardContainer.tsx
lucasgoral fe31088
fix
lucasgoral f6a4ca5
fixes
lucasgoral 7f9a96b
fixes
lucasgoral 8e28d80
fix
lucasgoral d709629
Merge branch 'main' into feat/components-selection-for-mcp
lucasgoral 613e729
Update CreateManagedControlPlaneWizardContainer.tsx
lucasgoral 01339c4
Update ComponentsSelection.module.css
lucasgoral ab73d54
Update ComponentsSelection.tsx
lucasgoral 58669ee
Update componentsVersions.spec.ts
lucasgoral 85a772b
Update ComponentsSelectionContainer.tsx
lucasgoral 9327fce
Update CreateManagedControlPlaneWizardContainer.tsx
lucasgoral 0f2aef7
Update createManagedControlPlane.ts
lucasgoral 721ce2a
fixes
lucasgoral a9ef812
fixes
lucasgoral 14a8ece
refactor
lucasgoral 6a2261d
Merge branch 'main' into feat/components-selection-for-mcp
lucasgoral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
src/components/ComponentsSelection/ComponentsSelection.module.css
This file contains hidden or 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,5 @@ | ||
.row { | ||
padding: 1rem; | ||
background: var(--sapBackgroundColor); | ||
border-bottom: 1px solid var(--sapList_BorderColor); | ||
} |
162 changes: 162 additions & 0 deletions
162
src/components/ComponentsSelection/ComponentsSelection.tsx
This file contains hidden or 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,162 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
CheckBox, | ||
Select, | ||
Option, | ||
FlexBox, | ||
Title, | ||
Text, | ||
Input, | ||
Button, | ||
Grid, | ||
List, | ||
ListItemStandard, | ||
Icon, | ||
Ui5CustomEvent, | ||
CheckBoxDomRef, | ||
SelectDomRef, | ||
InputDomRef, | ||
} from '@ui5/webcomponents-react'; | ||
import styles from './ComponentsSelection.module.css'; | ||
import { Infobox } from '../Ui/Infobox/Infobox.tsx'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export interface ComponentSelectionItem { | ||
name: string; | ||
versions: string[]; | ||
isSelected: boolean; | ||
selectedVersion: string; | ||
documentationUrl: string; | ||
} | ||
|
||
export interface ComponentsSelectionProps { | ||
components: ComponentSelectionItem[]; | ||
setSelectedComponents: React.Dispatch< | ||
React.SetStateAction<ComponentSelectionItem[]> | ||
>; | ||
} | ||
|
||
export const ComponentsSelection: React.FC<ComponentsSelectionProps> = ({ | ||
components, | ||
setSelectedComponents, | ||
}) => { | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
const { t } = useTranslation(); | ||
const handleSelectionChange = ( | ||
e: Ui5CustomEvent<CheckBoxDomRef, { checked: boolean }>, | ||
) => { | ||
const id = e.target?.id; | ||
setSelectedComponents((prev) => | ||
prev.map((component) => | ||
component.name === id | ||
? { ...component, isSelected: !component.isSelected } | ||
: component, | ||
), | ||
); | ||
}; | ||
|
||
const handleSearch = (e: Ui5CustomEvent<InputDomRef, never>) => { | ||
setSearchTerm(e.target.value.trim()); | ||
}; | ||
|
||
const handleVersionChange = ( | ||
e: Ui5CustomEvent<SelectDomRef, { selectedOption: HTMLElement }>, | ||
) => { | ||
const selectedOption = e.detail.selectedOption as HTMLElement; | ||
const name = selectedOption.dataset.name; | ||
const version = selectedOption.dataset.version; | ||
setSelectedComponents((prev) => | ||
prev.map((component) => | ||
component.name === name | ||
? { ...component, selectedVersion: version || '' } | ||
: component, | ||
), | ||
); | ||
}; | ||
|
||
const filteredComponents = components.filter(({ name }) => | ||
name.includes(searchTerm), | ||
); | ||
const selectedComponents = components.filter( | ||
(component) => component.isSelected, | ||
); | ||
|
||
return ( | ||
<div> | ||
<Title>{t('componentsSelection.selectComponents')}</Title> | ||
|
||
<Input | ||
placeholder={t('common.search')} | ||
id="search" | ||
showClearIcon | ||
icon={<Icon name="search" />} | ||
onInput={handleSearch} | ||
/> | ||
|
||
<Grid> | ||
<div data-layout-span="XL8 L8 M8 S8"> | ||
{filteredComponents.map((component) => ( | ||
<FlexBox | ||
key={component.name} | ||
className={styles.row} | ||
gap={10} | ||
justifyContent="SpaceBetween" | ||
> | ||
<CheckBox | ||
valueState="None" | ||
text={component.name} | ||
id={component.name} | ||
checked={component.isSelected} | ||
onChange={handleSelectionChange} | ||
/> | ||
<FlexBox | ||
gap={10} | ||
justifyContent="SpaceBetween" | ||
alignItems="Baseline" | ||
> | ||
{/*This button will be implemented later*/} | ||
{component.documentationUrl && ( | ||
<Button design="Transparent"> | ||
{t('common.documentation')} | ||
</Button> | ||
)} | ||
<Select | ||
value={component.selectedVersion} | ||
onChange={handleVersionChange} | ||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
{component.versions.map((version) => ( | ||
<Option | ||
key={version} | ||
data-version={version} | ||
data-name={component.name} | ||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
selected={component.selectedVersion === version} | ||
> | ||
{version} | ||
</Option> | ||
))} | ||
</Select> | ||
</FlexBox> | ||
</FlexBox> | ||
))} | ||
</div> | ||
<div data-layout-span="XL4 L4 M4 S4"> | ||
{selectedComponents.length > 0 ? ( | ||
<List headerText={t('componentsSelection.selectedComponents')}> | ||
{selectedComponents.map((component) => ( | ||
<ListItemStandard | ||
key={component.name} | ||
text={component.name} | ||
additionalText={component.selectedVersion} | ||
/> | ||
))} | ||
</List> | ||
) : ( | ||
<Infobox fullWidth variant={'success'}> | ||
<Text>{t('componentsSelection.pleaseSelectComponents')}</Text> | ||
</Infobox> | ||
)} | ||
</div> | ||
</Grid> | ||
</div> | ||
); | ||
}; |
72 changes: 72 additions & 0 deletions
72
src/components/ComponentsSelection/ComponentsSelectionContainer.tsx
This file contains hidden or 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, { useEffect, useState } from 'react'; | ||
import { | ||
ComponentSelectionItem, | ||
ComponentsSelection, | ||
} from './ComponentsSelection.tsx'; | ||
|
||
import IllustratedError from '../Shared/IllustratedError.tsx'; | ||
import { sortVersions } from '../../utils/componentsVersions.ts'; | ||
|
||
import { ListManagedComponents } from '../../lib/api/types/crate/listManagedComponents.ts'; | ||
import useApiResource from '../../lib/api/useApiResource.ts'; | ||
import Loading from '../Shared/Loading.tsx'; | ||
|
||
export interface ComponentItem { | ||
name: string; | ||
versions: string[]; | ||
} | ||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface ComponentsSelectionProps { | ||
selectedComponents: ComponentSelectionItem[]; | ||
setSelectedComponents: React.Dispatch< | ||
React.SetStateAction<ComponentSelectionItem[]> | ||
>; | ||
} | ||
export const ComponentsSelectionContainer: React.FC< | ||
ComponentsSelectionProps | ||
> = ({ setSelectedComponents, selectedComponents }) => { | ||
const { | ||
data: allManagedComponents, | ||
error, | ||
isLoading, | ||
} = useApiResource(ListManagedComponents()); | ||
const [isReady, setIsReady] = useState(false); | ||
useEffect(() => { | ||
if ( | ||
allManagedComponents?.items.length === 0 || | ||
!allManagedComponents?.items || | ||
isReady | ||
) | ||
return; | ||
|
||
setSelectedComponents( | ||
allManagedComponents?.items?.map((item) => { | ||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const versions = sortVersions(item.status.versions); | ||
return { | ||
name: item.metadata.name, | ||
versions: versions, | ||
selectedVersion: versions[0], | ||
isSelected: false, | ||
documentationUrl: '', | ||
}; | ||
}) ?? [], | ||
); | ||
setIsReady(true); | ||
}, [allManagedComponents, isReady, setSelectedComponents]); | ||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
if (error) return <IllustratedError />; | ||
return ( | ||
<> | ||
{selectedComponents.length > 0 ? ( | ||
<ComponentsSelection | ||
components={selectedComponents} | ||
setSelectedComponents={setSelectedComponents} | ||
/> | ||
) : ( | ||
<IllustratedError title={'Cannot load components list'} /> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.