Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deployment_view_button.vue « deployment « components « vue_merge_request_widget « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5efa0e2879e18b275ad6ded7266a9f2557225d1d (plain)
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
<script>
import {
  GlButtonGroup,
  GlDropdown,
  GlDropdownItem,
  GlIcon,
  GlLink,
  GlSearchBoxByType,
} from '@gitlab/ui';
import { isSafeURL } from '~/lib/utils/url_utility';
import { s__, __ } from '~/locale';
import autofocusonshow from '~/vue_shared/directives/autofocusonshow';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import ReviewAppLink from '../review_app_link.vue';

export default {
  name: 'DeploymentViewButton',
  components: {
    GlButtonGroup,
    GlDropdown,
    GlDropdownItem,
    GlIcon,
    GlLink,
    GlSearchBoxByType,
    ModalCopyButton,
    ReviewAppLink,
  },
  directives: {
    autofocusonshow,
  },
  props: {
    appButtonText: {
      type: Object,
      required: true,
    },
    deployment: {
      type: Object,
      required: true,
    },
  },
  data() {
    return { searchTerm: '' };
  },
  computed: {
    deploymentExternalUrl() {
      if (this.deployment.changes && this.deployment.changes.length === 1) {
        return this.deployment.changes[0].external_url;
      }
      return this.deployment.external_url;
    },
    shouldRenderDropdown() {
      return this.deployment.changes && this.deployment.changes.length > 1;
    },
    filteredChanges() {
      return this.deployment?.changes?.filter((change) => change.path.includes(this.searchTerm));
    },
    isSafeUrl() {
      return isSafeURL(this.deploymentExternalUrl);
    },
  },
  i18n: {
    copy: __('Copy URL'),
    copyTitle: s__('Environments|Copy live environment URL'),
  },
};
</script>
<template>
  <span class="gl-display-inline-flex">
    <gl-button-group v-if="shouldRenderDropdown" size="small">
      <review-app-link
        v-if="isSafeUrl"
        :display="appButtonText"
        :link="deploymentExternalUrl"
        size="small"
        css-class="deploy-link js-deploy-url inline gl-ml-3"
      />
      <modal-copy-button
        v-else
        :title="$options.i18n.copyTitle"
        :text="deploymentExternalUrl"
        size="small"
      >
        {{ $options.i18n.copy }}
      </modal-copy-button>
      <gl-dropdown toggle-class="gl-px-2!" size="small" class="js-mr-wigdet-deployment-dropdown">
        <template #button-content>
          <gl-icon
            class="dropdown-chevron gl-mx-0!"
            name="chevron-down"
            data-testid="mr-wigdet-deployment-dropdown-icon"
          />
        </template>
        <gl-search-box-by-type v-model.trim="searchTerm" v-autofocusonshow autofocus />
        <gl-dropdown-item
          v-for="change in filteredChanges"
          :key="change.path"
          class="js-filtered-dropdown-result"
        >
          <gl-link
            :href="change.external_url"
            target="_blank"
            rel="noopener noreferrer nofollow"
            class="js-deploy-url-menu-item menu-item"
          >
            <strong class="str-truncated-100 gl-mb-0 gl-display-block">{{ change.path }}</strong>
            <p class="text-secondary str-truncated-100 gl-mb-0 d-block">
              {{ change.external_url }}
            </p>
          </gl-link>
        </gl-dropdown-item>
      </gl-dropdown>
    </gl-button-group>
    <template v-else>
      <review-app-link
        v-if="isSafeUrl"
        :display="appButtonText"
        :link="deploymentExternalUrl"
        size="small"
        css-class="deploy-link js-deploy-url inline gl-ml-3"
      />
      <modal-copy-button
        v-else
        :title="$options.i18n.copyTitle"
        :text="deploymentExternalUrl"
        size="small"
      >
        {{ $options.i18n.copy }}
      </modal-copy-button>
    </template>
  </span>
</template>