Skip to content

Commit

Permalink
perf: ⚡️ ProArrayTable.DelegateAction act default
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx committed Feb 23, 2024
1 parent ce3c2b6 commit e771fb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions docs/components/demos/ProArrayTableWithShadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ const row: ISchema = {
"x-component": "ProArrayTable.Column",
"x-component-props": { title: "编辑", align: "center" },
properties: {
_trigger: {
// ↓ 不填写 act 属性的话, 就读这个 modal 了 (schema.name)
modal: {
type: "void",
"x-decorator": "ProArrayTable.DelegateAction",
"x-decorator-props": {
act: "modal",
// act: "modal", // 这里不填写的话, 就读取上面
initLoader: (o: any) => {
console.log("🚀 ~ o::", o);
return o;
Expand All @@ -83,7 +84,7 @@ const schema: ISchema = {
"x-component": "ProArrayTable",
items: row.items,
properties: {
// ↓ 不填写 act 属性的话, 就读这个 modal 字段
// ↓ 不填写 act 属性的话, 就读这个 modal 了 (schema.name)
modal: {
type: "void",
"x-component": "ProArrayTable.ShadowModal",
Expand Down
11 changes: 7 additions & 4 deletions src/pro-array-table/mixin.pro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ export const ArrayTableShowModal: React.FC<
};

export const DelegateAction: React.FC<{
/** 动作标志, 与 ShadowModal 对应 */
act: string;
/** 动作标志, 与 ShadowModal 对应, 不填写的话去 schema 的名字 */
act?: string;
/** 当前列所属 index, 默认使用 ArrayBase.useIndex() 获取当前数据对应位置 */
index?: number;
/** 数据初始化加载器, 默认使用 field.record 当前模型所对应 record */
Expand All @@ -231,19 +231,22 @@ export const DelegateAction: React.FC<{
}> = (props) => {
const index = "index" in (props ?? {}) ? props.index : ArrayBase.useIndex();
const field = useField();
const schema = useFieldSchema();
const record = useRecord();
const delegate = useContext(ArrayTableDelegateContext);

const actName = props.act ?? schema.name;

useEffect(() => {
if (!delegate.initLoader) return;
if (delegate.act === props.act && delegate.index === index) {
if (delegate.act === actName && delegate.index === index) {
delegate.initLoader.current = props.initLoader
? () => props.initLoader?.(record)
: () => record;
}
}, [delegate.act, delegate.index, delegate.initLoader]);
const dataInfo = {
[DATE_DELEGATE_ACT_KEY]: props.act,
[DATE_DELEGATE_ACT_KEY]: actName,
[DATE_DELEGATE_INDEX_KEY]: index,
};

Expand Down

0 comments on commit e771fb7

Please sign in to comment.