Skip to content

Commit d4a2c2f

Browse files
committed
Refactor(preferences): Refactor schemas generator
1 parent 8c5b1ff commit d4a2c2f

File tree

15 files changed

+1103
-899
lines changed

15 files changed

+1103
-899
lines changed

develop/test/settings_schemas.test.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ test("Schema and Settings Key Synchronization", async t => {
9898
boxes
9999
.flatMap(box => {
100100
return box.fields.flatMap(field => {
101-
return field.type === "table"
102-
? field.nestedBoxes.flatMap(b => b.fields.map(f => `${field.key}.${f.key}`))
103-
: field.key
101+
const nested = field.nestedBoxes ?? field.subSchema
102+
return nested?.flatMap(b => b.fields.map(f => `${field.key}.${f.key}`)) ?? field.key
104103
})
105104
})
106105
.map(e => e.replace(/\.\d+/g, ""))
@@ -121,6 +120,7 @@ test("all schemas keys should be translated", async t => {
121120

122121
const baseProps = ["label", "tooltip", "placeholder", "hintHeader", "hintDetail", "unit"]
123122
const specialProps = ["options", "thMap"]
123+
const nestedFieldProps = ["nestedBoxes", "subSchema"]
124124
const checkTranslated = (newBox, isTranslated) => {
125125
if (newBox.title) {
126126
isTranslated(newBox.title, { property: "title", boxTitle: newBox.title })
@@ -139,9 +139,9 @@ test("all schemas keys should be translated", async t => {
139139
})
140140
}
141141
})
142-
if (newField.nestedBoxes != null) {
143-
newField.nestedBoxes.forEach(box => checkTranslated(box, isTranslated))
144-
}
142+
nestedFieldProps.forEach(prop => {
143+
newField[prop]?.forEach(box => checkTranslated(box, isTranslated))
144+
})
145145
})
146146
}
147147

@@ -179,9 +179,12 @@ test("all i18n keys starting with $ should be used in schemas", async t => {
179179
}
180180

181181
const filterUsedKeys = (allI18NKeys, schemas) => {
182-
const baseProps = ["label", "tooltip", "placeholder", "hintHeader", "hintDetail", "unit"]
183-
const specialProps = ["options", "thMap"]
182+
const boxProps = ["title", "tooltip"]
183+
const baseFieldProps = ["label", "tooltip", "placeholder", "hintHeader", "hintDetail", "unit"]
184+
const specialFieldProps = ["options", "thMap"]
185+
const nestedFieldProps = ["nestedBoxes", "subSchema"]
184186
const _filterUsedKeys = (fixedName, key) => {
187+
if (key == null) return
185188
if (allI18NKeys[fixedName].has(key)) {
186189
allI18NKeys[fixedName].delete(key)
187190
} else if (allI18NKeys.settings.has(key)) {
@@ -190,25 +193,25 @@ test("all i18n keys starting with $ should be used in schemas", async t => {
190193
}
191194
for (const [fixedName, boxes] of Object.entries(schemas)) {
192195
for (const box of boxes) {
193-
if (box.title) {
194-
_filterUsedKeys(fixedName, box.title)
196+
for (const prop of boxProps) {
197+
_filterUsedKeys(fixedName, box[prop])
195198
}
196199
for (const field of box.fields || []) {
197-
for (const prop of baseProps) {
198-
if (field[prop] != null) {
199-
_filterUsedKeys(fixedName, field[prop])
200-
}
200+
for (const prop of baseFieldProps) {
201+
_filterUsedKeys(fixedName, field[prop])
201202
}
202-
for (const prop of specialProps) {
203+
for (const prop of specialFieldProps) {
203204
const propVal = field[prop]
204205
if (propVal && typeof propVal === "object") {
205206
for (const v of Object.values(propVal)) {
206207
_filterUsedKeys(fixedName, v)
207208
}
208209
}
209210
}
210-
if (field.nestedBoxes) {
211-
filterUsedKeys(allI18NKeys, { [fixedName]: field.nestedBoxes })
211+
for (const prop of nestedFieldProps) {
212+
if (field[prop]) {
213+
filterUsedKeys(allI18NKeys, { [fixedName]: field[prop] })
214+
}
212215
}
213216
}
214217
}

plugin/global/core/components/fast-window.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ customElements.define("fast-window", class extends HTMLElement {
191191

192192
this._isDragging = true
193193
this.style.transition = "none"
194-
this.entities.titleBar.classList.add("dragging")
195194

196195
const rect = this.getBoundingClientRect()
197196
this._offsetX = ev.clientX - rect.left
@@ -221,8 +220,6 @@ customElements.define("fast-window", class extends HTMLElement {
221220
_endDrag = () => {
222221
this._isDragging = false
223222
this.style.removeProperty("transition")
224-
this.entities.titleBar.classList.remove("dragging")
225-
226223
document.removeEventListener("mousemove", this._dragging)
227224
document.removeEventListener("mouseup", this._endDrag)
228225
}

0 commit comments

Comments
 (0)