Skip to content

Commit 5484fea

Browse files
feat: Add Community Modules sources list (#4420)
* List component added * Get sources and move list to separate file * Info button added * Style correction * Update public/i18n/en.yaml Co-authored-by: Grzegorz Karaluch <grzegorz.karaluch@sap.com> --------- Co-authored-by: Grzegorz Karaluch <grzegorz.karaluch@sap.com>
1 parent f474e83 commit 5484fea

File tree

6 files changed

+116
-5
lines changed

6 files changed

+116
-5
lines changed

public/i18n/en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,16 @@ modules:
958958
sla-warning: Community modules are contributed by the Kyma community and are not automatically updated or maintained. Additionally, they are not covered by any service level agreement (SLA). Use them at your own risk. <0>Learn more</0>
959959
source-yaml:
960960
add-source-yaml: Add Source YAML
961+
add-source-yaml-info: Add your own custom modules to the Kyma cluster by adding their source files to this list. After that, your modules show up automatically in the list.
961962
example-format: 'Example format: http://github.com/project/repo/file.yaml'
962963
module-already-exists: <0> {{moduleTemplate}} </0> already exists in the <0> {{namespace}} </0> namespace.
963964
module-templates-to-add: ModuleTemplates to add
964965
modules-wont-be-added: Following ModuleTemplates already exist in the cluster and cannot be added.
965966
namespace-description: Namespace where ModuleTemplates are applied. If left empty, the namespace defined in the ModuleTemplates is used. Resources cannot be created in the kyma-system namespace.
966967
no-module-templates: No ModuleTemplates to add.
968+
no-source-yaml: No source YAML added.
967969
source-yaml-url: Source YAML URL
970+
source-yamls-header: Source YAMLs
968971
title: Community Modules
969972
namespaces:
970973
create-modal:

src/components/Modules/community/CommunityModulesAddModule.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import { UnsavedMessageBox } from 'shared/components/UnsavedMessageBox/UnsavedMessageBox';
4646
import { createPortal } from 'react-dom';
4747
import { Description } from 'shared/components/Description/Description';
48+
import { CommunityModulesSourcesList } from './components/CommunityModulesSourcesList';
4849

4950
type VersionDisplayInfo = {
5051
moduleTemplate: {
@@ -384,6 +385,7 @@ export default function CommunityModulesAddModule(props: any) {
384385
url={'https://kyma-project.io/#/community-modules/user/README'}
385386
/>
386387
</MessageStrip>
388+
<CommunityModulesSourcesList />
387389
{communityModulesToDisplay?.length !== 0 ? (
388390
renderCards()
389391
) : (

src/components/Modules/community/components/AddSourceYamls.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ export const AddSourceYamls = () => {
191191
accessibleName="add-yamls"
192192
design="Emphasized"
193193
key="add-yamls"
194+
slot="action"
194195
onClick={() => {
195196
setShowAddSource(true);
196197
}}
197198
>
198-
{t('modules.community.source-yaml.add-source-yaml')}
199+
{t('common.buttons.add')}
199200
</Button>
200201

201202
{showAddSource &&
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.card-header {
2+
display: flex;
3+
justify-content: space-between;
4+
align-items: center;
5+
padding: 0.5rem 1rem;
6+
7+
&__title {
8+
display: flex;
9+
justify-content: start;
10+
align-items: center;
11+
}
12+
}
13+
.list-top-separator {
14+
border-top: 1px solid var(--sapGroup_TitleBorderColor);
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { useTranslation } from 'react-i18next';
2+
import {
3+
Card,
4+
Link,
5+
List,
6+
ListItemStandard,
7+
Title,
8+
} from '@ui5/webcomponents-react';
9+
import 'components/Modules/community/components/CommunityModulesSourcesList.scss';
10+
import { AddSourceYamls } from './AddSourceYamls';
11+
import { useContext, useState } from 'react';
12+
import { ModuleTemplatesContext } from 'components/Modules/providers/ModuleTemplatesProvider';
13+
import { Spinner } from 'shared/components/Spinner/Spinner';
14+
import { HintButton } from 'shared/components/HintButton/HintButton';
15+
16+
const ListElements = ({ sources }: { sources: string[] }) => {
17+
const { t } = useTranslation();
18+
19+
if (!sources.length) {
20+
return (
21+
<ListItemStandard
22+
text={t('modules.community.source-yaml.no-source-yaml')}
23+
/>
24+
);
25+
}
26+
return (
27+
<>
28+
{sources.map((sourceYaml, ind) => (
29+
<ListItemStandard key={`${ind}-${sourceYaml}`}>
30+
<Link design="Default" href={sourceYaml} target="_blank">
31+
{sourceYaml}
32+
</Link>
33+
</ListItemStandard>
34+
))}
35+
</>
36+
);
37+
};
38+
39+
export const CommunityModulesSourcesList = () => {
40+
const { t } = useTranslation();
41+
const { moduleTemplatesLoading, communityModuleTemplates } = useContext(
42+
ModuleTemplatesContext,
43+
);
44+
const [showTitleDescription, setShowTitleDescription] = useState(false);
45+
46+
const getSources = () => {
47+
const sources = (communityModuleTemplates?.items ?? [])
48+
.map((item: any) => {
49+
return item?.metadata?.annotations?.source;
50+
})
51+
.filter(Boolean);
52+
return [...new Set(sources)];
53+
};
54+
55+
return (
56+
<Card
57+
className="sap-margin-top-small"
58+
accessibleName={t('modules.community.source-yaml.source-yamls-header')}
59+
header={
60+
<div className="card-header">
61+
<div className="card-header__title">
62+
<Title level="H5">
63+
{t('modules.community.source-yaml.source-yamls-header')}
64+
</Title>
65+
<HintButton
66+
className="sap-margin-begin-tiny"
67+
setShowTitleDescription={setShowTitleDescription}
68+
description={t(
69+
'modules.community.source-yaml.add-source-yaml-info',
70+
)}
71+
showTitleDescription={showTitleDescription}
72+
ariaTitle={t('modules.community.source-yaml.source-yamls-header')}
73+
/>
74+
</div>
75+
<AddSourceYamls />
76+
</div>
77+
}
78+
>
79+
<List
80+
// TODO: Delete will be implemented in the next task.
81+
onItemDelete={(e) => console.log('DELETE', e)}
82+
selectionMode="None" // change to => 'Delete' once deleting is implemented
83+
separators="Inner"
84+
className="list-top-separator"
85+
>
86+
{moduleTemplatesLoading ? (
87+
<Spinner />
88+
) : (
89+
<ListElements sources={getSources()} />
90+
)}
91+
</List>
92+
</Card>
93+
);
94+
};

src/resources/other/kymaModules.routes.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { usePrepareLayoutColumns } from 'shared/hooks/usePrepareLayout';
1616
import { KymaModuleContextProvider } from 'components/Modules/providers/KymaModuleProvider';
1717
import { ModuleTemplatesContextProvider } from 'components/Modules/providers/ModuleTemplatesProvider';
1818
import { CommunityModulesDeleteBoxContextProvider } from 'components/Modules/community/components/CommunityModulesDeleteBox';
19-
import { AddSourceYamls } from 'components/Modules/community/components/AddSourceYamls';
2019
import { CommunityModuleContextProvider } from 'components/Modules/community/providers/CommunityModuleProvider';
2120
import { CommunityModulesUploadProvider } from 'components/Modules/community/providers/CommunitModulesInstalationProvider';
2221
import YamlUploadDialog from 'resources/Namespaces/YamlUpload/YamlUploadDialog';
@@ -101,8 +100,6 @@ const ColumnWrapper = ({
101100
</div>,
102101
);
103102

104-
const addSourceYAMLsButton = <AddSourceYamls />;
105-
106103
const midColumnComponent = (
107104
<>
108105
{/* details */}
@@ -137,7 +134,6 @@ const ColumnWrapper = ({
137134
{layoutState?.showCreate?.createType === 'community' && (
138135
<ResourceCreate
139136
title={t('modules.community.add-module')}
140-
headerActions={addSourceYAMLsButton}
141137
confirmText={t('common.buttons.add')}
142138
layoutCloseCreateUrl={url}
143139
renderForm={(renderProps) => {

0 commit comments

Comments
 (0)