Skip to content

Commit

Permalink
Merge 1.1.x & CRUD 的 source 用法优化 (#2188)
Browse files Browse the repository at this point in the history
* jssdk 产出带版本

* jssdk 产出带版本

* feat:当表单disable时隐藏QuickEdit (#2175)

Co-authored-by: qinhaoyan <qinhaoyan@baidu.com>

* chore: 更新版本号

* 优化 Static 下的 quickEdit 处理逻辑

* 修复弹框关闭逻辑

* tabs schema 中 activeKey 优先级降低 (#2186)

* 同步1.2版本的时间范围选择改动 (#2183)

* crud 的 source 用法优化 #2108

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
Co-authored-by: qinhaoyan <qinhaoyan@baidu.com>
Co-authored-by: 吴多益 <wuduoyi@baidu.com>
Co-authored-by: RickCole <rickcole21@outlook.com>
Co-authored-by: xuzhendong666 <810792608@Outlook.com>
  • Loading branch information
6 people authored Jun 30, 2021
1 parent 63466f4 commit 9ee369a
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 28 deletions.
1 change: 1 addition & 0 deletions scripts/embed-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module.exports = function (ret, pack, settings, opt) {
if (file) {
file.skiped = true;
let contents = file.getContent();


if (/_map\.js$/.test(file.subpath)) {
contents = `(function() {
Expand Down
8 changes: 7 additions & 1 deletion src/SchemaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {

const renderer = this.renderer as RendererConfig;
schema = filterSchema(schema, renderer, rest);
const {data: defaultData, value: defaultValue, ...restSchema} = schema;
const {
data: defaultData,
value: defaultValue,
activeKey: defaultActiveKey,
...restSchema
} = schema;
const Component = renderer.component;

// 原来表单项的 visible: false 和 hidden: true 表单项的值和验证是有效的
Expand All @@ -287,6 +292,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
{...exprProps}
defaultData={defaultData}
defaultValue={defaultValue}
defaultActiveKey={defaultActiveKey}
$path={$path}
$schema={schema}
ref={this.refFn}
Expand Down
12 changes: 12 additions & 0 deletions src/renderers/CRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {ActionSchema} from './Action';
import {CardsSchema} from './Cards';
import {ListSchema} from './List';
import {TableSchema} from './Table';
import {isPureVariable, resolveVariableAndFilter} from '../utils/tpl-builtin';

export type CRUDBultinToolbarType =
| 'columns-toggler'
Expand Down Expand Up @@ -529,6 +530,17 @@ export default class CRUD extends React.Component<CRUDProps, any> {
)
) {
dataInvalid = true;
} else if (!props.api && isPureVariable(props.source)) {
const prev = resolveVariableAndFilter(
prevProps.source,
prevProps.data,
'!raw'
);
const next = resolveVariableAndFilter(props.source, props.data, '!raw');

if (prev !== next) {
store.initFromScope(props.data, props.source);
}
}

if (dataInvalid) {
Expand Down
15 changes: 11 additions & 4 deletions src/renderers/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
difference,
ucFirst
} from '../utils/helper';
import {resolveVariable} from '../utils/tpl-builtin';
import {
isPureVariable,
resolveVariable,
resolveVariableAndFilter
} from '../utils/tpl-builtin';
import Sortable from 'sortablejs';
import {filter} from '../utils/tpl';
import {Icon} from '../components/icons';
Expand Down Expand Up @@ -258,8 +262,10 @@ export default class Cards extends React.Component<GridProps, object> {
if (Array.isArray(value)) {
items = value;
} else if (typeof source === 'string') {
const resolved = resolveVariable(source, props.data);
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
const resolved = resolveVariableAndFilter(source, props.data);
const prev = prevProps
? resolveVariableAndFilter(source, prevProps.data)
: null;

if (prev && prev === resolved) {
updateItems = false;
Expand Down Expand Up @@ -321,7 +327,8 @@ export default class Cards extends React.Component<GridProps, object> {

if (
anyChanged(['source', 'value', 'items'], prevProps, props) ||
(!props.value && !props.items && props.data !== prevProps.data)
(!props.value && !props.items && props.data !== prevProps.data) ||
(typeof props.source === 'string' && isPureVariable(props.source))
) {
Cards.syncItems(store, props, prevProps);
this.syncSelected();
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ export class DialogRenderer extends Dialog {
} else if (action.actionType === 'reload') {
store.setCurrentAction(action);
action.target && scoped.reload(action.target, data);
if (action.close) {
if (action.close || action.type === 'submit') {
this.handleSelfClose();
this.closeTarget(action.close);
}
Expand Down
10 changes: 6 additions & 4 deletions src/renderers/Form/Static.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,22 @@ export default class StaticControl extends React.Component<StaticProps, any> {
this.handleQuickChange = this.handleQuickChange.bind(this);
}

handleQuickChange(values: any, saveImmediately: boolean | any) {
async handleQuickChange(values: any, saveImmediately: boolean | any) {
const {onBulkChange, onAction, data} = this.props;

onBulkChange(values, saveImmediately === true);
if (saveImmediately && saveImmediately.api) {
onAction(
await onAction(
null,
{
actionType: 'ajax',
api: saveImmediately.api
},
extendObject(data, values)
extendObject(data, values),
true
);
}

onBulkChange(values, saveImmediately === true);
}

render() {
Expand Down
15 changes: 11 additions & 4 deletions src/renderers/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
isDisabled,
noop
} from '../utils/helper';
import {resolveVariable} from '../utils/tpl-builtin';
import {
isPureVariable,
resolveVariable,
resolveVariableAndFilter
} from '../utils/tpl-builtin';
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
import PopOver, {SchemaPopOver} from './PopOver';
import Sortable from 'sortablejs';
Expand Down Expand Up @@ -327,8 +331,10 @@ export default class List extends React.Component<ListProps, object> {
if (Array.isArray(value)) {
items = value;
} else if (typeof source === 'string') {
const resolved = resolveVariable(source, props.data);
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
const resolved = resolveVariableAndFilter(source, props.data);
const prev = prevProps
? resolveVariableAndFilter(source, prevProps.data)
: null;

if (prev && prev === resolved) {
updateItems = false;
Expand Down Expand Up @@ -390,7 +396,8 @@ export default class List extends React.Component<ListProps, object> {

if (
anyChanged(['source', 'value', 'items'], prevProps, props) ||
(!props.value && !props.items && props.data !== prevProps.data)
(!props.value && !props.items && props.data !== prevProps.data) ||
(typeof props.source === 'string' && isPureVariable(props.source))
) {
List.syncItems(store, props, prevProps);
this.syncSelected();
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default class Page extends React.Component<PageProps> {
ctx: object,
throwErrors: boolean = false,
delegate?: IScopedContext
) {
): any {
const {env, store, messages, onAction} = this.props;

if (action.actionType === 'dialog') {
Expand All @@ -269,7 +269,7 @@ export default class Page extends React.Component<PageProps> {
store.openDrawer(ctx);
} else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
store
return store
.saveRemote(action.api as string, ctx, {
successMessage:
(action.messages && action.messages.success) ||
Expand All @@ -290,7 +290,7 @@ export default class Page extends React.Component<PageProps> {
})
.catch(() => {});
} else {
onAction(e, action, ctx, throwErrors, delegate || this.context);
return onAction(e, action, ctx, throwErrors, delegate || this.context);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/renderers/QuickEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (
false,
(quickEdit as QuickEditConfig).resetOnFailed
);

return false;
}

handleInit(values: object) {
Expand Down Expand Up @@ -513,7 +515,13 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (
disabled
} = this.props;

if (!quickEdit || !onQuickChange || quickEditEnabled === false || noHoc || disabled) {
if (
!quickEdit ||
!onQuickChange ||
quickEditEnabled === false ||
noHoc ||
disabled
) {
return <Component {...this.props} />;
}

Expand Down
16 changes: 12 additions & 4 deletions src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
getVariable,
removeHTMLTag
} from '../../utils/helper';
import {resolveVariable} from '../../utils/tpl-builtin';
import {
isPureVariable,
resolveVariable,
resolveVariableAndFilter
} from '../../utils/tpl-builtin';
import debounce from 'lodash/debounce';
import Sortable from 'sortablejs';
import {resizeSensor} from '../../utils/resize-sensor';
Expand Down Expand Up @@ -471,8 +475,10 @@ export default class Table extends React.Component<TableProps, object> {
if (Array.isArray(value)) {
rows = value;
} else if (typeof source === 'string') {
const resolved = resolveVariable(source, props.data);
const prev = prevProps ? resolveVariable(source, prevProps.data) : null;
const resolved = resolveVariableAndFilter(source, props.data);
const prev = prevProps
? resolveVariableAndFilter(source, prevProps.data)
: null;

if (prev && prev === resolved) {
updateRows = false;
Expand Down Expand Up @@ -558,14 +564,16 @@ export default class Table extends React.Component<TableProps, object> {

if (
anyChanged(['source', 'value', 'items'], prevProps, props) ||
(!props.value && !props.items && props.data !== prevProps.data)
(!props.value && !props.items && props.data !== prevProps.data) ||
(typeof props.source === 'string' && isPureVariable(props.source))
) {
Table.syncRows(store, props, prevProps);
this.syncSelected();
} else if (isArrayChildrenModified(prevProps.selected!, props.selected!)) {
store.updateSelected(props.selected || [], props.valueField);
this.syncSelected();
}

this.updateTableInfoLazy();
}

Expand Down
14 changes: 9 additions & 5 deletions src/renderers/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,18 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
let activeKey: any = 0;

if (typeof props.activeKey !== 'undefined') {
activeKey =
typeof props.activeKey === 'string'
? tokenize(props.activeKey, props.data)
: props.activeKey;
activeKey = props.activeKey;
} else if (location && Array.isArray(tabs)) {
const hash = location.hash.substring(1);
const tab: TabSchema = find(tabs, tab => tab.hash === hash) as TabSchema;
activeKey = tab && tab.hash ? tab.hash : (tabs[0] && tabs[0].hash) || 0;

if (tab) {
activeKey = tab.hash;
} else if (props.defaultActiveKey) {
activeKey = tokenize(props.defaultActiveKey, props.data);
}

activeKey = activeKey || (tabs[0] && tabs[0].hash) || 0;
}

this.state = {
Expand Down
4 changes: 3 additions & 1 deletion src/store/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,12 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
'| raw'
);

if (!Array.isArray(rowsData)) {
if (!Array.isArray(rowsData) && !self.items.length) {
return;
}

rowsData = Array.isArray(rowsData) ? rowsData : [];

const data = {
...self.pristine,
items: rowsData,
Expand Down

0 comments on commit 9ee369a

Please sign in to comment.