Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const handleJoyrideCallback = (data) => {
const {
action, index, type, status,
} = data;
if ([EVENTS.TOUR_START].includes(type)) {
document.addEventListener('mouseup', onClick);
} else if ([ACTIONS.START].includes(action) && index === 0) {
// if the guide is restarted there will be no EVENTS.TOUR_START, the EventListener must
// be added on ACTION.START and step 0.
document.addEventListener('mouseup', onClick);
} else if ([ACTIONS.CLOSE].includes(action) || [STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
if (runGuide) {
endGuide();
}
} else if ([EVENTS.STEP_AFTER].includes(type)) {
const newStepIndex = index + (action === ACTIONS.PREV ? -1 : 1);
if (action !== ACTIONS.PREV && !readyToProceed(newStepIndex)) {
// we are not ready to proceed to the next step. Reset the current step.
// The stop/start of the guide is needed to reset the Joyride events, or it will
// be somewhere in between steps, statewise.
setRunGuide(false);
setStepIndex(index);
setTimeout(() => setRunGuide(true), 100);
} else {
// Update state to advance the guide
setStepIndex(newStepIndex);
}
} else if ([EVENTS.TARGET_NOT_FOUND].includes(type)) {
// The target could not be found. Go to next step.
const newStepIndex = index + 1;
setStepIndex(newStepIndex);
callback={data => {
const { action, index, type, status, step } = data;
const { actions } = step || {};
const { prev, next } = actions || {};
if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
// Need to set our running state to false, so we can restart if we click start again.
handleStateChange({ open: false, stepIndex: 0, stepsKey: '' });
} else if (data.action === 'close' || data.type === 'tour:end') {
handleStateChange({
stepIndex: 0,
open: false
});
} else if (
[
EVENTS.STEP_AFTER,
EVENTS.TARGET_NOT_FOUND,
EVENTS.TOUR_START
].includes(type)
) {
const newStepIndex = index + (action === ACTIONS.PREV ? -1 : 1);
// Update state to advance the tour
let delay = 400;
if (action === 'prev' && prev) {
prev();
}
if (action === 'next' && next) {
next();
}
handleJoyrideCallback = tour => {
const { action, index, type } = tour;
if (type === EVENTS.TOUR_END || action === EVENTS.TOOLTIP_CLOSE || type === EVENTS.STEP_AFTER && index >= lastStepIndex) {
logEvent('tour', index >= lastStepIndex ? 'complete' : 'skip', index);
// Update user preferences with completed tour flag
this.setState({
stepIndex: 0,
run: false
});
this.props.setConfig({
showTour: false
});
} else if (type === EVENTS.STEP_AFTER) {
// Since this is a controlled tour you'll need to update the state to advance the tour
this.setState({
stepIndex: index + (action === ACTIONS.PREV ? -1 : 1)
});
}
}
RendererAnalytics.event({category: 'tour-skip', action: 'skipped-at-step-' + callbackProps.index});
LifecycleToggle.mark(LifecycleEvents.TOUR_SKIPPED);
break;
case STATUS.FINISHED:
RendererAnalytics.event({category: 'tour-result', action: 'finished'});
LifecycleToggle.mark(LifecycleEvents.TOUR_FINISHED);
break;
}
} finally {
LifecycleToggle.mark(LifecycleEvents.TOUR_TERMINATED);
}
} else if (callbackProps.type === EVENTS.STEP_AFTER) {
if ( ! this.state.run) {
setTimeout(() => {
this.setState({
...this.state,
run: true
});
}, 250);
return;
}