mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-04 13:49:19 +01:00
* wip: add oldmarr config import
* wip: add support for wrong amount of categories / sections with autofix, color mapping, position adjustments of wrappers
* fix: lockfile broken
* feat: add support for form data trpc requests
* wip: improve file upload
* refactor: restructure import, add import configuration
* wip: add configurations for import to modal
* refactor: move oldmarr import to old-import package
* fix: column count not respects screen size for board
* feat: add beta badge for oldmarr config import
* chore: address pull request feedback
* fix: format issues
* fix: inconsistent versions
* fix: deepsource issues
* fix: revert {} to Record<string, never> convertion to prevent typecheck issue
* fix: inconsistent zod version
* fix: format issue
* chore: address pull request feedback
* fix: wrong import
* fix: broken lock file
* fix: inconsistent versions
* fix: format issues
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { createId } from "@homarr/db";
|
|
import { logger } from "@homarr/log";
|
|
import type { OldmarrConfig } from "@homarr/old-schema";
|
|
|
|
export const fixSectionIssues = (old: OldmarrConfig) => {
|
|
const wrappers = old.wrappers.sort((wrapperA, wrapperB) => wrapperA.position - wrapperB.position);
|
|
const categories = old.categories.sort((categoryA, categoryB) => categoryA.position - categoryB.position);
|
|
|
|
const neededSectionCount = categories.length * 2 + 1;
|
|
const hasToMuchEmptyWrappers = wrappers.length > categories.length + 1;
|
|
|
|
logger.debug(
|
|
`Fixing section issues neededSectionCount=${neededSectionCount} hasToMuchEmptyWrappers=${hasToMuchEmptyWrappers}`,
|
|
);
|
|
|
|
for (let position = 0; position < neededSectionCount; position++) {
|
|
const index = Math.floor(position / 2);
|
|
const isEmpty = position % 2 === 0;
|
|
const section = isEmpty ? wrappers[index] : categories[index];
|
|
if (!section) {
|
|
// If there are not enough empty sections for categories we need to insert them
|
|
if (isEmpty) {
|
|
// Insert empty wrapper for between categories
|
|
wrappers.push({
|
|
id: createId(),
|
|
position,
|
|
});
|
|
}
|
|
continue;
|
|
}
|
|
|
|
section.position = position;
|
|
}
|
|
|
|
// Find all wrappers that should be merged into one
|
|
const wrapperIdsToMerge = wrappers.slice(categories.length).map((section) => section.id);
|
|
// Remove all wrappers after the first at the end
|
|
wrappers.splice(categories.length + 1);
|
|
|
|
if (wrapperIdsToMerge.length >= 2) {
|
|
logger.debug(`Found wrappers to merge count=${wrapperIdsToMerge.length}`);
|
|
}
|
|
|
|
return {
|
|
wrappers,
|
|
categories,
|
|
wrapperIdsToMerge,
|
|
};
|
|
};
|