-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): add Rule index page (#89)
- Loading branch information
Showing
6 changed files
with
687 additions
and
2 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
5 changes: 5 additions & 0 deletions
5
packages/components/src/pages/Resources/RuleIndex/constants.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,5 @@ | ||
import { Client } from '@rsdoctor/types'; | ||
|
||
export const name = 'Rule Index'; | ||
|
||
export const route = Client.DoctorClientRoutes.RuleIndex; |
83 changes: 83 additions & 0 deletions
83
packages/components/src/pages/Resources/RuleIndex/index.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,83 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Rule } from '@rsdoctor/types'; | ||
import { Badge, Card, Space, Typography, Col, Row, Tag } from 'antd'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import { values } from 'lodash-es'; | ||
import { Title } from '../../../components/Title'; | ||
import { Size } from '../../../constants'; | ||
import { useUrlQuery } from '../../../utils'; | ||
|
||
export const Page: React.FC = () => { | ||
const query = useUrlQuery(); | ||
|
||
const defaultErrorCode = query[Rule.DoctorRuleClientConstant.UrlQueryForErrorCode] || ''; | ||
|
||
// @ts-ignore | ||
const [ruleMessage, setRuleMessage] = useState<Rule.RuleMessage>(Rule.RuleErrorMap[defaultErrorCode]); | ||
|
||
const dataSource = values(Rule.RuleErrorMap)!; | ||
|
||
useEffect(() => { | ||
window.scrollTo({ top: 0 }); | ||
}, []); | ||
|
||
return ( | ||
<Row gutter={Size.BasePadding / 2}> | ||
<Col span={8}> | ||
<Card title={<Title text="list of the error codes." />} bordered> | ||
<Space direction="vertical"> | ||
{dataSource.map((e, i) => ( | ||
<Space | ||
style={{ marginTop: i === 0 ? 0 : Size.BasePadding / 2, cursor: 'pointer' }} | ||
onClick={() => setRuleMessage(e)} | ||
key={e.code} | ||
align="center" | ||
> | ||
<Badge status="default" /> | ||
<Typography.Text code> | ||
<a>{e.code}</a> | ||
</Typography.Text> | ||
<Typography.Text style={{ color: ruleMessage && ruleMessage.code === e.code ? '#1890ff' : undefined }}> | ||
{e.title} | ||
</Typography.Text> | ||
</Space> | ||
))} | ||
</Space> | ||
</Card> | ||
</Col> | ||
<Col span={16}> | ||
{ruleMessage ? ( | ||
<Card | ||
title={ | ||
<Row justify="space-between"> | ||
<Space> | ||
<Typography.Text code>{ruleMessage.code}</Typography.Text> | ||
<Typography.Text>{ruleMessage.title}</Typography.Text> | ||
</Space> | ||
<div> | ||
<Tag>{ruleMessage.category}</Tag> | ||
</div> | ||
</Row> | ||
} | ||
bodyStyle={{ paddingTop: 0 }} | ||
bordered | ||
> | ||
<Typography.Paragraph> | ||
{ruleMessage.type === 'markdown' ? ( | ||
<ReactMarkdown>{ruleMessage.description}</ReactMarkdown> | ||
) : ( | ||
<Typography.Text>{ruleMessage.description}</Typography.Text> | ||
)} | ||
</Typography.Paragraph> | ||
</Card> | ||
) : ( | ||
<Card title={'This page lists all the error codes emitted by the Web Doctor.'} bordered> | ||
<Typography.Text>click the error code in left bar to show more details.</Typography.Text> | ||
</Card> | ||
)} | ||
</Col> | ||
</Row> | ||
); | ||
}; | ||
|
||
export * from './constants' |
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.