import React, {FC} from "react"; import {ConditionColorPalette, getConditionColorPalette} from "./Colors"; import {useOpenTestablesPopupWindow} from "./useOpenTestablesPopupWindow"; import {convertTestableData, useNodesStore} from "./store"; import {Testables} from "./testables"; import {PopupWindowStateContext, TreeContextData} from "./atoms"; import {Context} from "./Context"; import {__, CouponsPlus} from "../globals"; import {RightContextButton} from "./RightContextButton"; import {NoPredates} from "./NoPredates"; import {WeeklyScheduleMeta} from "./cards/conditions/WeeklySchedule"; import {HolidaysMeta} from "./cards/conditions/Holidays"; import {predatesConditionPalette} from "./predatesPalette"; import {VerticalOrConnector} from "./VerticalOrConnector"; export type TreePredatesProps = { } type PredatesAccentTheme = { headingIcon: string, headingTitle: string, } const getPredatesAccentTheme = (palette: ConditionColorPalette): PredatesAccentTheme => ({ headingIcon: `text-${palette}-normal`, headingTitle: `text-${palette}-shade-100`, }) /** * I know the name makes no sense but i kind of want to keep it the same as "predates", a better name couldve been "scheduling". This naming convention will be applied to "prefilters" too which themselves could be called something like "excluded products" * so: * preconditions * predates * prefilters * * Very self-explanatory when you read them this way (they will be executed before the main grove) */ export const TreePredates: FC = ({}) => { const predatesAccentTheme = getPredatesAccentTheme(predatesConditionPalette) const color = getConditionColorPalette(predatesConditionPalette) const predatesSupportedComponents = [ CouponsPlus?.components?.conditions?.Date?.type, CouponsPlus?.components?.conditions?.WeeklySchedule?.type ?? WeeklyScheduleMeta.id, CouponsPlus?.components?.conditions?.Holidays?.type ?? HolidaysMeta.id ] const openTestablesPopupWindow = useOpenTestablesPopupWindow() const predatesID = useNodesStore(store => store.predatesID) const addTestables = useNodesStore(store => store.addTestables) const predatesContextIDs: string[] = useNodesStore(({ predatesID, testables, testableRelations, testablePartials }) => { if (!predatesID) { return [] } const testablesManager = new Testables({testables, testableRelations, testablePartials}) return testablesManager.getChildren(predatesID).map(({id}) => id) }) if (predatesContextIDs.length === 0) { return } /** * This has a lot of repetition with the testable popup of NoPredates */ const openTestables = () => { // @ts-ignore const context = { id: 'predates-or-add', scope: 'predates', data: { componentType: 'condition', conditionColorPalette: predatesConditionPalette, targetType: 'testableComposite', supportedComponents: predatesSupportedComponents, supportsMultipleComponents: false, showTabs: false, targetId: predatesID, // this is the main predates 'OR' group } } as PopupWindowStateContext openTestablesPopupWindow({ // @ts-ignore context, onClose: (data) => { if (data.status !== 'success' || !data.components) { return } addTestables([ convertTestableData(data.components), predatesID, true // wrap in group ], (addedIds, testablesManager, writeableStore) => { }) } }) } return

{__('Available')}

{predatesContextIDs.map((id, index) =>
{index + 1 < predatesContextIDs.length && } {(index + 1 === predatesContextIDs.length) && (
)}
)}
}