Split toolbox storage by module
This commit is contained in:
parent
97253acb00
commit
588c1298cd
18 changed files with 1248 additions and 1180 deletions
28
website/src/features/toolboxes/storage/modules/counters.js
Normal file
28
website/src/features/toolboxes/storage/modules/counters.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Rôle : normalise et compacte les compteurs toolbox.
|
||||
import { uid } from "./shared.js";
|
||||
|
||||
function normalizeCounterValue(value) {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
export function normalizeCountersData(data) {
|
||||
return {
|
||||
counters: (data?.counters || [])
|
||||
.map((counter) => ({
|
||||
id: counter?.id || uid("counter"),
|
||||
label: String(counter?.label || "").trim(),
|
||||
value: normalizeCounterValue(counter?.value)
|
||||
}))
|
||||
.filter((counter) => counter.label)
|
||||
};
|
||||
}
|
||||
|
||||
export function compactCountersDataForStorage(value) {
|
||||
const counters = normalizeCountersData(value).counters.map((counter) => ({
|
||||
id: counter.id,
|
||||
label: counter.label,
|
||||
value: counter.value
|
||||
}));
|
||||
return counters.length ? { counters } : null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue