mirror of
https://github.com/nocobase/nocobase.git
synced 2026-09-21 13:52:17 +08:00
refactor: update ctx.record to not use cache (#8051)
* refactor: update ctx.record to not use cache * fix: tests
This commit is contained in:
@@ -64,7 +64,7 @@ function AssignFieldsEditor() {
|
||||
// 批量配置态:移除 ctx.record(Action 为区块级,不具备单条记录上下文)
|
||||
const isBulk = action instanceof CollectionActionModel && !(action instanceof RecordActionModel);
|
||||
if (isBulk && (formModel as any)?.context?.defineProperty) {
|
||||
formModel.context.defineProperty('record', { get: () => undefined });
|
||||
formModel.context.defineProperty('record', { get: () => undefined, cache: false });
|
||||
}
|
||||
initializedRef.current = true;
|
||||
}, [action, blockModel?.collection, formModel]);
|
||||
|
||||
@@ -626,6 +626,7 @@ export class GridModel<T extends { subModels: { items: FlowModel[] } } = Default
|
||||
});
|
||||
fork.context.defineProperty('record', {
|
||||
get: () => record,
|
||||
cache: false,
|
||||
});
|
||||
return fork;
|
||||
})();
|
||||
|
||||
@@ -112,6 +112,7 @@ export class QuickEditFormModel extends FlowModel {
|
||||
const recordMeta: PropertyMetaFactory = createCurrentRecordMetaFactory(this.context, () => this.collection);
|
||||
this.context.defineProperty('record', {
|
||||
get: () => this.resource.getData(),
|
||||
cache: false,
|
||||
resolveOnServer: createRecordResolveOnServerWithLocal(
|
||||
() => this.collection,
|
||||
() => this.resource.getData(),
|
||||
|
||||
@@ -128,6 +128,7 @@ export class JSColumnModel extends TableCustomColumnModel {
|
||||
);
|
||||
fork.context.defineProperty('record', {
|
||||
get: () => record,
|
||||
cache: false,
|
||||
resolveOnServer: createRecordResolveOnServerWithLocal(
|
||||
() => fork.context.collection,
|
||||
() => record,
|
||||
|
||||
@@ -56,6 +56,7 @@ const Columns = observer<any>(({ record, model, index }) => {
|
||||
);
|
||||
fork.context.defineProperty('record', {
|
||||
get: () => record,
|
||||
cache: false,
|
||||
resolveOnServer: createRecordResolveOnServerWithLocal(
|
||||
() => (fork.context as any).collection,
|
||||
() => record,
|
||||
|
||||
@@ -291,6 +291,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
||||
);
|
||||
fork.context.defineProperty('record', {
|
||||
get: () => record,
|
||||
cache: false,
|
||||
meta: recordMeta,
|
||||
});
|
||||
fork.setProps({ ...model.props, value: values[dataIndex] });
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ export function LabelByField(props: Readonly<LabelByFieldProps>) {
|
||||
const fieldModel = field.createFork({}, key);
|
||||
fieldModel.context.defineProperty('record', {
|
||||
get: () => option,
|
||||
cache: false,
|
||||
meta: createCurrentRecordMetaFactory(fieldModel.context, () => fieldModel.context.collection),
|
||||
});
|
||||
const labelValue = option?.[fieldNames.label] || option.label;
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ const ArrayNester = ({ name, value = [] }: any) => {
|
||||
});
|
||||
fork.context.defineProperty('record', {
|
||||
get: () => record,
|
||||
cache: false,
|
||||
});
|
||||
forksRef.current[key] = fork;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ export class VariableFieldFormModel extends FlowModel {
|
||||
});
|
||||
this.context.defineProperty('record', {
|
||||
get: () => {},
|
||||
cache: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+9
-4
@@ -108,10 +108,15 @@ describe('RangePicker', () => {
|
||||
await userEvent.click(document.querySelector('[title="2023-05-01"]') as HTMLElement);
|
||||
await userEvent.click(document.querySelector('[title="2023-05-02"]') as HTMLElement);
|
||||
|
||||
await waitFor(() => expect(startInput).toHaveValue('2023-05-01'));
|
||||
await waitFor(() => expect(endInput).toHaveValue('2023-05-02'));
|
||||
// Read pretty
|
||||
expect(screen.getByText('2023-05-01~2023-05-02', { selector: '.ant-description-text' })).toBeInTheDocument();
|
||||
await waitFor(
|
||||
() => {
|
||||
expect(startInput).toHaveValue('2023-05-01');
|
||||
expect(endInput).toHaveValue('2023-05-02');
|
||||
// Read pretty(等到回填完成再断言,避免动画未收起导致的偶发失败)
|
||||
expect(screen.getByText('2023-05-01~2023-05-02', { selector: '.ant-description-text' })).toBeInTheDocument();
|
||||
},
|
||||
{ timeout: 3000 },
|
||||
);
|
||||
// Value
|
||||
expect(screen.getByText('2023-05-01T00:00:00.000Z ~ 2023-05-02T23:59:59.999Z')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
+1
@@ -60,6 +60,7 @@ function AssignFieldsEditor() {
|
||||
// formModel.context.defineProperty('formValues', { get: () => undefined });
|
||||
formModel.context.defineProperty('record', {
|
||||
get: () => undefined,
|
||||
cache: false,
|
||||
});
|
||||
initializedRef.current = true;
|
||||
}, [action, blockModel?.collection, formModel]);
|
||||
|
||||
+1
@@ -121,6 +121,7 @@ export class GridCardItemModel extends FlowModel<GridItemModelStructure> {
|
||||
get: () => this.context.record,
|
||||
resolveOnServer: true,
|
||||
meta: recordMeta,
|
||||
cache: false,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -103,6 +103,7 @@ export class ListItemModel extends FlowModel<ListItemModelStructure> {
|
||||
get: () => this.context.record,
|
||||
resolveOnServer: true,
|
||||
meta: recordMeta,
|
||||
cache: false,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user