• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/js/utils/onboardingmanager.js
1
// Copyright 2019 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React from 'react';
15

16
import BaseOnboardingTip from '../components/helptips/baseonboardingtip';
17
import OnboardingCompleteTip from '../components/helptips/onboardingcompletetip';
18
import {
19
  DashboardOnboardingPendings,
20
  DashboardOnboardingState,
21
  DeploymentsInprogress,
22
  DeploymentsPast,
23
  DeploymentsPastCompletedFailure,
24
  DevicePendingTip,
25
  DevicesAcceptedOnboarding,
26
  DevicesDeployReleaseOnboarding,
27
  DevicesPendingAcceptingOnboarding,
28
  DevicesPendingDelayed,
29
  GetStartedTip,
30
  SchedulingAllDevicesSelection,
31
  SchedulingArtifactSelection,
32
  SchedulingGroupSelection,
33
  SchedulingReleaseToDevices
34
} from '../components/helptips/onboardingtips';
35
import { yes } from '../constants/appConstants';
36
import { DEPLOYMENT_STATES } from '../constants/deploymentConstants';
37
import { onboardingSteps as stepNames } from '../constants/onboardingConstants';
38

39
export const onboardingSteps = {
183✔
40
  [stepNames.DASHBOARD_ONBOARDING_START]: {
41
    condition: { min: stepNames.ONBOARDING_START },
42
    specialComponent: <GetStartedTip />
43
  },
44
  [stepNames.DEVICES_PENDING_ONBOARDING_START]: {
45
    condition: { min: stepNames.DASHBOARD_ONBOARDING_START, max: stepNames.DEVICES_PENDING_ONBOARDING },
46
    fallbackStep: stepNames.DASHBOARD_ONBOARDING_START,
47
    specialComponent: <DevicePendingTip />
48
  },
49
  [stepNames.DEVICES_DELAYED_ONBOARDING]: {
50
    condition: { min: stepNames.DASHBOARD_ONBOARDING_START },
51
    component: DevicesPendingDelayed,
52
    fallbackStep: stepNames.DASHBOARD_ONBOARDING_START,
53
    extra: ({ deviceConnection }) => {
54
      const now = new Date();
×
55
      const then = new Date(deviceConnection);
×
56
      then.setMinutes(then.getMinutes() + 5);
×
57
      return !!deviceConnection && then < now;
×
58
    }
59
  },
60
  [stepNames.DEVICES_PENDING_ONBOARDING]: {
61
    condition: { min: stepNames.DASHBOARD_ONBOARDING_START },
62
    component: DashboardOnboardingState,
63
    fallbackStep: stepNames.DASHBOARD_ONBOARDING_START
64
  },
65
  [stepNames.DEVICES_PENDING_ACCEPTING_ONBOARDING]: {
66
    condition: { min: stepNames.DEVICES_PENDING_ONBOARDING, max: stepNames.DEVICES_ACCEPTED_ONBOARDING },
67
    component: DevicesPendingAcceptingOnboarding
68
  },
69
  [stepNames.DASHBOARD_ONBOARDING_PENDINGS]: {
70
    condition: { min: stepNames.DEVICES_PENDING_ONBOARDING },
71
    component: DashboardOnboardingPendings
72
  },
73
  [stepNames.DEVICES_ACCEPTED_ONBOARDING]: {
74
    condition: { min: stepNames.DASHBOARD_ONBOARDING_PENDINGS },
75
    specialComponent: <DevicesAcceptedOnboarding />
76
  },
77
  [stepNames.DEVICES_DEPLOY_RELEASE_ONBOARDING]: {
78
    condition: {},
79
    component: DevicesDeployReleaseOnboarding
80
  },
81
  [stepNames.SCHEDULING_ALL_DEVICES_SELECTION]: {
82
    condition: { min: stepNames.DEVICES_ACCEPTED_ONBOARDING, max: stepNames.DEPLOYMENTS_INPROGRESS },
83
    component: SchedulingAllDevicesSelection
84
  },
85
  [stepNames.SCHEDULING_GROUP_SELECTION]: {
86
    condition: { min: stepNames.DEVICES_ACCEPTED_ONBOARDING, max: stepNames.DEPLOYMENTS_INPROGRESS },
87
    component: SchedulingGroupSelection
88
  },
89
  [stepNames.SCHEDULING_ARTIFACT_SELECTION]: {
90
    condition: { min: stepNames.SCHEDULING_ALL_DEVICES_SELECTION, max: stepNames.DEPLOYMENTS_INPROGRESS },
91
    component: SchedulingArtifactSelection
92
  },
93
  [stepNames.SCHEDULING_RELEASE_TO_DEVICES]: {
94
    condition: { min: stepNames.SCHEDULING_ARTIFACT_SELECTION, max: stepNames.DEPLOYMENTS_INPROGRESS },
95
    component: SchedulingReleaseToDevices
96
  },
97
  [stepNames.DEPLOYMENTS_INPROGRESS]: {
98
    condition: {},
99
    component: DeploymentsInprogress
100
  },
101
  [stepNames.DEPLOYMENTS_PAST]: {
102
    condition: { min: stepNames.DEPLOYMENTS_INPROGRESS, extra: () => !window.location.pathname.includes(DEPLOYMENT_STATES.finished) },
×
103
    component: DeploymentsPast
104
  },
105
  [stepNames.DEPLOYMENTS_PAST_COMPLETED]: {
106
    condition: { max: stepNames.DEPLOYMENTS_PAST_COMPLETED_FAILURE },
107
    specialComponent: <OnboardingCompleteTip targetUrl="destination-unreachable" />
108
  },
109
  [stepNames.DEPLOYMENTS_PAST_COMPLETED_FAILURE]: {
110
    condition: { max: stepNames.ONBOARDING_CANCELED },
111
    component: DeploymentsPastCompletedFailure
112
  },
113
  [stepNames.ONBOARDING_CANCELED]: {
114
    condition: {},
115
    specialComponent: <div />
116
  }
117
};
118

