summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/packages_and_registries/container_registry/explorer/components/details_page/delete_modal.vue
blob: 7a8a1bbcf092722a613dbea869c5bb15d0aeefc9 (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
<script>
import { GlModal, GlSprintf, GlFormInput } from '@gitlab/ui';
import { n__ } from '~/locale';
import {
  REMOVE_TAG_CONFIRMATION_TEXT,
  REMOVE_TAGS_CONFIRMATION_TEXT,
  DELETE_IMAGE_CONFIRMATION_TITLE,
  DELETE_IMAGE_CONFIRMATION_TEXT,
} from '../../constants';

export default {
  components: {
    GlModal,
    GlSprintf,
    GlFormInput,
  },
  props: {
    itemsToBeDeleted: {
      type: Array,
      required: false,
      default: () => [],
    },
    deleteImage: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      projectPath: '',
    };
  },
  computed: {
    imageProjectPath() {
      return this.itemsToBeDeleted[0]?.project?.path;
    },
    modalTitle() {
      if (this.deleteImage) {
        return DELETE_IMAGE_CONFIRMATION_TITLE;
      }
      return n__(
        'ContainerRegistry|Remove tag',
        'ContainerRegistry|Remove tags',
        this.itemsToBeDeleted.length,
      );
    },
    modalDescription() {
      if (this.deleteImage) {
        return {
          message: DELETE_IMAGE_CONFIRMATION_TEXT,
          item: this.imageProjectPath,
        };
      }
      if (this.itemsToBeDeleted.length > 1) {
        return {
          message: REMOVE_TAGS_CONFIRMATION_TEXT,
          item: this.itemsToBeDeleted.length,
        };
      }

      const [first] = this.itemsToBeDeleted;
      return {
        message: REMOVE_TAG_CONFIRMATION_TEXT,
        item: first?.path,
      };
    },
    disablePrimaryButton() {
      return this.deleteImage && this.projectPath !== this.imageProjectPath;
    },
  },
  methods: {
    show() {
      this.$refs.deleteModal.show();
    },
  },
};
</script>

<template>
  <gl-modal
    ref="deleteModal"
    modal-id="delete-tag-modal"
    ok-variant="danger"
    size="sm"
    :action-primary="{
      text: __('Delete'),
      attributes: [{ variant: 'danger' }, { disabled: disablePrimaryButton }],
    }"
    :action-cancel="{ text: __('Cancel') }"
    @primary="$emit('confirmDelete')"
    @cancel="$emit('cancelDelete')"
    @change="projectPath = ''"
  >
    <template #modal-title>{{ modalTitle }}</template>
    <p v-if="modalDescription" data-testid="description">
      <gl-sprintf :message="modalDescription.message">
        <template #item>
          <b>{{ modalDescription.item }}</b>
        </template>
        <template #code>
          <code>{{ modalDescription.item }}</code>
        </template>
      </gl-sprintf>
    </p>
    <div v-if="deleteImage">
      <gl-form-input v-model="projectPath" />
    </div>
  </gl-modal>
</template>