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

artifacts_table_row_details.vue « components « artifacts « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a826d0d4625cbef0b885646a6e04cdbfb6fbb24 (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
<script>
import { createAlert } from '~/flash';
import { DynamicScroller, DynamicScrollerItem } from 'vendor/vue-virtual-scroller';
import getJobArtifactsQuery from '../graphql/queries/get_job_artifacts.query.graphql';
import destroyArtifactMutation from '../graphql/mutations/destroy_artifact.mutation.graphql';
import { removeArtifactFromStore } from '../graphql/cache_update';
import {
  I18N_DESTROY_ERROR,
  ARTIFACT_ROW_HEIGHT,
  ARTIFACTS_SHOWN_WITHOUT_SCROLLING,
} from '../constants';
import ArtifactRow from './artifact_row.vue';
import ArtifactDeleteModal from './artifact_delete_modal.vue';

export default {
  name: 'ArtifactsTableRowDetails',
  components: {
    DynamicScroller,
    DynamicScrollerItem,
    ArtifactRow,
    ArtifactDeleteModal,
  },
  props: {
    artifacts: {
      type: Object,
      required: true,
    },
    queryVariables: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isModalVisible: false,
      deleteInProgress: false,
      deletingArtifactId: null,
      deletingArtifactName: '',
    };
  },
  computed: {
    scrollContainerStyle() {
      /*
       limit the height of the expanded artifacts container to a number of artifacts
       if a job has more artifacts than ARTIFACTS_SHOWN_WITHOUT_SCROLLING, scroll to see the rest
       add one pixel to row height to account for borders
      */
      return { maxHeight: `${ARTIFACTS_SHOWN_WITHOUT_SCROLLING * (ARTIFACT_ROW_HEIGHT + 1)}px` };
    },
  },
  methods: {
    isLastRow(index) {
      return index === this.artifacts.nodes.length - 1;
    },
    showModal(item) {
      this.deletingArtifactId = item.id;
      this.deletingArtifactName = item.name;
      this.isModalVisible = true;
    },
    hideModal() {
      this.isModalVisible = false;
    },
    clearModal() {
      this.deletingArtifactId = null;
      this.deletingArtifactName = '';
    },
    destroyArtifact() {
      const id = this.deletingArtifactId;
      this.deleteInProgress = true;

      this.$apollo
        .mutate({
          mutation: destroyArtifactMutation,
          variables: { id },
          update: (store) => {
            removeArtifactFromStore(store, id, getJobArtifactsQuery, this.queryVariables);
          },
        })
        .catch(() => {
          createAlert({
            message: I18N_DESTROY_ERROR,
          });
          this.$emit('refetch');
        })
        .finally(() => {
          this.deleteInProgress = false;
          this.clearModal();
        });
    },
  },
  ARTIFACT_ROW_HEIGHT,
};
</script>
<template>
  <div :style="scrollContainerStyle">
    <dynamic-scroller :items="artifacts.nodes" :min-item-size="$options.ARTIFACT_ROW_HEIGHT">
      <template #default="{ item, index, active }">
        <dynamic-scroller-item :item="item" :active="active" :class="{ active }">
          <artifact-row
            :artifact="item"
            :is-last-row="isLastRow(index)"
            @delete="showModal(item)"
          />
        </dynamic-scroller-item>
      </template>
    </dynamic-scroller>
    <artifact-delete-modal
      :artifact-name="deletingArtifactName"
      :visible="isModalVisible"
      :delete-in-progress="deleteInProgress"
      @primary="destroyArtifact"
      @cancel="hideModal"
      @close="hideModal"
      @hide="hideModal"
      @hidden="clearModal"
    />
  </div>
</template>