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

fix(sonar bugs): fix sonar bugs #205

Merged
merged 9 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
"dependencies": {
"@catena-x/portal-shared-components": "^2.0.14",
"@catena-x/portal-shared-components": "^2.0.18",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/error-message": "^2.0.1",
Expand Down
23 changes: 7 additions & 16 deletions src/components/pages/AdminBoardDetail/BoardContentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import {
Expand All @@ -39,20 +38,6 @@ import BoardTechnicalUserSetup from './components/BoardTechnicalUserSetup'
export default function BoardContentDetails({ item }: { item: AppDetails }) {
const { t } = useTranslation()
const navigate = useNavigate()
const [images, setImages] = useState<any>()

useEffect(() => {
if (item) {
const newPromies = CommonService.fetchLeadPictures(item.images, item.id)
Promise.all(newPromies)
.then((result) => {
setImages(result.flat())
})
.catch((err) => {
console.log(err)
})
}
}, [item])

return (
item && (
Expand All @@ -79,7 +64,13 @@ export default function BoardContentDetails({ item }: { item: AppDetails }) {
</div>
))}
</div>
{images && <ImageGallery gallery={images} modalWidth="900" />}
<ImageGallery
gallery={CommonService.imagesAndAppidToImageType(
item.images,
item.id
)}
modalWidth="900"
/>
<div className="divider-height" />
<BoardPrivacy item={item} />
<div className="divider-height" />
Expand Down
30 changes: 10 additions & 20 deletions src/components/pages/AppDetail/AppDetailContentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { useEffect, useState } from 'react'
import { useState } from 'react'
import {
Typography,
Navigation,
Expand Down Expand Up @@ -47,7 +47,6 @@ export default function AppDetailContentDetails({
}) {
const navigate = useNavigate()
const { t } = useTranslation()
const [images, setImages] = useState<any>()
const [selectedItem, setSelectedItem] = useState<string>('#description')

const navigationItems = [
Expand All @@ -73,19 +72,6 @@ export default function AppDetailContentDetails({
},
]

useEffect(() => {
if (item) {
const newPromies = CommonService.fetchLeadPictures(item.images, item.id)
Promise.all(newPromies)
.then((result) => {
setImages(result.flat())
})
.catch((err) => {
console.log(err)
})
}
}, [item])

return (
item && (
<>
Expand Down Expand Up @@ -122,11 +108,15 @@ export default function AppDetailContentDetails({
</Typography>
</div>
<div className="divider-height" />
{images && (
<div id="image-gallery">
<ImageGallery gallery={images} modalWidth="900" />
</div>
)}
<div id="image-gallery">
<ImageGallery
gallery={CommonService.imagesAndAppidToImageType(
item.images,
item.id
)}
modalWidth="900"
/>
</div>
<div className="divider-height" />
<AppDetailPrivacy item={item} />
<div className="divider-height" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,12 @@ export default function CommonValidateAndPublish({
statusData?.documents?.APP_IMAGE &&
statusData?.documents?.APP_IMAGE[0].documentId
) {
const newPromies = CommonService.fetchLeadPictures(
statusData?.documents?.APP_IMAGE,
id
setMultipleImages(
CommonService.imagesAndAppidToImageType(
statusData?.documents?.APP_IMAGE,
id
)
)
Promise.all(newPromies)
.then((result) => {
setMultipleImages(result.flat())
})
.catch((err) => {
console.log(err)
})
}
setDefaultValues(values)
reset(values)
Expand Down
3 changes: 2 additions & 1 deletion src/features/admin/serviceApiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export const apiSlice = createApi({
`/api/administration/serviceaccount/owncompany/serviceaccounts/${id}`,
}),
fetchServiceAccountRoles: builder.query<ServiceAccountRole[], void>({
query: () => `/api/administration/serviceaccount/user/roles?languageShortName=${i18next.language}`,
query: () =>
`/api/administration/serviceaccount/user/roles?languageShortName=${i18next.language}`,
}),
}),
})
Expand Down
58 changes: 14 additions & 44 deletions src/services/CommonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

import { getApiBase, getAssetBase } from './EnvironmentService'
import i18next from 'i18next'
import UserService from './UserService'
import { AppMarketplaceApp } from 'features/apps/apiSlice'
import { ImageType } from '@catena-x/portal-shared-components'
import { fetchImageWithToken } from './ImageService'

const getName = (app: AppMarketplaceApp) => app.name ?? ''
const getDescription = (app: AppMarketplaceApp) =>
Expand All @@ -48,48 +49,17 @@ const appToCard = (app: AppMarketplaceApp) => ({
},
})

const fetchLeadPictures = (images: string[], appId: string) => {
const promises = images?.map((image: any) => {
return [
new Promise((resolve, reject) => {
let url = ''
if (!image.documentId) {
url = `${getApiBase()}/api/apps/${appId}/appDocuments/${isValidPictureId(
image
)}`
} else {
url = `${getApiBase()}/api/apps/${appId}/appDocuments/${isValidPictureId(
image.documentId
)}`
}

return fetch(url, {
method: 'GET',
headers: {
authorization: `Bearer ${UserService.getToken()}`,
},
})
.then((response) => response.blob())
.then(
async (blob) =>
await new Promise((callback) => {
let reader = new FileReader()
reader.onload = function () {
resolve({
url: this.result,
text: '',
})
}
reader.readAsDataURL(blob)
})
)
}),
]
})

const newPromies = promises.map((promise) => Promise.all(promise))
return newPromies
}
const imagesAndAppidToImageType = (
images: string[],
appId: string
): ImageType[] =>
images?.map((image: any) => ({
url: `${getApiBase()}/api/apps/${appId}/appDocuments/${isValidPictureId(
image.documentId ?? image
)}`,
text: 'Catena-X',
loader: fetchImageWithToken,
}))

const isValidPictureId = (id: string) => {
return id === '00000000-0000-0000-0000-000000000000'
Expand Down Expand Up @@ -153,7 +123,7 @@ const CommonService = {
getCompanyRoles,
getUseCases,
getDataSpace,
fetchLeadPictures,
imagesAndAppidToImageType,
getRoleDescription,
getCompanyRoleUpdateData,
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10339,4 +10339,4 @@ yargs@^16.2.0:
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==