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
14 changed files
with
324 additions
and
158 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
frontend/src/component/application/ApplicationIssues/ApplicationIssues.test.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,27 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { ApplicationIssues } from './ApplicationIssues'; | ||
import { ApplicationOverviewIssuesSchema } from 'openapi'; | ||
|
||
test('Display all application issues', async () => { | ||
const issues: ApplicationOverviewIssuesSchema[] = [ | ||
{ | ||
type: 'missingFeatures', | ||
items: ['my-app'], | ||
}, | ||
{ | ||
type: 'missingStrategies', | ||
items: ['defaultStrategy', 'mainStrategy'], | ||
}, | ||
]; | ||
render(<ApplicationIssues issues={issues} />); | ||
|
||
await screen.findByText('my-app'); | ||
await screen.findByText('mainStrategy'); | ||
await screen.findByText( | ||
`We detected 1 feature flag defined in the SDK that does not exist in Unleash`, | ||
); | ||
await screen.findByText( | ||
`We detected 2 strategy types defined in the SDK that do not exist in Unleash`, | ||
); | ||
}); |
117 changes: 117 additions & 0 deletions
117
frontend/src/component/application/ApplicationIssues/ApplicationIssues.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,117 @@ | ||
import { Box, styled } from '@mui/material'; | ||
import { ConditionallyRender } from '../../common/ConditionallyRender/ConditionallyRender'; | ||
import { WarningAmberRounded } from '@mui/icons-material'; | ||
import { ApplicationOverviewIssuesSchema } from 'openapi'; | ||
|
||
const WarningContainer = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
paddingBottom: theme.spacing(8), | ||
})); | ||
|
||
const WarningHeader = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
padding: theme.spacing(2, 3, 2, 3), | ||
alignItems: 'flex-start', | ||
gap: theme.spacing(1.5), | ||
alignSelf: 'stretch', | ||
borderRadius: `${theme.shape.borderRadiusLarge}px ${theme.shape.borderRadiusLarge}px 0 0`, | ||
border: `1px solid ${theme.palette.warning.border}`, | ||
background: theme.palette.warning.light, | ||
})); | ||
|
||
const SmallText = styled(Box)(({ theme }) => ({ | ||
fontSize: theme.fontSizes.smallBody, | ||
})); | ||
|
||
const WarningHeaderText = styled(SmallText)(({ theme }) => ({ | ||
color: theme.palette.warning.dark, | ||
fontWeight: theme.fontWeight.bold, | ||
})); | ||
|
||
const StyledList = styled('ul')(({ theme }) => ({ | ||
padding: theme.spacing(0, 0, 0, 2), | ||
})); | ||
|
||
const StyledListElement = styled('li')(({ theme }) => ({ | ||
fontWeight: theme.fontWeight.bold, | ||
fontSize: theme.fontSizes.smallBody, | ||
})); | ||
|
||
const IssueContainer = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
padding: theme.spacing(3), | ||
flexDirection: 'column', | ||
alignItems: 'flex-start', | ||
alignSelf: 'stretch', | ||
gap: theme.spacing(3), | ||
borderRadius: ` 0 0 ${theme.shape.borderRadiusLarge}px ${theme.shape.borderRadiusLarge}px`, | ||
border: `1px solid ${theme.palette.warning.border}`, | ||
})); | ||
|
||
const IssueTextContainer = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
padding: theme.spacing(2), | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'flex-start', | ||
alignSelf: 'stretch', | ||
gap: theme.spacing(0.5), | ||
borderRadius: theme.spacing(1), | ||
border: `1px solid ${theme.palette.divider}`, | ||
})); | ||
|
||
export interface IApplicationIssuesProps { | ||
issues: ApplicationOverviewIssuesSchema[]; | ||
} | ||
|
||
const resolveIssueText = (issue: ApplicationOverviewIssuesSchema) => { | ||
const issueCount = issue.items.length; | ||
let issueText = ''; | ||
|
||
switch (issue.type) { | ||
case 'missingFeatures': | ||
issueText = `feature flag${issueCount !== 1 ? 's' : ''}`; | ||
break; | ||
case 'missingStrategies': | ||
issueText = `strategy type${issueCount !== 1 ? 's' : ''}`; | ||
break; | ||
} | ||
|
||
return `We detected ${issueCount} ${issueText} defined in the SDK that ${ | ||
issueCount !== 1 ? 'do' : 'does' | ||
} not exist in Unleash`; | ||
}; | ||
|
||
export const ApplicationIssues = ({ issues }: IApplicationIssuesProps) => { | ||
return ( | ||
<ConditionallyRender | ||
condition={issues.length > 0} | ||
show={ | ||
<WarningContainer> | ||
<WarningHeader> | ||
<WarningAmberRounded /> | ||
<WarningHeaderText> | ||
We detected {issues.length} issues in this | ||
application | ||
</WarningHeaderText> | ||
</WarningHeader> | ||
<IssueContainer> | ||
{issues.map((issue) => ( | ||
<IssueTextContainer key={issue.type}> | ||
<SmallText>{resolveIssueText(issue)}</SmallText> | ||
<StyledList> | ||
{issue.items.map((item) => ( | ||
<StyledListElement key={item}> | ||
{item} | ||
</StyledListElement> | ||
))} | ||
</StyledList> | ||
</IssueTextContainer> | ||
))} | ||
</IssueContainer> | ||
</WarningContainer> | ||
} | ||
/> | ||
); | ||
}; |
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
Oops, something went wrong.