# All files NavigatorControl.vue

100% Statements 293/293
100% Branches 23/23
100% Functions 5/5
100% Lines 293/293

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    2941x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    6x
    1x
    1x
    1x
    5x
    1x
    1x
    1x
    6x
    6x
    6x
    6x
    1x
    1x
    1x
    7x
    2x
    2x
    2x
    2x
    2x
    1x
    1x
    6x
    3x
    3x
    3x
    1x
    1x
    10x
    10x
    10x
    1x
    1x
    2x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    6x
    6x
    1x
    1x
    8x
    1x
    1x
    10x
    10x
    6x
    6x
    4x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
     <template>
      <div :class="getNavigateClass()">
        <v-stepper :model-value="currentStep - 1">
          <template v-for="index in steps" :key="index">
            <v-stepper-item
              :editable="navigationType === 'tab' || currentStep > index"
              :title="prompts[index - 1] ? prompts[index - 1].name : ''"
              :complete="getComplete(index)"
              :class="getStepClass(currentStep, index)"
              @click="gotoStep(index)"
            />
            <div class="breadcrumbs-container">
              <BreadcrumbsContainer
                :id="`breadcrumbs-${index}`"
                class="breadcrumbs"
                :breadcrumbs="answers[prompts[index - 1] ? prompts[index - 1].name : undefined]"
                :showIconForError="showIconForError"
              />
            </div>
          </template>
        </v-stepper>
      </div>
    </template>

    <script setup>
    import { computed, ref, toRefs, unref, watchEffect } from "vue";
    import BreadcrumbsContainer from "./BreadcrumbsContainer.vue";
    import { isEmpty } from "lodash";
    const props = defineProps({
      promptIndex: {
        type: Number,
        default: 0,
      },
      prompts: {
        type: Array,
        default: () => [],
      },
      promptAnswers: {
        type: Object,
        default: () => {},
      },
      allAnswers: {
        type: Object,
        default: () => {},
      },
      navigationType: {
        type: String,
        default: "tab",
      },
      showIconForError: {
        type: Boolean,
        default: false,
      },
    });

    const { promptIndex, prompts, allAnswers, promptAnswers, navigationType, showIconForError } = toRefs(props);

    const emits = defineEmits(["onGotoStep"]);

    const answers = ref({});

    const currentStep = ref(0);

    //travel is used to keep track of the steps that have been visited
    const travel = ref({});

    const steps = computed(() => {
      return unref(prompts).length;
    });

    watchEffect(() => {
      currentStep.value = unref(promptIndex) + 1;
    });

    watchEffect(() => {
      const count = unref(prompts).length;
      for (let i = 0; i < count; i++) {
        travel.value[i + 1] = false;
      }
    });

    watchEffect(() => {
      if (unref(promptAnswers) && unref(promptAnswers).promptName && unref(promptAnswers).answers) {
        // Vue 2 requires a new object for reactivity to trigger updates
        answers.value = Object.assign({}, unref(answers), {
          [unref(promptAnswers).promptName]: unref(promptAnswers).answers,
        });
      }
    });
    watchEffect(() => {
      if (unref(allAnswers) && !isEmpty(unref(allAnswers))) {
        // Vue 2 requires a new object for reactivity to trigger updates
        answers.value = Object.assign({}, unref(answers), unref(allAnswers));
      }
    });
    const getStepClass = (currentStep, index) => {
      return {
        "step-linkable": navigationType.value === "tab" ? true : currentStep > index,
      };
    };
    const gotoStep = (index) => {
      if (navigationType.value === "tab") {
        currentStep.value = index;
        emits("onGotoStep", index - 1);
      } else {
        // numOfSteps is number of steps to go back
        const numOfSteps = currentStep.value - index;
        if (numOfSteps > 0) {
          emits("onGotoStep", numOfSteps);
        }
      }
    };
    const isTraveled = (index) => {
      travel.value[currentStep.value] = true;
      return index !== currentStep.value && !!travel.value[index];
    };
    const getNavigateClass = () => {
      return navigationType.value === "tab" ? "NavigationTabClass" : "NavigationStepperClass";
    };
    const getComplete = (index) => {
      // numOfSteps is number of steps to go back
      if (navigationType.value === "tab") {
        return isTraveled(index);
      }
      return currentStep.value > index;
    };

    defineExpose({
      gotoStep,
      steps,
      currentStep,
      getStepClass,
    });
    </script>

    <style lang="scss">
    div.NavigationTabClass {
      div.v-stepper .v-stepper-item {
        padding-left: 0px;
        padding-top: 10px;
        padding-bottom: 10px;
        opacity: 1 !important;
        /* Step bullet  */
        .v-stepper-item__avatar {
          font-size: 0px;

          background-color: var(--vscode-editor-background, white) !important;

          //background-color: transparent !important; // Required since  Vuetify `.v-application .primary` adds background-color !important
          color: var(--vscode-foreground, #616161);
          border: 1px solid;
          height: 10px !important;
          width: 10px !important;
          min-width: 10px;
          margin-right: 10px;
          transition: 0.3s ease-in-out;
          .v-icon.v-icon {
            font-size: 0;
          }
        }
        /* Step label */
        .v-stepper-item__title {
          font-weight: bold;
          font-size: 14px;
          line-height: 17px;
          color: var(
            --vscode-foreground,
            #616161
          ) !important; // Required since Vuetify adds inline color for selector: `.theme--dark.v-stepper .v-stepper__label`
          transition: 0.3s ease-in-out;
        }
        &--complete {
          .v-stepper-item__avatar {
            background-color: var(--vscode-foreground, #616161) !important;
            border-color: var(
              --vscode-foreground,
              #616161
            ) !important; // Required since Vuetify adds border-color !important for selector `.v-application .primary`
          }
        }
        &--selected {
          .v-stepper-item__title {
            color: var(
              --vscode-pickerGroup-foreground,
              #0066bf
            ) !important; // Required since Vuetify adds inline color for selector: `.theme--dark.v-stepper .v-stepper__label`
            transition: 0.3s ease-in-out;
          }
          .v-stepper-item__avatar {
            background-color: var(--vscode-pickerGroup-foreground, #0066bf) !important;
            border-color: var(
              --vscode-pickerGroup-foreground,
              #0066bf
            ) !important; // Required since Vuetify adds border-color !important for selector `.v-application .primary`
          }
        }
      }
    }

    div.NavigationStepperClass {
      div.v-stepper .v-stepper-item {
        padding-left: 0px;
        padding-top: 10px;
        padding-bottom: 10px;
        opacity: 0.4;
        /* Step bullet  */
        .v-stepper-item__avatar {
          font-size: 0px;
          background-color: transparent !important; // Required since  Vuetify `.v-application .primary` adds background-color !important
          color: var(--vscode-editor-foreground, #616161);
          border: 1px solid;
          height: 10px !important;
          width: 10px !important;
          min-width: 10px;
          margin-right: 10px;
          transition: 0.3s ease-in-out;
          .v-icon.v-icon {
            font-size: 0;
          }
        }
        /* Step label */
        .v-stepper-item__title {
          font-weight: bold;
          font-size: 14px;
          line-height: 17px;
          color: var(
            --vscode-editor-foreground,
            #616161
          ) !important; // Required since Vuetify adds inline color for selector: `.theme--dark.v-stepper .v-stepper__label`
          transition: 0.3s ease-in-out;
          text-align: left;
        }
        &--complete {
          opacity: unset !important; // Overrides the default opacity of .v-stepper-item in case of complete step
          .v-stepper-item__title {
            color: var(--vscode-textLink-foreground, #3794ff) !important;
            text-decoration-line: underline;
            cursor: pointer;
            &:hover {
              text-decoration-line: none;
            }
          }
          .v-stepper-item__avatar {
            background-color: var(
              --vscode-textLink-foreground,
              #3794ff
            ) !important; // Required since Vuetify adds background-color !important for selector `.v-application .primary`
            border: none;
          }
        }
        &--selected {
          opacity: 1 !important; // Overrides the default opacity of .v-stepper-item in case of selected step
          .v-stepper-item__avatar {
            background-color: transparent !important;
            border-color: var(
              --vscode-editor-foreground,
              #616161
            ) !important; // Required since Vuetify adds border-color !important for selector `.v-application .primary`
          }
        }
      }
    }
    div.v-application {
      div.v-stepper {
        background-color: var(--vscode-editor-background, white);
        box-shadow: none;
        padding-top: 10px;
        .breadcrumbs-container {
          margin-left: 5px;
          margin-bottom: 0px;
          margin-top: 0px;
          padding-top: 0px;
          padding-bottom: 20px;
          padding-left: 16px;
          transition: none;
          &:not(:last-child) {
            border-left: 1px solid var(--vscode-editorWidget-border, #c8c8c8);
            transition: none;
          }
          &:last-child {
            padding-left: 17px; // Adjust for border-left
          }
          .v-stepper__wrapper {
            height: auto !important; // Override inline height: 0px for complete and inactive steps.
            transition: none;
          }
          .breadcrumbs {
            transition: max-height 0.3s ease-in-out;
          }
        }
      }
    }
    </style>