From e585d1c0448e4e2f8556957181b0ad0e9e40554f Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 15 Aug 2021 17:00:38 +0800 Subject: [PATCH] refactor: nodata --- web/src/components/AlertErrorView.tsx | 3 +- web/src/components/NoData.tsx | 14 ++ web/src/components/__tests__/NoData.spec.tsx | 15 ++ .../AlertErrorView.spec.tsx.snap | 16 +- .../__snapshots__/NoData.spec.tsx.snap | 155 ++++++++++++++++++ 5 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 web/src/components/NoData.tsx create mode 100644 web/src/components/__tests__/NoData.spec.tsx create mode 100644 web/src/components/__tests__/__snapshots__/NoData.spec.tsx.snap diff --git a/web/src/components/AlertErrorView.tsx b/web/src/components/AlertErrorView.tsx index 7448b6c4..28fb8548 100644 --- a/web/src/components/AlertErrorView.tsx +++ b/web/src/components/AlertErrorView.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { Alert, Button } from 'antd'; import clsx from 'clsx'; +import { t } from 'tailchat-shared'; /** * 用于接口错误显示的组件 @@ -20,7 +21,7 @@ export const AlertErrorView: React.FC<{ type="link" onClick={() => setShow(true)} > - 显示详情 + {t('显示详情')} {show &&
{String(error.stack)}
} diff --git a/web/src/components/NoData.tsx b/web/src/components/NoData.tsx new file mode 100644 index 00000000..1ad61d97 --- /dev/null +++ b/web/src/components/NoData.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { Empty } from 'antd'; + +interface NoDataProps { + message?: string; +} + +/** + * 没有数据或没找到数据 + */ +export const NoData: React.FC = React.memo((props) => { + return ; +}); +NoData.displayName = 'NoData'; diff --git a/web/src/components/__tests__/NoData.spec.tsx b/web/src/components/__tests__/NoData.spec.tsx new file mode 100644 index 00000000..f62bd0aa --- /dev/null +++ b/web/src/components/__tests__/NoData.spec.tsx @@ -0,0 +1,15 @@ +import { render } from '@testing-library/react'; +import React from 'react'; +import { NoData } from '../NoData'; + +describe('NoData', () => { + test('render', () => { + const wrapper = render(); + expect(wrapper.container).toMatchSnapshot(); + }); + + test('render with text', () => { + const wrapper = render(); + expect(wrapper.container).toMatchSnapshot(); + }); +}); diff --git a/web/src/components/__tests__/__snapshots__/AlertErrorView.spec.tsx.snap b/web/src/components/__tests__/__snapshots__/AlertErrorView.spec.tsx.snap index 611c0702..e599b261 100644 --- a/web/src/components/__tests__/__snapshots__/AlertErrorView.spec.tsx.snap +++ b/web/src/components/__tests__/__snapshots__/AlertErrorView.spec.tsx.snap @@ -3,7 +3,7 @@ exports[`AlertErrorView render 1`] = `
diff --git a/web/src/components/__tests__/__snapshots__/NoData.spec.tsx.snap b/web/src/components/__tests__/__snapshots__/NoData.spec.tsx.snap new file mode 100644 index 00000000..52f3f635 --- /dev/null +++ b/web/src/components/__tests__/__snapshots__/NoData.spec.tsx.snap @@ -0,0 +1,155 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`NoData render 1`] = ` +
+
+
+ + + + + + + + + + + + + + + + +
+
+ No Data +
+
+
+`; + +exports[`NoData render with text 1`] = ` +
+
+
+ + + + + + + + + + + + + + + + +
+
+ 无数据 +
+
+
+`;