/** * External dependencies */ import type { AlternativeId, Experiment, GoalId, Maybe, SegmentId, } from '@nab/types'; import { State } from '../types'; export type EditorAction = | SetActiveGoal | SetActiveSegment | SetExperimentAsBeingSaved | SetDraftStatusRationale | SetExperimentAsRecentlySaved | SetupEditor | OpenAlternativePreviewer | CloseAlternativePreviewer | OpenReusableDialog | CloseReusableDialog | ShowAiAlternativeModal; export type SetupEditor = { readonly type: 'SETUP_EDITOR'; readonly experiment: Experiment; }; export function setupEditor( experiment: Experiment ): SetupEditor { return { type: 'SETUP_EDITOR', experiment, }; } export function setActiveGoal( goalId: GoalId ): SetActiveGoal { return { type: 'SET_ACTIVE_GOAL', goalId, }; } export function setActiveSegment( segmentId: SegmentId ): SetActiveSegment { return { type: 'SET_ACTIVE_SEGMENT', segmentId, }; } export function setExperimentAsBeingSaved( status: boolean ): SetExperimentAsBeingSaved { return { type: 'SET_EXPERIMENT_AS_BEING_SAVED', status, }; } export function setDraftStatusRationale( rationale: string ): SetDraftStatusRationale { return { type: 'SET_DRAFT_STATUS_RATIONALE', rationale, }; } export function setExperimentAsRecentlySaved(): SetExperimentAsRecentlySaved { return { type: 'SET_EXPERIMENT_AS_RECENTLY_SAVED', }; } export function openAlternativePreviewer( url: string ): OpenAlternativePreviewer { return { type: 'OPEN_ALTERNATIVE_PREVIEWER', url, }; } export function closeAlternativePreviewer(): CloseAlternativePreviewer { return { type: 'CLOSE_ALTERNATIVE_PREVIEWER', }; } export function showAiAlternativeModal( alternativeId: Maybe< AlternativeId > ): ShowAiAlternativeModal { return { type: 'SHOW_AI_ALTERNATIVE_MODAL', alternativeId, }; } export function openReusableDialog( dialog: State[ 'editor' ][ 'reusableDialog' ] ): OpenReusableDialog { return { type: 'OPEN_REUSABLE_DIALOG', dialog, }; } export function closeReusableDialog(): CloseReusableDialog { return { type: 'CLOSE_REUSABLE_DIALOG', }; } // ===== // TYPES // ===== type SetActiveGoal = { readonly type: 'SET_ACTIVE_GOAL'; readonly goalId: GoalId; }; type SetActiveSegment = { readonly type: 'SET_ACTIVE_SEGMENT'; readonly segmentId: SegmentId; }; type SetExperimentAsBeingSaved = { readonly type: 'SET_EXPERIMENT_AS_BEING_SAVED'; readonly status: boolean; }; type SetDraftStatusRationale = { readonly type: 'SET_DRAFT_STATUS_RATIONALE'; readonly rationale: string; }; type SetExperimentAsRecentlySaved = { readonly type: 'SET_EXPERIMENT_AS_RECENTLY_SAVED'; }; type OpenAlternativePreviewer = { readonly type: 'OPEN_ALTERNATIVE_PREVIEWER'; readonly url: string; }; type CloseAlternativePreviewer = { readonly type: 'CLOSE_ALTERNATIVE_PREVIEWER'; }; type ShowAiAlternativeModal = { readonly type: 'SHOW_AI_ALTERNATIVE_MODAL'; readonly alternativeId: Maybe< AlternativeId >; }; type OpenReusableDialog = { readonly type: 'OPEN_REUSABLE_DIALOG'; readonly dialog: State[ 'editor' ][ 'reusableDialog' ]; }; type CloseReusableDialog = { readonly type: 'CLOSE_REUSABLE_DIALOG'; };