fix(ui): allow json fields to be updated externally (#11371)
### What? Unable to update json fields externally. For example, calling `setValue` on a json field would not be reflected in the admin panel UI. ### Why? JSON fields use the monaco editor to manage state internally, so programmatically updating the value in state does not change the internal value. ### How? Set a ref when the user updates the value and then unset the ref after the change is complete. Inside the hook that watches `value`, if the value changed and the change came from the system (i.e. a programmatic change) refresh the editor by adjusting its key prop. If the change was made by the user, there is no need to refresh the editor. Fixes https://github.com/payloadcms/payload/issues/10819
This commit is contained in:
@@ -1474,6 +1474,15 @@ export interface JsonField {
|
||||
| boolean
|
||||
| null;
|
||||
};
|
||||
customJSON?:
|
||||
| {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
| unknown[]
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -3165,6 +3174,7 @@ export interface JsonFieldsSelect<T extends boolean = true> {
|
||||
| {
|
||||
jsonWithinGroup?: T;
|
||||
};
|
||||
customJSON?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user