forked from cloudforet-io/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlertDetailInfoTableProject.vue
135 lines (120 loc) · 4.47 KB
/
AlertDetailInfoTableProject.vue
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
<script setup lang="ts">
import { computed, reactive } from 'vue';
import {
PButton, PLink, PButtonModal, PCopyButton,
} from '@cloudforet/mirinae';
import { useUserWorkspaceStore } from '@/store/app-context/workspace/user-workspace-store';
import { useAllReferenceStore } from '@/store/reference/all-reference-store';
import type { ProjectReferenceMap } from '@/store/reference/project-reference-store';
import { referenceRouter } from '@/lib/reference/referenceRouter';
import ProjectSelectDropdown from '@/common/modules/project/ProjectSelectDropdown.vue';
import { useAlertInfoItem } from '@/services/alert-manager/v1/composables/alert-info';
import { EDIT_MODE } from '@/services/alert-manager/v1/constants/alert-constant';
const props = defineProps<{
id?: string;
alertData?: Record<string, any>;
manageDisabled?: boolean;
}>();
const {
state: alertDetailItemState,
cancelEdit,
startEdit,
onClickSave,
} = useAlertInfoItem({
alertId: props.id ?? '',
isEditMode: false,
dataForUpdate: props.alertData?.project_id,
});
const allReferenceStore = useAllReferenceStore();
const userWorkspaceStore = useUserWorkspaceStore();
const state = reactive({
projects: computed<ProjectReferenceMap>(() => allReferenceStore.getters.project),
modalVisible: false,
});
const openModal = () => {
state.modalVisible = true;
};
const onSelectProject = (selected) => {
alertDetailItemState.dataForUpdate = selected[0]?.id;
};
</script>
<template>
<fragment>
<p v-if="!alertDetailItemState.isEditMode"
class="content-wrapper"
>
<span class="project">
<p-copy-button :value="props.alertData.project_id">
<p-link action-icon="internal-link"
new-tab
:to="referenceRouter(
props.alertData.project_id,
{ resource_type: 'identity.Project', workspace_id: userWorkspaceStore.getters.currentWorkspaceId },)"
highlight
>
{{ state.projects[props.alertData.project_id] ? state.projects[props.alertData.project_id].label : props.alertData.project_id }}
</p-link>
</p-copy-button>
</span>
<p-button style-type="tertiary"
size="sm"
class="add-button ml-2"
:disabled="props.manageDisabled"
@click="startEdit(props.alertData.project_id)"
>
{{ $t('MONITORING.ALERT.DETAIL.INFO.CHANGE') }}
</p-button>
</p>
<div v-else
class="content-wrapper"
>
<project-select-dropdown :selected-project-ids="alertDetailItemState.dataForUpdate ? [alertDetailItemState.dataForUpdate] : []"
project-selectable
:project-group-selectable="false"
@select="onSelectProject"
/>
<div class="button-group ml-2">
<p-button style-type="secondary"
size="sm"
class="cancel-button"
@click="cancelEdit(props.alertData.project_id)"
>
{{ $t('COMMON.TAGS.CANCEL') }}
</p-button>
<p-button style-type="primary"
size="sm"
@click="openModal"
>
{{ $t('MONITORING.ALERT.DETAIL.INFO.SAVE_CHANGES') }}
</p-button>
</div>
</div>
<p-button-modal
:header-title="$t('MONITORING.ALERT.DETAIL.INFO.CHANGE_PROJECT_MODAL_TITLE')"
centered
size="sm"
fade
backdrop
theme-color="alert"
:visible.sync="state.modalVisible"
@confirm="onClickSave(EDIT_MODE.PROJECT)"
>
<template #body>
<p class="modal-body">
{{ $t('MONITORING.ALERT.DETAIL.INFO.CHANGE_PROJECT_MODAL_DESC') }}
</p>
</template>
</p-button-modal>
</fragment>
</template>
<style lang="postcss" scoped>
@import './styles/alertInfoItem.pcss';
.modal-body {
margin-top: 2rem;
}
/* custom project-select-dropdown */
:deep(.project-select-dropdown) {
max-width: 25rem;
flex-grow: 1;
}
</style>