import React, {FC} from "react"; import {ConditionColorPalette} from "./tree/Colors"; import {NodeWithAnchors} from "./NodeWithAnchors"; import {NodeProps} from "@xyflow/react"; import {useCardRenderer} from "./tree/hooks"; import {Card} from "./tree/Card"; import {CardItem} from "./tree/CardItem"; import {useTreeNodeTestable} from "./tree/TreeHooks"; import {Anchor, TestablePartial} from "./tree/store"; import {PopupWindowStateContext, TreeContextData} from "./tree/atoms"; import {TestablesSaver} from "./tree/TestablesSaver"; import {useOpenTestablesPopupWindow} from "./tree/useOpenTestablesPopupWindow"; import {__} from "./globals"; import classNames from "classnames"; import {getTierCardColor} from "./tree/getTierCardColor"; export type TierSubchildNodeProps = {} export const TieredSubchildNode: FC = ({id}) => { const testableNode = useTreeNodeTestable(id) const branch = testableNode?.branch const cardRenderer = useCardRenderer(id, 'testablePartials') const openTestablePopupWindow = useOpenTestablesPopupWindow() if (!testableNode) { console.error('TieredSubchildNode: testableNode not found', id) return null; } if (!branch) { console.error('TieredSubchildNode: testable not found', id) return null; } const baseTestable = testableNode.getTestable().getParent() const parentCompositeData = baseTestable?.getParent()?.getData() const conditionPalette = ( parentCompositeData && typeof parentCompositeData === 'object' && 'conditionColorPalette' in parentCompositeData && typeof parentCompositeData.conditionColorPalette === 'string' ) ? parentCompositeData.conditionColorPalette as ConditionColorPalette : undefined const color = getTierCardColor( baseTestable?.getMode() || 'filter', { conditionPalette, place: 'tier-subchild', } ) const canRenderFilteredItemsLabel = baseTestable?.getMode() === 'filter' return { // open the testabls popup to edit ts, in TIER SUBCHILD context! const context = { id: 'subchild-edit', scope: 'tier-subchild', // don't change it as it's used in the popup to locate the correct testable! data: { componentType: baseTestable?.getTestableType() || 'filter', supportsMultipleComponents: false, supportsOptionalQuantity: false, targetType: 'testablePartial', mode: 'edit', targetId: id } } as PopupWindowStateContext openTestablePopupWindow({ context, onClose: (data) => { if (data.status !== 'success' || !data.components) { return } // @ts-ignore const saver = new TestablesSaver(context) // here we have the component with extra data possibly added so let's just add the expected testable partial structure, // i dont know how i feel abt this though bc if we change the partials structure there's a good chance we'll forget to change it here and only find out after trying to update a partial from the ui (bug) // let's just hope typescript catches this? saver.update(data.components.map(partialMergeWithParent => ({ id: partialMergeWithParent.id as string, options: partialMergeWithParent.options, }))) } }); }} />
{canRenderFilteredItemsLabel &&
{false &&

{__('Filter items')}

}
}
}