Refactor executable IDs to use strings #262
This commit unifies executable ID structure across categories and scripts, paving the way for more complex ID solutions for #262. It also refactors related code to adapt to the changes. Key changes: - Change numeric IDs to string IDs for categories - Use named types for string IDs to improve code clarity - Add unit tests to verify ID uniqueness Other supporting changes: - Separate concerns in entities for data access and executables by using separate abstractions (`Identifiable` and `RepositoryEntity`) - Simplify usage and construction of entities. - Remove `BaseEntity` for simplicity. - Move creation of categories/scripts to domain layer - Refactor CategoryCollection for better validation logic isolation - Rename some categories to keep the names (used as pseudo-IDs) unique on Windows.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
export type TreeInputNodeDataId = string;
|
||||
|
||||
export interface TreeInputNodeData {
|
||||
readonly id: string;
|
||||
readonly id: TreeInputNodeDataId;
|
||||
readonly children?: readonly TreeInputNodeData[];
|
||||
readonly parent?: TreeInputNodeData | null;
|
||||
readonly data?: object;
|
||||
|
||||
@@ -56,7 +56,7 @@ import { useNodeState } from './UseNodeState';
|
||||
import LeafTreeNode from './LeafTreeNode.vue';
|
||||
import InteractableNode from './InteractableNode.vue';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { NodeRenderingStrategy } from '../Rendering/Scheduling/NodeRenderingStrategy';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
@@ -69,7 +69,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -18,13 +18,13 @@ import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { useNodeState } from './UseNodeState';
|
||||
import { useKeyboardInteractionState } from './UseKeyboardInteractionState';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -28,7 +28,7 @@ import { defineComponent, computed, toRef } from 'vue';
|
||||
import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import NodeCheckbox from './NodeCheckbox.vue';
|
||||
import InteractableNode from './InteractableNode.vue';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
@@ -39,7 +39,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -14,13 +14,13 @@ import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { useNodeState } from './UseNodeState';
|
||||
import { TreeNodeCheckState } from './State/CheckState';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { HierarchyAccess, HierarchyReader } from './Hierarchy/HierarchyAccess';
|
||||
import type { TreeNodeStateAccess, TreeNodeStateReader } from './State/StateAccess';
|
||||
|
||||
export type TreeNodeId = string;
|
||||
|
||||
export interface ReadOnlyTreeNode {
|
||||
readonly id: string;
|
||||
readonly id: TreeNodeId;
|
||||
readonly state: TreeNodeStateReader;
|
||||
readonly hierarchy: HierarchyReader;
|
||||
readonly metadata?: object;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TreeNodeHierarchy } from './Hierarchy/TreeNodeHierarchy';
|
||||
import { TreeNodeState } from './State/TreeNodeState';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { TreeNodeStateAccess } from './State/StateAccess';
|
||||
import type { HierarchyAccess } from './Hierarchy/HierarchyAccess';
|
||||
|
||||
@@ -9,7 +9,7 @@ export class TreeNodeManager implements TreeNode {
|
||||
|
||||
public readonly hierarchy: HierarchyAccess;
|
||||
|
||||
constructor(public readonly id: string, public readonly metadata?: object) {
|
||||
constructor(public readonly id: TreeNodeId, public readonly metadata?: object) {
|
||||
if (!id) {
|
||||
throw new Error('missing id');
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { ReadOnlyTreeNode, TreeNode } from '../../../Node/TreeNode';
|
||||
import type { ReadOnlyTreeNode, TreeNode, TreeNodeId } from '../../../Node/TreeNode';
|
||||
|
||||
export interface ReadOnlyQueryableNodes {
|
||||
readonly rootNodes: readonly ReadOnlyTreeNode[];
|
||||
readonly flattenedNodes: readonly ReadOnlyTreeNode[];
|
||||
|
||||
getNodeById(id: string): ReadOnlyTreeNode;
|
||||
getNodeById(nodeId: TreeNodeId): ReadOnlyTreeNode;
|
||||
}
|
||||
|
||||
export interface QueryableNodes extends ReadOnlyQueryableNodes {
|
||||
readonly rootNodes: readonly TreeNode[];
|
||||
readonly flattenedNodes: readonly TreeNode[];
|
||||
|
||||
getNodeById(id: string): TreeNode;
|
||||
getNodeById(nodeId: TreeNodeId): TreeNode;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { QueryableNodes } from './QueryableNodes';
|
||||
import type { TreeNode } from '../../../Node/TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from '../../../Node/TreeNode';
|
||||
|
||||
export class TreeNodeNavigator implements QueryableNodes {
|
||||
public readonly flattenedNodes: readonly TreeNode[];
|
||||
@@ -8,10 +8,10 @@ export class TreeNodeNavigator implements QueryableNodes {
|
||||
this.flattenedNodes = flattenNodes(rootNodes);
|
||||
}
|
||||
|
||||
public getNodeById(id: string): TreeNode {
|
||||
const foundNode = this.flattenedNodes.find((node) => node.id === id);
|
||||
public getNodeById(nodeId: TreeNodeId): TreeNode {
|
||||
const foundNode = this.flattenedNodes.find((node) => node.id === nodeId);
|
||||
if (!foundNode) {
|
||||
throw new Error(`Node could not be found: ${id}`);
|
||||
throw new Error(`Node could not be found: ${nodeId}`);
|
||||
}
|
||||
return foundNode;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from 'vue';
|
||||
import HierarchicalTreeNode from '../Node/HierarchicalTreeNode.vue';
|
||||
import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { type TreeNodeId } from '../Node/TreeNode';
|
||||
import type { NodeRenderingStrategy } from '../Rendering/Scheduling/NodeRenderingStrategy';
|
||||
import type { TreeRoot } from './TreeRoot';
|
||||
import type { PropType } from 'vue';
|
||||
@@ -43,7 +44,7 @@ export default defineComponent({
|
||||
setup(props) {
|
||||
const { nodes } = useCurrentTreeNodes(toRef(props, 'treeRoot'));
|
||||
|
||||
const renderedNodeIds = computed<string[]>(() => {
|
||||
const renderedNodeIds = computed<TreeNodeId[]>(() => {
|
||||
return nodes
|
||||
.value
|
||||
.rootNodes
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useLeafNodeCheckedStateUpdater } from './UseLeafNodeCheckedStateUpdater
|
||||
import { useAutoUpdateParentCheckState } from './UseAutoUpdateParentCheckState';
|
||||
import { useAutoUpdateChildrenCheckState } from './UseAutoUpdateChildrenCheckState';
|
||||
import { useGradualNodeRendering, type NodeRenderingControl } from './Rendering/UseGradualNodeRendering';
|
||||
import { type TreeNodeId } from './Node/TreeNode';
|
||||
import type { TreeNodeStateChangedEmittedEvent } from './Bindings/TreeNodeStateChangedEmittedEvent';
|
||||
import type { TreeInputNodeData } from './Bindings/TreeInputNodeData';
|
||||
import type { TreeViewFilterEvent } from './Bindings/TreeInputFilterEvent';
|
||||
@@ -45,7 +46,7 @@ export default defineComponent({
|
||||
default: () => undefined,
|
||||
},
|
||||
selectedLeafNodeIds: {
|
||||
type: Array as PropType<ReadonlyArray<string>>,
|
||||
type: Array as PropType<ReadonlyArray<TreeNodeId>>,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user