Refactor to unify scripts/categories as Executable
This commit consolidates scripts and categories under a unified 'Executable' concept. This simplifies the architecture and improves code readability. - Introduce subfolders within `src/domain` to segregate domain elements. - Update class and interface names by removing the 'I' prefix in alignment with new coding standards. - Replace 'Node' with 'Executable' to clarify usage; reserve 'Node' exclusively for the UI's tree component.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ICategory, IScript } from '@/domain/ICategory';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { type NodeMetadata, NodeType } from '../NodeContent/NodeMetadata';
|
||||
|
||||
export function parseAllCategories(collection: ICategoryCollection): NodeMetadata[] {
|
||||
@@ -15,7 +16,7 @@ export function parseSingleCategory(
|
||||
return tree;
|
||||
}
|
||||
|
||||
export function getScriptNodeId(script: IScript): string {
|
||||
export function getScriptNodeId(script: Script): string {
|
||||
return script.id;
|
||||
}
|
||||
|
||||
@@ -27,12 +28,12 @@ export function getCategoryId(nodeId: string): number {
|
||||
return +nodeId;
|
||||
}
|
||||
|
||||
export function getCategoryNodeId(category: ICategory): string {
|
||||
export function getCategoryNodeId(category: Category): string {
|
||||
return `${category.id}`;
|
||||
}
|
||||
|
||||
function parseCategoryRecursively(
|
||||
parentCategory: ICategory,
|
||||
parentCategory: Category,
|
||||
): NodeMetadata[] {
|
||||
return [
|
||||
...createCategoryNodes(parentCategory.subCategories),
|
||||
@@ -40,19 +41,19 @@ function parseCategoryRecursively(
|
||||
];
|
||||
}
|
||||
|
||||
function createScriptNodes(scripts: ReadonlyArray<IScript>): NodeMetadata[] {
|
||||
function createScriptNodes(scripts: ReadonlyArray<Script>): NodeMetadata[] {
|
||||
return (scripts || [])
|
||||
.map((script) => convertScriptToNode(script));
|
||||
}
|
||||
|
||||
function createCategoryNodes(categories: ReadonlyArray<ICategory>): NodeMetadata[] {
|
||||
function createCategoryNodes(categories: ReadonlyArray<Category>): NodeMetadata[] {
|
||||
return (categories || [])
|
||||
.map((category) => ({ category, children: parseCategoryRecursively(category) }))
|
||||
.map((data) => convertCategoryToNode(data.category, data.children));
|
||||
}
|
||||
|
||||
function convertCategoryToNode(
|
||||
category: ICategory,
|
||||
category: Category,
|
||||
children: readonly NodeMetadata[],
|
||||
): NodeMetadata {
|
||||
return {
|
||||
@@ -65,7 +66,7 @@ function convertCategoryToNode(
|
||||
};
|
||||
}
|
||||
|
||||
function convertScriptToNode(script: IScript): NodeMetadata {
|
||||
function convertScriptToNode(script: Script): NodeMetadata {
|
||||
return {
|
||||
id: getScriptNodeId(script),
|
||||
type: NodeType.Script,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
type Ref, shallowReadonly, shallowRef,
|
||||
} from 'vue';
|
||||
import type { IScript } from '@/domain/IScript';
|
||||
import type { ICategory } from '@/domain/ICategory';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import type { ReadonlyFilterContext } from '@/application/Context/State/Filter/FilterContext';
|
||||
import type { FilterResult } from '@/application/Context/State/Filter/Result/FilterResult';
|
||||
@@ -76,10 +76,10 @@ function filterMatches(node: NodeMetadata, filter: FilterResult): boolean {
|
||||
|| containsCategory(node, filter.categoryMatches);
|
||||
}
|
||||
|
||||
function containsScript(expected: NodeMetadata, scripts: readonly IScript[]) {
|
||||
return scripts.some((existing: IScript) => expected.id === getScriptNodeId(existing));
|
||||
function containsScript(expected: NodeMetadata, scripts: readonly Script[]) {
|
||||
return scripts.some((existing: Script) => expected.id === getScriptNodeId(existing));
|
||||
}
|
||||
|
||||
function containsCategory(expected: NodeMetadata, categories: readonly ICategory[]) {
|
||||
return categories.some((existing: ICategory) => expected.id === getCategoryNodeId(existing));
|
||||
function containsCategory(expected: NodeMetadata, categories: readonly Category[]) {
|
||||
return categories.some((existing: Category) => expected.id === getCategoryNodeId(existing));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user