-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate optimizations summary to federated module
- Loading branch information
Showing
19 changed files
with
269 additions
and
20 deletions.
There are no files selected for viewing
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
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,26 @@ | ||
/* eslint-disable no-console */ | ||
import IntlProvider from '@redhat-cloud-services/frontend-components-translations/Provider'; | ||
import { getLocale } from 'components/i18n'; | ||
import React from 'react'; | ||
import { OptimizationsSummary } from 'routes/optimizations/optimizationsSummary'; | ||
|
||
// eslint-disable-next-line no-restricted-imports | ||
import messages from '../../locales/data.json'; | ||
|
||
export interface OptimizationsSummaryOwnProps { | ||
toPath?: string; | ||
} | ||
|
||
type OptimizationsSummaryProps = OptimizationsSummaryOwnProps; | ||
|
||
const MfeOptimizationsSummary: React.FC<OptimizationsSummaryProps> = ({ toPath }: OptimizationsSummaryOwnProps) => { | ||
const locale = getLocale(); | ||
|
||
return ( | ||
<IntlProvider defaultLocale="en" locale={locale} messages={messages[locale]} onError={console.log}> | ||
<OptimizationsSummary toPath={toPath} /> | ||
</IntlProvider> | ||
); | ||
}; | ||
|
||
export default MfeOptimizationsSummary; |
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,2 @@ | ||
export * from './optimizationsSummary'; | ||
export { default as OptimizationsSummaryDemo } from './optimizationsSummaryDemo'; |
8 changes: 8 additions & 0 deletions
8
src/routes/optimizations/optimizationsSummary/optimizations.styles.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,8 @@ | ||
import global_FontSize_md from '@patternfly/react-tokens/dist/js/global_FontSize_md'; | ||
import type React from 'react'; | ||
|
||
export const styles = { | ||
infoIcon: { | ||
fontSize: global_FontSize_md.value, | ||
}, | ||
} as { [className: string]: React.CSSProperties }; |
11 changes: 11 additions & 0 deletions
11
src/routes/optimizations/optimizationsSummary/optimizationsSummary.scss
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,11 @@ | ||
@import url("~@patternfly/patternfly/base/patternfly-variables.css"); | ||
|
||
.skeleton { | ||
height: 125px; | ||
margin-bottom: var(--pf-v5-global--spacer--md); | ||
margin-top: var(--pf-v5-global--spacer--md); | ||
} | ||
|
||
.summary { | ||
height: 100%; | ||
} |
122 changes: 122 additions & 0 deletions
122
src/routes/optimizations/optimizationsSummary/optimizationsSummary.tsx
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,122 @@ | ||
import { | ||
Button, | ||
ButtonVariant, | ||
Card, | ||
CardBody, | ||
CardTitle, | ||
Popover, | ||
Skeleton, | ||
Title, | ||
TitleSizes, | ||
} from '@patternfly/react-core'; | ||
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon'; | ||
import { getQuery } from 'api/queries/query'; | ||
import type { RosReport } from 'api/ros/ros'; | ||
import { RosPathsType, RosType } from 'api/ros/ros'; | ||
import type { AxiosError } from 'axios'; | ||
import messages from 'locales/messages'; | ||
import React, { useEffect } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import type { AnyAction } from 'redux'; | ||
import type { ThunkDispatch } from 'redux-thunk'; | ||
import { skeletonWidth } from 'routes/utils/skeleton'; | ||
import type { RootState } from 'store'; | ||
import { FetchStatus } from 'store/common'; | ||
import { rosActions, rosSelectors } from 'store/ros'; | ||
|
||
import { styles } from './optimizations.styles'; | ||
|
||
export interface OptimizationsSummaryOwnProps { | ||
toPath?: string; | ||
} | ||
|
||
export interface OptimizationsSummaryStateProps { | ||
report?: RosReport; | ||
reportError?: AxiosError; | ||
reportFetchStatus?: FetchStatus; | ||
reportQueryString?: string; | ||
} | ||
|
||
type OptimizationsSummaryProps = OptimizationsSummaryOwnProps & OptimizationsSummaryStateProps; | ||
|
||
const reportPathsType = RosPathsType.recommendations; | ||
const reportType = RosType.ros; | ||
|
||
const OptimizationsSummary: React.FC<OptimizationsSummaryProps> = ({ toPath }: OptimizationsSummaryOwnProps) => { | ||
const intl = useIntl(); | ||
const { report, reportFetchStatus } = useMapToProps(); | ||
|
||
const count = report?.meta ? report.meta.count : 0; | ||
const description = intl.formatMessage(messages.optimizationsDetails, { count }); | ||
|
||
return ( | ||
<Card className="summary"> | ||
<CardTitle> | ||
<Title headingLevel="h2" size={TitleSizes.lg}> | ||
{intl.formatMessage(messages.optimizations)} Test | ||
<span style={styles.infoIcon}> | ||
<Popover | ||
aria-label={intl.formatMessage(messages.optimizationsInfoArialLabel)} | ||
enableFlip | ||
bodyContent={<p style={styles.infoTitle}>{intl.formatMessage(messages.optimizationsInfo)}</p>} | ||
> | ||
<Button | ||
aria-label={intl.formatMessage(messages.optimizationsInfoButtonArialLabel)} | ||
variant={ButtonVariant.plain} | ||
> | ||
<OutlinedQuestionCircleIcon /> | ||
</Button> | ||
</Popover> | ||
</span> | ||
</Title> | ||
</CardTitle> | ||
<CardBody> | ||
{reportFetchStatus === FetchStatus.inProgress ? ( | ||
<> | ||
<Skeleton width="16%" /> | ||
<Skeleton className="skeleton" width={skeletonWidth.md} /> | ||
</> | ||
) : toPath && count > 0 ? ( | ||
<Link to={toPath}>{description}</Link> | ||
) : ( | ||
description | ||
)} | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
const useMapToProps = (): OptimizationsSummaryStateProps => { | ||
const dispatch: ThunkDispatch<RootState, any, AnyAction> = useDispatch(); | ||
|
||
const reportQuery: any = { | ||
// TBD... | ||
}; | ||
const reportQueryString = getQuery(reportQuery); | ||
const report: any = useSelector((state: RootState) => | ||
rosSelectors.selectRos(state, reportPathsType, reportType, reportQueryString) | ||
); | ||
const reportFetchStatus = useSelector((state: RootState) => | ||
rosSelectors.selectRosFetchStatus(state, reportPathsType, reportType, reportQueryString) | ||
); | ||
const reportError = useSelector((state: RootState) => | ||
rosSelectors.selectRosError(state, reportPathsType, reportType, reportQueryString) | ||
); | ||
|
||
useEffect(() => { | ||
if (!reportError && reportFetchStatus !== FetchStatus.inProgress) { | ||
dispatch(rosActions.fetchRosReport(reportPathsType, reportType, reportQueryString)); | ||
} | ||
}, [reportQueryString]); | ||
|
||
return { | ||
report, | ||
reportError, | ||
reportFetchStatus, | ||
reportQueryString, | ||
}; | ||
}; | ||
|
||
export { OptimizationsSummary }; |
Oops, something went wrong.