119
const getOnboardingStepCompleted = (id, onboardingState) => {
183✔
120
  const { progress, complete, showTips } = onboardingState;
2,178✔
121
  const keys = Object.keys(onboardingSteps);
2,178✔
122
  const {
123
    condition: { min = id, max = id },
1,844✔
124
    extra,
125
    progressIndex
126
  } = Object.entries(onboardingSteps).reduce(
2,178✔
127
    (accu, [key, value], index) => {
128
      accu = key === id ? { ...accu, ...value } : accu;
37,026✔
129
      accu.progressIndex = key === progress ? index : accu.progressIndex;
37,026✔
130
      return accu;
37,026✔
131
    },
132
    { progressIndex: 0, extra: yes, condition: { min: id, max: id } }
133
  );
134
  return (
2,178✔
135
    !complete &&
4,092!
136
    showTips &&
137
    progressIndex >= keys.findIndex(step => step === min) &&
×
138
    progressIndex <= keys.findIndex(step => step === max) &&
×
139
    extra(onboardingState)
140
  );
141
};
142

143
export const getOnboardingComponentFor = (id, componentProps, params = {}, previousComponent = null) => {
183!
144
  const step = onboardingSteps[id];
2,178✔
145
  const isValid = getOnboardingStepCompleted(id, componentProps);
2,178✔
146
  if (!isValid) {
2,178!
147
    return previousComponent;
2,178✔
148
  }
149
  if (step.specialComponent) {
×
150
    // const Component = step.specialComponent
151
    return React.cloneElement(step.specialComponent, params);
×
152
  }
153
  const component = step.component(componentProps);
×
154
  return <BaseOnboardingTip id={id} component={component} progress={step.progress || params.progress || null} {...params} />;
×
155
};
156

157
export const applyOnboardingFallbacks = progress => {
183✔
158
  const step = onboardingSteps[progress];
6✔
159
  if (step && step.fallbackStep) {
6!
160
    return step.fallbackStep;
×
161
  }
162
  return progress;
6✔
163
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc