Add config cloning on instance creation (#747)

* Add instance config cloning on creation

* Add test for instance cloning

* Add tooltip to copy config button
This commit is contained in:
Cooldude2606 authored and GitHub committed 2025-04-06 02:00:08 +01:00
1 parent 0055f28f45
commit ce85149b4c
6 files changed
+63 -10

No files matched your search

+6 -1
View File
@@ -312,11 +312,16 @@ export class Config<
* Serialize the config to a plain JavaScript object
*
* @param remote - Location this serialised representation is for
* @param filter - When provided, only the given fields are serialized
* @returns JSON serializable representation of the config.
*/
toRemote(remote: ConfigLocation): Static<typeof Config.jsonSchema> {
toRemote(remote: ConfigLocation, filter?: (keyof Fields)[]): Static<typeof Config.jsonSchema> {
let fields: Record<string, FieldValue> = {};
for (let [name, value] of Object.entries(this.fields)) {
if (filter && !filter.includes(name as keyof Fields)) {
continue;
}
let def = this.constructor.fieldDefinitions[name];
if (
this.location !== "control" && !this._checkAccess(name, def, this.location, ConfigAccess.write, false)
+3 -1
View File
@@ -137,14 +137,16 @@ export class InstanceCreateRequest {
constructor(
public config: Static<typeof InstanceConfig.jsonSchema>,
public cloneFromId?: number,
) { }
static jsonSchema = Type.Object({
"config": InstanceConfig.jsonSchema,
"cloneFromId": Type.Optional(Type.Number()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.config);
return new this(json.config, json.cloneFromId);
}
}