/** * External dependencies */ import type { ExperimentId, Maybe } from '@nab/types'; /** * Internal dependencies */ import type { State, ViewEvent, ConversionEvent, ClickEvent } from './types'; import type { SegmentationSettings } from '../../public/utils/segmentation/segmentation-settings'; export type Action = | AddViewEvent | AddConversionEvent | AddClickEvent | AddNewPage | SetAlternative | SetCloudConnection | SetGdprStatus | SetHighlightedClick | SetNewAlternative | SetNewActiveSegments | SetPageName | SetPosition | SetSegmentation | SetSettings | SetStatus | SetTab | SetViews; export function setPosition( position: State[ 'position' ] ): SetPosition { return { type: 'SET_POSITION', position, }; } export function setTab( tab: State[ 'tab' ] ): SetTab { return { type: 'SET_TAB', tab, }; } export function setStatus( status: State[ 'status' ] ): SetStatus { return { type: 'SET_STATUS', status, }; } export function setCloudConnection( connected: boolean ): SetCloudConnection { return { type: 'SET_CLOUD_CONNECTION', connected, }; } export function setGdprStatus( status: 'awaiting' | 'ready' ): SetGdprStatus { return { type: 'SET_GDPR_STATUS', status, }; } export function addNewPage( url: string ): AddNewPage { return { type: 'ADD_NEW_PAGE', url, }; } export function setPageName( name: string ): SetPageName { return { type: 'SET_PAGE_NAME', name, }; } export function setSettings( settings: Partial< State[ 'settings' ] > ): SetSettings { return { type: 'SET_SETTINGS', settings, }; } export function setAlternative( value: number ): SetAlternative { return { type: 'SET_ALTERNATIVE', value, }; } export function setSegmentation( value: SegmentationSettings ): SetSegmentation { return { type: 'SET_SEGMENTATION', value, }; } export function setViews( value: State[ 'cookies' ][ 'views' ] ): SetViews { return { type: 'SET_VIEWS', value, }; } export function addViewEvent( event: ViewEvent ): AddViewEvent { return { type: 'ADD_VIEW_EVENT', event, }; } export function addConversionEvent( event: ConversionEvent ): AddConversionEvent { return { type: 'ADD_CONVERSION_EVENT', event, }; } export function addClickEvent( event: ClickEvent ): AddClickEvent { return { type: 'ADD_CLICK_EVENT', event, }; } export function setHighlightedClick( selector: Maybe< ClickEvent > ): SetHighlightedClick { return { type: 'SET_HIGHLIGHTED_CLICK', selector, }; } export function setNewAlternative( value: number ): SetNewAlternative { return { type: 'SET_NEW_ALTERNATIVE', value, }; } export function setNewActiveSegments( experimentId: ExperimentId, segments: ReadonlyArray< number > ): SetNewActiveSegments { return { type: 'SET_NEW_ACTIVE_SEGMENTS', experimentId, segments, }; } // ============ // HELPER TYPES // ============ type SetStatus = { readonly type: 'SET_STATUS'; readonly status: State[ 'status' ]; }; type SetTab = { readonly type: 'SET_TAB'; readonly tab: State[ 'tab' ]; }; type SetCloudConnection = { readonly type: 'SET_CLOUD_CONNECTION'; readonly connected: boolean; }; type SetGdprStatus = { readonly type: 'SET_GDPR_STATUS'; readonly status: 'awaiting' | 'ready'; }; type AddNewPage = { readonly type: 'ADD_NEW_PAGE'; readonly url: string; }; type SetPageName = { readonly type: 'SET_PAGE_NAME'; readonly name: string; }; type SetSettings = { readonly type: 'SET_SETTINGS'; readonly settings: Partial< State[ 'settings' ] >; }; type SetAlternative = { readonly type: 'SET_ALTERNATIVE'; readonly value: number; }; type SetSegmentation = { readonly type: 'SET_SEGMENTATION'; readonly value: SegmentationSettings; }; type SetViews = { readonly type: 'SET_VIEWS'; readonly value: State[ 'cookies' ][ 'views' ]; }; type AddViewEvent = { readonly type: 'ADD_VIEW_EVENT'; readonly event: ViewEvent; }; type AddConversionEvent = { readonly type: 'ADD_CONVERSION_EVENT'; readonly event: ConversionEvent; }; type AddClickEvent = { readonly type: 'ADD_CLICK_EVENT'; readonly event: ClickEvent; }; type SetPosition = { readonly type: 'SET_POSITION'; readonly position: State[ 'position' ]; }; type SetHighlightedClick = { readonly type: 'SET_HIGHLIGHTED_CLICK'; readonly selector: Maybe< ClickEvent >; }; type SetNewAlternative = { readonly type: 'SET_NEW_ALTERNATIVE'; readonly value: number; }; type SetNewActiveSegments = { readonly type: 'SET_NEW_ACTIVE_SEGMENTS'; readonly experimentId: ExperimentId; readonly segments: ReadonlyArray< number >; };