-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
237 additions
and
24 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/components/content/order/common/utils/groupServicesByLatestVersion.ts
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,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { UserOrderableServiceVo } from '../../../../../xpanse-api/generated'; | ||
import { sortVersion } from '../../../../utils/Sort.ts'; | ||
import { UserServiceLatestVersionDisplayType } from '../../services/UserServiceLatestVersionDisplayType.ts'; | ||
import { groupServicesByName, groupVersionsForService } from '../../services/userServiceHelper.ts'; | ||
|
||
export function groupServicesByLatestVersion( | ||
allServices: UserOrderableServiceVo[], | ||
filterByServiceName: string | ||
): UserServiceLatestVersionDisplayType[] { | ||
const serviceList: UserServiceLatestVersionDisplayType[] = []; | ||
const servicesGroupedByName: Map<string, UserOrderableServiceVo[]> = groupServicesByName(allServices); | ||
servicesGroupedByName.forEach((orderableServicesList, _) => { | ||
const versionMapper: Map<string, UserOrderableServiceVo[]> = groupVersionsForService(orderableServicesList); | ||
const versionList: string[] = Array.from(versionMapper.keys()); | ||
const latestVersion = sortVersion(versionList)[0]; | ||
if (versionMapper.has(latestVersion) && versionMapper.get(latestVersion)) { | ||
if (versionMapper.get(latestVersion)?.[0].name.includes(filterByServiceName)) { | ||
const serviceItem = { | ||
name: versionMapper.get(latestVersion)?.[0].name, | ||
content: versionMapper.get(latestVersion)?.[0].description, | ||
icon: versionMapper.get(latestVersion)?.[0].icon, | ||
latestVersion: latestVersion, | ||
category: versionMapper.get(latestVersion)?.[0].category, | ||
}; | ||
serviceList.push(serviceItem as UserServiceLatestVersionDisplayType); | ||
} | ||
} | ||
}); | ||
return serviceList; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { AlertTwoTone, LoadingOutlined, SearchOutlined } from '@ant-design/icons'; | ||
import { Button, Input, Modal, Space } from 'antd'; | ||
import { SearchProps } from 'antd/lib/input'; | ||
import { useMemo, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import appStyles from '../../../styles/app.module.css'; | ||
import searchServiceStyle from '../../../styles/search-services.module.css'; | ||
import { category } from '../../../xpanse-api/generated'; | ||
import { groupServicesByLatestVersion } from '../../content/order/common/utils/groupServicesByLatestVersion.ts'; | ||
import userOrderableServicesQuery from '../../content/order/query/userOrderableServicesQuery.ts'; | ||
import { UserServiceLatestVersionDisplayType } from '../../content/order/services/UserServiceLatestVersionDisplayType.ts'; | ||
import { createServicePageRoute } from '../../utils/constants.tsx'; | ||
|
||
export function SearchServices() { | ||
const navigate = useNavigate(); | ||
const orderableServicesQuery = userOrderableServicesQuery(undefined, undefined); | ||
const [isSearchClicked, setIsSearchClicked] = useState<boolean>(false); | ||
const [searchText, setSearchText] = useState<string>(''); | ||
const { Search } = Input; | ||
const onSelectService = function (serviceName: string, latestVersion: string, category: category) { | ||
setIsSearchClicked(false); | ||
setSearchText(''); | ||
navigate( | ||
createServicePageRoute | ||
.concat('?serviceName=', serviceName) | ||
.concat('&latestVersion=', latestVersion.replace(' ', '')) | ||
.concat('#', category) | ||
); | ||
}; | ||
|
||
const onSearch: SearchProps['onSearch'] = (value, _e, _info) => { | ||
setSearchText(value); | ||
}; | ||
|
||
const filteredServices: UserServiceLatestVersionDisplayType[] = useMemo(() => { | ||
let serviceList: UserServiceLatestVersionDisplayType[] = []; | ||
if (orderableServicesQuery.data && searchText) { | ||
serviceList = groupServicesByLatestVersion(orderableServicesQuery.data, searchText); | ||
} | ||
return serviceList; | ||
}, [orderableServicesQuery.data, searchText]); | ||
|
||
const retryRequest = () => { | ||
void orderableServicesQuery.refetch(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Modal | ||
title='Search Services' | ||
width={1000} | ||
open={isSearchClicked} | ||
onCancel={() => { | ||
setIsSearchClicked(false); | ||
setSearchText(''); | ||
}} | ||
footer={null} | ||
> | ||
<Search | ||
loading={false} | ||
onSearch={onSearch} | ||
value={searchText} | ||
onChange={(e) => { | ||
setSearchText(e.target.value); | ||
}} | ||
/> | ||
{searchText.length > 0 ? ( | ||
filteredServices.length > 0 ? ( | ||
filteredServices.map((service) => { | ||
return ( | ||
<div key={service.name}> | ||
<Button | ||
onClick={() => { | ||
onSelectService(service.name, service.latestVersion, service.category); | ||
}} | ||
type={'link'} | ||
className={searchServiceStyle.searchResults} | ||
> | ||
{service.name} | ||
</Button> | ||
<Space>{service.content}</Space> | ||
</div> | ||
); | ||
}) | ||
) : orderableServicesQuery.isError ? ( | ||
<div className={searchServiceStyle.searchErrorBlock}> | ||
<AlertTwoTone twoToneColor='#eb2f96' className={searchServiceStyle.searchErrorIcon} /> | ||
<div className={searchServiceStyle.searchResults}> | ||
{'Error loading services - ' + orderableServicesQuery.error.toString()} | ||
</div> | ||
<Button | ||
type={'link'} | ||
onClick={retryRequest} | ||
className={searchServiceStyle.searchErrorRetryButton} | ||
> | ||
retry | ||
</Button> | ||
</div> | ||
) : orderableServicesQuery.isLoading ? ( | ||
<div className={searchServiceStyle.searchServicesLoading}> | ||
<div className={searchServiceStyle.searchResults}>{'Loading Services'}</div> | ||
<LoadingOutlined spin className={searchServiceStyle.searchLoadingIcon} /> | ||
</div> | ||
) : ( | ||
<p className={searchServiceStyle.searchServicesNoMatchFound}> | ||
Your search <span className={searchServiceStyle.searchTextColor}>{searchText}</span> did not | ||
match any service names | ||
</p> | ||
) | ||
) : undefined} | ||
</Modal> | ||
<Button | ||
className={appStyles.headerMenuButton} | ||
icon={<SearchOutlined />} | ||
onClick={() => { | ||
setIsSearchClicked(true); | ||
}} | ||
> | ||
Search Services | ||
</Button> | ||
</> | ||
); | ||
} |
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,13 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
.user-info-spacing { | ||
margin-left: 15px; | ||
} | ||
|
||
.layout-header { | ||
width: 100%; | ||
background: #ffffff; | ||
} |
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,44 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
.search-results { | ||
padding-top: 10px; | ||
} | ||
|
||
.search-loading-icon { | ||
padding: 10px; | ||
margin-top: 5px; | ||
} | ||
|
||
.search-error-icon { | ||
padding-left: 15px; | ||
padding-right: 10px; | ||
margin-top: 5px; | ||
} | ||
|
||
.search-error-retry-button { | ||
padding: 10px; | ||
margin-top: 5px; | ||
} | ||
|
||
.search-services-loading { | ||
display: flex; | ||
margin: 0; | ||
padding-left: 15px; | ||
} | ||
|
||
.search-services-no-match-found { | ||
margin: 0; | ||
padding-left: 15px; | ||
padding-top: 8px; | ||
} | ||
|
||
.search-error-block { | ||
display: flex; | ||
} | ||
|
||
.search-text-color { | ||
color: #1677ff; | ||
} |