Skip to content

Commit

Permalink
get default kredeum storage config
Browse files Browse the repository at this point in the history
  • Loading branch information
dlaxcess committed Feb 3, 2024
1 parent a03369c commit 3fb9cc0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
41 changes: 20 additions & 21 deletions svelte/components/Input/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export default class Config {
display: "IPFS",
editable: false,
fields: [
{ key: "apiEndPoint", value: "", display: "API end Point", fixed: true, undeletable: true },
{ key: "apiEndpoint", value: "", display: "API end Point", fixed: true, undeletable: true },
{ key: "apiKey", value: "", fixed: true, undeletable: true }
]
},
swarm: {
display: "Swarm",
editable: false,
fields: [
{ key: "apiEndPoint", value: "", fixed: true, undeletable: true },
{ key: "apiEndpoint", value: "", fixed: true, undeletable: true },
{ key: "apiKey", value: "", fixed: true, undeletable: true }
]
}
Expand All @@ -58,54 +58,53 @@ export default class Config {

loadConfigFromFile = () => {

}
};

localConfigSet = () => {

}
};

localConfigInit = () => {

}
};

getConfig = () => {
return this.attributes;
};

deleteAttribute = () => {

}
};

addAttribute = () => {

}
};

addField(namespace: string): void {
const fields = this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields;
this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields = [...fields, { key: "", value: "" }];
console.log("addField ~ this.attributes[namespace].fields:", this.attributes[namespace].fields);

document.dispatchEvent(this.propertyChangedEvent);
}

removeField(namespace: string, i: number): void {
const fields = this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields;
if (fields.length > 1) {
this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields = fields.filter((_, index) => i !== index);
} else {
this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields[i] = { key: "", value: "" };
}
// if (fields.length > 1) {
this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields = fields.filter((_, index) => i !== index);
// } else {
// this.attributes[namespace].fieldsGroups[this.attributes[namespace].default.value].fields[i] = { key: "", value: "" };
// }

document.dispatchEvent(this.propertyChangedEvent);
}


//////////////////////////////////////////////
// actual localStorage storage structure
let storage = {
default: "swarm",
swarm: {
apiEndpoint: "http://localhost:1633",
apiKey: "f2b69cfcb5666586d028e965f75fc19bd3eba48313591cf61418856f6904d5d4"
}
//////////////////////////////////////////////
// actual localStorage storage structure
// let storage = {
// default: "swarm",
// swarm: {
// apiEndpoint: "http://localhost:1633",
// apiKey: "f2b69cfcb5666586d028e965f75fc19bd3eba48313591cf61418856f6904d5d4"
// }
}
42 changes: 25 additions & 17 deletions svelte/components/Input/Config/InputConfigFields.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { StorageConfigType } from "@lib/common/types";
import type { UserConfig } from "./configTypes";
import config from "@config/config.json";
Expand Down Expand Up @@ -43,15 +44,30 @@
const localConfigGetKey = (key) => key.replace(`${krdNamespace}.`, "");
const importConfigSection= (namespace, configSection) => {
}
const importConfigSection = (namespace, fieldsGroups) => {
Object.entries(fieldsGroups).forEach(([fieldGroupKey, fieldGroupFields]) => {
if (fieldGroupFields && typeof fieldGroupFields === "object") {
Object.entries(fieldGroupFields).forEach(([key, value]) => {
if (attributes[namespace].fieldsGroups[fieldGroupKey]?.fields.some((field) => field.key === key)) {
attributes[namespace].fieldsGroups[fieldGroupKey].fields.forEach((field) => {
if (field.key === key) field.value = value;
});
} else {
attributes[namespace].fieldsGroups[fieldGroupKey]?.fields.push({ key, value });
}
});
}
});
};
const defaultConfigInit = () => {
const defaultStorageConfigInit = () => {
let storage = config.storage;
}
attributes.storage.default.value = storage.default;
importConfigSection("storage", storage);
};
const localConfigInit = (): void => {
defaultStorageConfigInit();
// if (!localConfigGet("api")) localConfigSet("api", BEE_API_DEFAULT);
// if (!localConfigGet("gateway")) localConfigSet("gateway", BEE_GATEWAY_DEFAULT);
// if (!localConfigGet("batchId")) localConfigSet("batchId", BEE_BATCHID_DEFAULT);
Expand All @@ -64,17 +80,7 @@
let localFieldsObject = JSON.parse(fields);
attributes[namespace].default.value = localFieldsObject.default;
Object.entries(localFieldsObject).forEach(([localFieldsObjectKey, ObjectEntries]) => {
Object.entries(ObjectEntries).forEach(([key, value]) => {
if (attributes[namespace].fieldsGroups[localFieldsObjectKey]?.fields.some((field) => field.key === key)) {
attributes[namespace].fieldsGroups[localFieldsObjectKey].fields = attributes[namespace].fieldsGroups[
localFieldsObjectKey
].fields.map((field) => (field.key === key ? { ...field, value: value.toString() } : field));
} else {
attributes[namespace].fieldsGroups[localFieldsObjectKey]?.fields.push({ key, value: value.toString() });
}
});
});
importConfigSection(namespace, localFieldsObject);
});
for (const namespace of Object.keys(attributes)) {
Expand Down Expand Up @@ -103,9 +109,11 @@
});
});
if (Object.keys(storageFields).length > 0) {
storageFields.default = defaultValue;
(storageFields as StorageConfigType).default = defaultValue;
localConfigSet(namespace, JSON.stringify(storageFields));
} else {
localConfigRemove(namespace);
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions svelte/components/Input/Config/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ type UserConfig = Record<string, ConfigSection>;

type ConfigSection = {
display: string;
default: { display: string; value: string };
editable: boolean;
default: { display?: string; value: string };
fieldsGroups: Record<string, FieldGroup>;
}

Expand Down

0 comments on commit 3fb9cc0

Please sign in to comment.