META-INF.resources.js.components.SegmentsExperimentsActions.es.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.segments.experiment.web
Show all versions of com.liferay.segments.experiment.web
Liferay Segments Experiment Web
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import ClayButton from '@clayui/button';
import ClayIcon from '@clayui/icon';
import ClayLink from '@clayui/link';
import {useModal} from '@clayui/modal';
import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import SegmentsExperimentsContext from '../context.es';
import {
closeReviewAndRunExperiment,
openTerminateModal,
reviewAndRunExperiment,
runExperiment,
} from '../state/actions.es';
import {
STATUS_DRAFT,
STATUS_FINISHED_NO_WINNER,
STATUS_FINISHED_WINNER,
STATUS_PAUSED,
STATUS_RUNNING,
STATUS_TERMINATED,
} from '../util/statuses.es';
import {DispatchContext, StateContext} from './../state/context.es';
import {ReviewExperimentModal} from './ReviewExperimentModal.es';
function SegmentsExperimentsActions({
onCreateSegmentsExperiment,
onDeleteSegmentsExperiment,
onEditSegmentsExperimentStatus,
}) {
const {
experiment,
reviewExperimentModal,
variants,
viewExperimentDetailsURL,
} = useContext(StateContext);
const dispatch = useContext(DispatchContext);
const {observer, onClose} = useModal({
onClose: () => dispatch(closeReviewAndRunExperiment()),
});
const {APIService} = useContext(SegmentsExperimentsContext);
return (
<>
{experiment.status.value === STATUS_DRAFT && (
dispatch(reviewAndRunExperiment())}
>
{Liferay.Language.get('review-and-run-test')}
)}
{experiment.status.value === STATUS_RUNNING && (
dispatch(openTerminateModal())}
>
{Liferay.Language.get('terminate-test')}
)}
{experiment.status.value === STATUS_PAUSED && (
<>
onEditSegmentsExperimentStatus(
experiment,
STATUS_RUNNING
)
}
>
{Liferay.Language.get('restart-test')}
>
)}
{(experiment.status.value === STATUS_FINISHED_WINNER ||
experiment.status.value === STATUS_FINISHED_NO_WINNER) && (
<>
{Liferay.Language.get('discard-test')}
>
)}
{experiment.status.value === STATUS_TERMINATED && (
{Liferay.Language.get('create-new-test')}
)}
{reviewExperimentModal.active && (
)}
{viewExperimentDetailsURL && (
{Liferay.Language.get('view-data-in-analytics-cloud')}
)}
>
);
function _handleRunExperiment({
confidenceLevel,
segmentsExperimentType,
splitVariantsMap,
}) {
const body = {
confidenceLevel,
segmentsExperimentId: experiment.segmentsExperimentId,
segmentsExperimentRels: JSON.stringify(splitVariantsMap),
segmentsExperimentType,
status: STATUS_RUNNING,
};
return APIService.runExperiment(body).then((response) => {
const {segmentsExperiment} = response;
dispatch(
runExperiment({
experiment: segmentsExperiment,
splitVariantsMap,
})
);
});
}
}
SegmentsExperimentsActions.propTypes = {
onCreateSegmentsExperiment: PropTypes.func.isRequired,
onEditSegmentsExperimentStatus: PropTypes.func.isRequired,
};
export default SegmentsExperimentsActions;