Skip to content
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

chore: support additional contents - catalog #3215

Merged
merged 70 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
60b0480
add content mapping - wip
taban03 Nov 8, 2023
d4f3654
fix slint
taban03 Nov 9, 2023
d550465
embed medium blogs
taban03 Nov 9, 2023
79ca689
remove config
taban03 Nov 9, 2023
60026b9
fix
taban03 Nov 10, 2023
938f8ec
add expandable icons
taban03 Nov 14, 2023
20fdc24
wip - use cases work
taban03 Nov 14, 2023
e41e79f
format cases
taban03 Nov 14, 2023
005a7d2
fix
taban03 Nov 14, 2023
72d5b87
open new tab for links
taban03 Nov 14, 2023
306ec23
embed internal doc
taban03 Nov 16, 2023
8e9aa3f
adjusting based on the design decision
taban03 Nov 16, 2023
37d9eea
fix css
taban03 Nov 16, 2023
22910e9
fix
taban03 Nov 16, 2023
ce9bc0b
fix
taban03 Nov 16, 2023
070f9be
fix window size
taban03 Nov 16, 2023
f72b7ed
fix css
taban03 Nov 16, 2023
cb5fabe
fix
taban03 Nov 16, 2023
8f85c38
fix margin between videos
taban03 Nov 16, 2023
0feabc2
revert back
taban03 Nov 21, 2023
6f66f10
fix label name
taban03 Nov 21, 2023
44d1a1f
add check for title and description
taban03 Nov 21, 2023
c0f8448
disable link
taban03 Nov 21, 2023
120c5bf
add tests
taban03 Nov 21, 2023
c077c66
fix
taban03 Nov 22, 2023
6fc6195
clean up of codea nd tests
taban03 Nov 22, 2023
d381375
clean up
taban03 Nov 22, 2023
d2746ea
increase default counter
taban03 Nov 22, 2023
db1d68f
revert back tests
taban03 Nov 22, 2023
0c3c810
add margin to blogs
taban03 Nov 22, 2023
e759b49
fix button
taban03 Nov 24, 2023
ec43138
support zowe doc tutorials
taban03 Nov 24, 2023
0a381f3
fix testa
taban03 Nov 24, 2023
3302c03
fix test
taban03 Nov 27, 2023
855d5b8
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Nov 27, 2023
9244e07
increase coverage
taban03 Nov 27, 2023
3d94e76
reduce complexity
taban03 Nov 27, 2023
3c2c09f
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Nov 28, 2023
78289a4
fix code smells
taban03 Nov 28, 2023
ee205b6
fix
taban03 Nov 28, 2023
55dea9f
fix code smells
taban03 Nov 28, 2023
1718605
fix code smell
taban03 Nov 28, 2023
11afb48
fix bug
taban03 Nov 28, 2023
19f42c7
add tests
taban03 Nov 29, 2023
fa00717
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Nov 29, 2023
d442cb6
fix bug
taban03 Nov 29, 2023
68cd912
add test
taban03 Nov 29, 2023
b7415dc
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Nov 29, 2023
1c07318
fix test
taban03 Nov 29, 2023
33ed2f4
refactoring
taban03 Nov 29, 2023
3c0250c
fix test
taban03 Nov 29, 2023
d3f1b7e
fix
taban03 Nov 29, 2023
4b86c51
optymize
taban03 Nov 29, 2023
e595483
fix
taban03 Nov 30, 2023
01c6c6d
add tests
taban03 Nov 30, 2023
f31b586
fix test
taban03 Nov 30, 2023
fc37803
add test
taban03 Nov 30, 2023
3b21b93
add tests
taban03 Dec 1, 2023
0199683
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 1, 2023
326b31c
fix
taban03 Dec 1, 2023
539159e
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 2, 2023
c103b2d
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 4, 2023
e2a6cae
fix issue with description
taban03 Dec 7, 2023
d3c5455
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 8, 2023
868999d
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 8, 2023
ee50c2e
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 8, 2023
39999b6
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 8, 2023
b3e2188
add test
taban03 Dec 11, 2023
b348c28
add test
taban03 Dec 11, 2023
416c616
Merge branch 'v2.x.x' into reboot/poc_additional_contents_portal
taban03 Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions api-catalog-ui/frontend/src/components/DetailPage/DetailPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class DetailPage extends Component {
history,
currentTileId,
fetchNewTiles,
selectedService,
} = this.props;
let { tiles } = this.props;
const iconBack = <ChevronLeftIcon />;
Expand All @@ -102,7 +103,15 @@ export default class DetailPage extends Component {
}
const apiPortalEnabled = isAPIPortal();
const hasTiles = !fetchTilesError && tiles && tiles.length > 0;
const { useCasesCounter, tutorialsCounter, videosCounter } = countAdditionalContents(services);
const {
useCasesCounter,
tutorialsCounter,
videosCounter,
filteredUseCases,
filteredTutorials,
videos,
documentation,
} = countAdditionalContents(selectedService);
const onlySwaggerPresent = tutorialsCounter === 0 && videosCounter === 0 && useCasesCounter === 0;
const showSideBar = false;
if (
Expand Down Expand Up @@ -202,7 +211,7 @@ export default class DetailPage extends Component {
className="links"
onClick={(e) => this.handleLinkClick(e, '#tutorials-label')}
>
Tutorials ({tutorialsCounter})
TechDocs Resources ({tutorialsCounter})
pablocarle marked this conversation as resolved.
Show resolved Hide resolved
</Link>
<Link
className="links"
Expand Down Expand Up @@ -236,9 +245,13 @@ export default class DetailPage extends Component {
render={() => (
<div className="tabs-swagger">
<ServiceTabContainer
videos={videos}
useCases={filteredUseCases}
tutorials={filteredTutorials}
videosCounter={videosCounter}
tutorialsCounter={tutorialsCounter}
useCasesCounter={useCasesCounter}
documentation={documentation}
tiles={tiles}
/>
</div>
Expand Down Expand Up @@ -271,4 +284,5 @@ DetailPage.propTypes = {
history: PropTypes.shape({
push: PropTypes.func.isRequired,
}).isRequired,
selectedService: PropTypes.object.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright Contributors to the Zowe Project.
*/
import { shallow } from 'enzyme';
import { describe, expect, it, jest } from '@jest/globals';
import { describe, expect, it } from '@jest/globals';
import DetailPage from './DetailPage';

const tile = {
Expand Down Expand Up @@ -51,6 +51,10 @@ describe('>>> Detailed Page component tests', () => {
process.env.REACT_APP_API_PORTAL = false;
});

afterEach(() => {
jest.clearAllMocks();
});

it('should start epic on mount', () => {
const fetchTilesStart = jest.fn();
const fetchNewTiles = jest.fn();
Expand Down Expand Up @@ -252,9 +256,19 @@ describe('>>> Detailed Page component tests', () => {
process.env.REACT_APP_API_PORTAL = true;
const fetchTilesStart = jest.fn();
const fetchNewTiles = jest.fn();
tile.services[0].videos = ['video1', 'video2'];
tile.services[0].tutorials = ['tutorial1', 'tutorial2'];
tile.services[0].useCases = ['useCase1', 'useCase2'];
// eslint-disable-next-line global-require
const utils = require('../../utils/utilFunctions');
const spyOnCountAdditionalContents = jest.spyOn(utils, 'default');
spyOnCountAdditionalContents.mockImplementation(() => ({
useCasesCounter: 2,
tutorialsCounter: 2,
videosCounter: 2,
hasSwagger: true,
useCases: [],
tutorials: [],
videos: [],
documentation: '',
}));
const wrapper = shallow(
<DetailPage
tiles={[tile]}
Expand All @@ -268,6 +282,7 @@ describe('>>> Detailed Page component tests', () => {
/>
);
expect(wrapper.find('#right-resources-menu').exists()).toEqual(true);
spyOnCountAdditionalContents.mockRestore();
});

it('should click on the links', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mapStateToProps = (state) => ({
fetchTilesError: state.tilesReducer.error,
selectedTile: state.selectedServiceReducer.selectedTile,
selectedServiceId: state.selectedServiceReducer.selectedService.serviceId,
selectedService: state.selectedServiceReducer.selectedService,
taban03 marked this conversation as resolved.
Show resolved Hide resolved
isLoading: loadingSelector(state),
currentTileId: state.tilesReducer.currentTileId,
});
Expand Down
110 changes: 110 additions & 0 deletions api-catalog-ui/frontend/src/components/ExtraContents/BlogContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import BlogTile from './BlogTile';

export default function BlogContainer({ user, url, title }) {
const rss2json = `https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40${user}`;
const [myBlog, setMyBlog] = useState([]);

const fetchData = async () => {
try {
const res = await fetch(url);
const data = await res.text();

const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
const divs = doc.querySelector('.linklist.relatedlinks');
if (divs) {
divs.parentNode.removeChild(divs);
}

let content = doc.querySelector('.shortdesc');
if (!content?.textContent) {
content = doc.querySelector('.p');
}
const tutorialTitle = doc.querySelector('h1.title');
const blogTitle = tutorialTitle?.textContent;
const blogContent = content?.textContent;

const blogData = {
content: blogContent,
description: blogContent,
title: blogTitle,
link: url,
};

setMyBlog(blogData);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching data:', error);
return null;
}
};

useEffect(() => {
const fetchDataEffect = async () => {
if (!url?.includes('medium.com') && !url?.includes('docs.zowe.org')) {
await fetchData();
} else if (url?.includes('docs.zowe.org')) {
const blogData = {
content: '',
description: `Tutorial from the Zowe documentation related to ${title}`,
title,
link: url,
};
setMyBlog(blogData);
} else {
try {
const res = await fetch(rss2json);
const data = await res.json();
setMyBlog(data);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching data:', error);
return null;
}
}
};

fetchDataEffect();
}, [rss2json]);

function displayBlogs() {
taban03 marked this conversation as resolved.
Show resolved Hide resolved
if (myBlog?.items) {
const correctBlog = myBlog.items.find((blog) => blog?.link.includes(url));
return correctBlog && <BlogTile blogData={correctBlog} />;
}
}
if (url?.includes('medium.com')) {
taban03 marked this conversation as resolved.
Show resolved Hide resolved
return (
<div data-testid="medium-blog-container" className="BlogsContainer">
{displayBlogs()}
</div>
);
}

return (
myBlog && (
<div data-testid="tech-blog-container" className="BlogsContainer">
<BlogTile blogData={myBlog} />
</div>
)
);
}

BlogContainer.propTypes = {
url: PropTypes.shape({
includes: PropTypes.func.isRequired,
}).isRequired,
user: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
};
Loading
Loading