Skip to content

Commit

Permalink
chore(merge): Merge master branch and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Oct 23, 2023
2 parents 2be4b65 + a83e10a commit 0cc0f99
Show file tree
Hide file tree
Showing 28 changed files with 471 additions and 739 deletions.
2 changes: 1 addition & 1 deletion .dumi/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { webVitals } from './vitals';

webVitals({ debug: true });
webVitals({});
3 changes: 3 additions & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default defineConfig({
},
extraBabelPresets: [require.resolve('@emotion/babel-preset-css-prop')],
outputPath: 'site',
define: {
'process.env.VERCEL_ANALYTICS_ID': process.env.VERCEL_ANALYTICS_ID,
},
analytics: {
ga_v2: 'G-81Y5XPZY2E',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test:update": "NODE_OPTIONS=--max_old_space_size=4096 cross-env TZ=UTC jest --updateSnapshot",
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint --cache --ext .js,.jsx,.ts,.tsx --fix --format=pretty",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,less,md,json}\"",
"tsc": "tsc --noEmit",
"tsc:clean": "tsc --build --clean",
"locale:remove-useless": "ts-node scripts/remove-useless-locale.ts"
Expand Down
3 changes: 1 addition & 2 deletions packages/codemod/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const _ = require('lodash');
const chalk = require('chalk');
const isGitClean = require('is-git-clean');
const updateCheck = require('update-check');
const findUp = require('find-up');
const semver = require('semver');
const { run: jscodeshift } = require('jscodeshift/src/Runner');
const execa = require('execa');
Expand Down Expand Up @@ -286,7 +285,7 @@ async function bootstrap() {
console.log('[Prettier] format files running...');
try {
const isDir = isDirectory.sync(dir);
const path = isDir ? '**/*.{js,jsx,tsx,ts,d.ts}' : dir;
const path = isDir ? path.join(dir, '**/*.{js,jsx,ts,tsx,d.ts}') : dir;
const npxCommand = commandExistsSync('tnpx') ? 'tnpx' : 'npx';
await execa(npxCommand, ['prettier', '--write', path], { stdio: 'inherit' });
console.log('\n[Prettier] format files completed!\n');
Expand Down
2 changes: 1 addition & 1 deletion packages/codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanbase/codemod",
"version": "0.2.5",
"version": "0.2.6",
"description": "Codemod for OceanBase Design upgrade",
"keywords": [
"oceanbase",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Alert, Button, BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, ConfigProvider, Login, PageContainer, theme } from '@alipay/ob-ui';
import { Alert, Button, BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, ConfigProvider, ContentWithQuestion, IconFont, Login, PageContainer, Ranger, theme, TreeSearch } from '@alipay/ob-ui';
import type { BackgroundTaskManagerRef, ITaskMgrPreset, ITaskMgrQueue, TaskMgrID } from '@alipay/ob-ui';
import type { BasicLayoutProps } from '@alipay/ob-ui/es/BasicLayout';
import type { LoginProps } from '@alipay/ob-ui/es/Login';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Alert, Button, ConfigProvider, theme } from '@oceanbase/design';
import { BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, Login, PageContainer } from '@oceanbase/ui';
import { BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, ContentWithQuestion, IconFont, Login, PageContainer, Ranger, TreeSearch } from '@oceanbase/ui';
import type { BackgroundTaskManagerRef, ITaskMgrPreset, ITaskMgrQueue, TaskMgrID } from '@oceanbase/ui';
import type { BasicLayoutProps } from '@oceanbase/ui/es/BasicLayout';
import type { LoginProps } from '@oceanbase/ui/es/Login';
Expand Down
24 changes: 24 additions & 0 deletions packages/codemod/transforms/obui-to-oceanbase-design-and-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ module.exports = (file, api, options) => {
'ContentWithQuestion',
'Dialog',
'DocDialog',
'FullscreenBox',
'Highlight',
'GraphToolbar',
'IconFont',
'Login',
'Lottie',
'NavMenu',
'Password',
'Ranger',
'SideTip',
'TaskGraph',
'TreeSearch',
'Welcome',
],
types: [
'PageContainerProps',
'ActionProps',
// BackgroundTaskManager
'BackgroundTaskManagerProps',
'BackgroundTaskManagerRef',
'ITaskMgrPreset',
Expand All @@ -38,10 +48,24 @@ module.exports = (file, api, options) => {
'ContentWithQuestionProps',
'DialogProps',
'DocDialogProps',
'FullscreenBoxProps',
'GraphToolbarProps',
'HighlightProps',
'IconFontProps',
'LoginProps',
'LottieProps',
'NavMenuProps',
'PasswordProps',
// Ranger
'RangerProps',
'QuickPickerProps',
'SideTipProps',
'TaskGraphProps',
// TreeSearch
'TreeSearchProps',
'TreeSearchRef',
'Node',
'WelcomeProps',
],
paths: ['/locale/', '/locale/'],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanbase/design",
"version": "0.2.22",
"version": "0.2.23",
"description": "The Design System of OceanBase",
"keywords": [
"oceanbase",
Expand Down
61 changes: 61 additions & 0 deletions packages/design/src/table/demo/bordered.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import { Table } from '@oceanbase/design';
import type { ColumnsType } from '@oceanbase/design/es/table';

interface DataType {
key: string;
name: string;
money: string;
address: string;
}

const columns: ColumnsType<DataType> = [
{
title: 'Name',
dataIndex: 'name',
render: text => <a>{text}</a>,
},
{
title: 'Cash Assets',
className: 'column-money',
dataIndex: 'money',
align: 'right',
},
{
title: 'Address',
dataIndex: 'address',
},
];

const data: DataType[] = [
{
key: '1',
name: 'John Brown',
money: '¥300,000.00',
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: 'Jim Green',
money: '¥1,256,000.00',
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: 'Joe Black',
money: '¥120,000.00',
address: 'Sydney No. 1 Lake Park',
},
];

const App: React.FC = () => (
<Table
columns={columns}
dataSource={data}
bordered
title={() => 'Header'}
footer={() => 'Footer'}
/>
);

export default App;
182 changes: 182 additions & 0 deletions packages/design/src/table/demo/edit-row.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import React, { useState } from 'react';
import { Form, Input, InputNumber, Popconfirm, Table, Typography } from '@oceanbase/design';

interface Item {
key: string;
name: string;
age: number;
address: string;
}

const originData: Item[] = [];
for (let i = 0; i < 100; i++) {
originData.push({
key: i.toString(),
name: `Edward ${i}`,
age: 32,
address: `London Park no. ${i}`,
});
}
interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
editing: boolean;
dataIndex: string;
title: any;
inputType: 'number' | 'text';
record: Item;
index: number;
children: React.ReactNode;
}

const EditableCell: React.FC<EditableCellProps> = ({
editing,
dataIndex,
title,
inputType,
record,
index,
children,
...restProps
}) => {
const inputNode = inputType === 'number' ? <InputNumber /> : <Input />;

return (
<td {...restProps}>
{editing ? (
<Form.Item
name={dataIndex}
style={{ margin: 0 }}
rules={[
{
required: true,
message: `Please Input ${title}!`,
},
]}
>
{inputNode}
</Form.Item>
) : (
children
)}
</td>
);
};

const App: React.FC = () => {
const [form] = Form.useForm();
const [data, setData] = useState(originData);
const [editingKey, setEditingKey] = useState('');

const isEditing = (record: Item) => record.key === editingKey;

const edit = (record: Partial<Item> & { key: React.Key }) => {
form.setFieldsValue({ name: '', age: '', address: '', ...record });
setEditingKey(record.key);
};

const cancel = () => {
setEditingKey('');
};

const save = async (key: React.Key) => {
try {
const row = (await form.validateFields()) as Item;

const newData = [...data];
const index = newData.findIndex(item => key === item.key);
if (index > -1) {
const item = newData[index];
newData.splice(index, 1, {
...item,
...row,
});
setData(newData);
setEditingKey('');
} else {
newData.push(row);
setData(newData);
setEditingKey('');
}
} catch (errInfo) {
console.log('Validate Failed:', errInfo);
}
};

const columns = [
{
title: 'name',
dataIndex: 'name',
width: '25%',
editable: true,
},
{
title: 'age',
dataIndex: 'age',
width: '15%',
editable: true,
},
{
title: 'address',
dataIndex: 'address',
width: '40%',
editable: true,
},
{
title: 'operation',
dataIndex: 'operation',
render: (_: any, record: Item) => {
const editable = isEditing(record);
return editable ? (
<span>
<Typography.Link onClick={() => save(record.key)} style={{ marginRight: 8 }}>
Save
</Typography.Link>
<Popconfirm title="Sure to cancel?" onConfirm={cancel}>
<a>Cancel</a>
</Popconfirm>
</span>
) : (
<Typography.Link disabled={editingKey !== ''} onClick={() => edit(record)}>
Edit
</Typography.Link>
);
},
},
];

const mergedColumns = columns.map(col => {
if (!col.editable) {
return col;
}
return {
...col,
onCell: (record: Item) => ({
record,
inputType: col.dataIndex === 'age' ? 'number' : 'text',
dataIndex: col.dataIndex,
title: col.title,
editing: isEditing(record),
}),
};
});

return (
<Form form={form} component={false}>
<Table
components={{
body: {
cell: EditableCell,
},
}}
bordered
dataSource={data}
columns={mergedColumns}
rowClassName="editable-row"
pagination={{
onChange: cancel,
}}
/>
</Form>
);
};

export default App;
4 changes: 4 additions & 0 deletions packages/design/src/table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ nav:

<code src="./demo/basic.tsx" title="基本"></code>

<code src="./demo/bordered.tsx" title="带边框" description="添加表格边框线"></code>

<code src="./demo/fixed-columns-header-tables.tsx" title="固定头和列"></code>

<code src="./demo/multiple-tables.tsx" title="选择和操作"></code>
Expand All @@ -24,6 +26,8 @@ nav:

<code src="./demo/ellipsis.tsx" title="单元格自动省略" description="设置 `column.ellipsis` 可以让单元格内容根据宽度自动省略,并使用 Tooltip 展示全部内容。`说明`: 列头缩略暂不支持和排序筛选一起使用。"></code>

<code src="./demo/edit-row.tsx" title="可编辑行" description="带行编辑功能的表格。"></code>

<code src="./demo/dynamic-settings.tsx" title="动态控制表格属性" description="选择不同配置组合查看效果。"></code>

## API
Expand Down
2 changes: 1 addition & 1 deletion packages/design/src/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Table<T>(props: TableProps<T>) {
const [currentSelectedRows, setCurrentSelectedRows] = useState<any[]>([]);
const [currentSelectedInfo, setCurrentSelectedInfo] = useState<any>({});

const newColumns = columns.map(item => {
const newColumns = columns?.map(item => {
if (item.ellipsis) {
return {
...item,
Expand Down
Loading

0 comments on commit 0cc0f99

Please sign in to comment.