-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: apply API at service detail header (edit / delete) (#5211)
Signed-off-by: NaYeong,Kim <[email protected]>
- Loading branch information
Showing
4 changed files
with
251 additions
and
35 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
apps/web/src/services/alert-manager-v2/components/ServiceDetailDeleteModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script setup lang="ts"> | ||
import { reactive } from 'vue'; | ||
import { useRouter } from 'vue-router/composables'; | ||
import { PButtonModal } from '@cloudforet/mirinae'; | ||
import { useProperRouteLocation } from '@/common/composables/proper-route-location'; | ||
import { useProxyValue } from '@/common/composables/proxy-state'; | ||
import { ALERT_MANAGER_ROUTE_V2 } from '@/services/alert-manager-v2/routes/route-constant'; | ||
import { useServiceDetailPageStore } from '@/services/alert-manager-v2/stores/service-detail-page-store'; | ||
interface Props { | ||
visible: boolean; | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
visible: false, | ||
}); | ||
const serviceDetailPageStore = useServiceDetailPageStore(); | ||
const router = useRouter(); | ||
const { getProperRouteLocation } = useProperRouteLocation(); | ||
const emit = defineEmits<{(e: 'update:visible'): void; }>(); | ||
const state = reactive({ | ||
loading: false, | ||
proxyVisible: useProxyValue('visible', props, emit), | ||
}); | ||
const handleConfirm = () => { | ||
state.loading = true; | ||
try { | ||
serviceDetailPageStore.deleteServiceDetailData(); | ||
router.push(getProperRouteLocation({ name: ALERT_MANAGER_ROUTE_V2.SERVICE._NAME })); | ||
} finally { | ||
state.loading = false; | ||
handleClose(); | ||
} | ||
}; | ||
const handleClose = () => { | ||
state.proxyVisible = false; | ||
}; | ||
</script> | ||
|
||
<template> | ||
<p-button-modal class="service-detail-delete-modal" | ||
:header-title="$t('ALERT_MANAGER.SERVICE.MODAL_DELETE_TITLE')" | ||
size="sm" | ||
theme-color="alert" | ||
:fade="true" | ||
:backdrop="true" | ||
:visible="state.proxyVisible" | ||
:loading="state.loading" | ||
@confirm="handleConfirm" | ||
@cancel="handleClose" | ||
@close="handleClose" | ||
/> | ||
</template> |
106 changes: 106 additions & 0 deletions
106
apps/web/src/services/alert-manager-v2/components/ServiceDetailEditModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<script setup lang="ts"> | ||
import { computed, onMounted, reactive } from 'vue'; | ||
import { PButtonModal, PFieldGroup, PTextInput } from '@cloudforet/mirinae'; | ||
import type { ServiceModel } from '@/schema/alert-manager/service/model'; | ||
import { i18n } from '@/translations'; | ||
import { useFormValidator } from '@/common/composables/form-validator'; | ||
import { useProxyValue } from '@/common/composables/proxy-state'; | ||
import { useServiceDetailPageStore } from '@/services/alert-manager-v2/stores/service-detail-page-store'; | ||
interface Props { | ||
visible: boolean; | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
visible: false, | ||
}); | ||
const serviceDetailPageStore = useServiceDetailPageStore(); | ||
const serviceDetailPageState = serviceDetailPageStore.state; | ||
const serviceDetailPageGetters = serviceDetailPageStore.getters; | ||
const emit = defineEmits<{(e: 'update:visible'): void; }>(); | ||
const storeState = reactive({ | ||
serviceList: computed<ServiceModel[]>(() => serviceDetailPageState.serviceList), | ||
serviceName: computed<string>(() => serviceDetailPageGetters.serviceInfo.name), | ||
}); | ||
const state = reactive({ | ||
loading: false, | ||
proxyVisible: useProxyValue('visible', props, emit), | ||
}); | ||
const { | ||
forms: { | ||
name, | ||
}, | ||
setForm, | ||
invalidState, | ||
invalidTexts, | ||
isAllValid, | ||
} = useFormValidator({ | ||
name: storeState.serviceName, | ||
}, { | ||
name(value: string) { | ||
if (!value) return ' '; | ||
const duplicatedName = storeState.serviceList?.find((item) => item.name === value); | ||
if (duplicatedName) { | ||
return i18n.t('ALERT_MANAGER.SERVICE.VALIDATION_NAME_UNIQUE'); | ||
} | ||
return ''; | ||
}, | ||
}); | ||
const handleConfirm = async () => { | ||
state.loading = true; | ||
try { | ||
await serviceDetailPageStore.updateServiceDetailData(name.value); | ||
} finally { | ||
state.loading = false; | ||
handleClose(); | ||
} | ||
}; | ||
const handleClose = () => { | ||
state.proxyVisible = false; | ||
}; | ||
onMounted(() => { | ||
serviceDetailPageStore.fetchServiceList(); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<p-button-modal class="service-detail-edit-modal" | ||
:header-title="$t('ALERT_MANAGER.SERVICE.MODAL_EDIT_TITLE')" | ||
size="sm" | ||
:fade="true" | ||
:backdrop="true" | ||
:visible="state.proxyVisible" | ||
:disabled="!isAllValid" | ||
:loading="state.loading" | ||
@confirm="handleConfirm" | ||
@cancel="handleClose" | ||
@close="handleClose" | ||
> | ||
<template #body> | ||
<div class="form-contents"> | ||
<p-field-group :label="$t('ALERT_MANAGER.SERVICE.LABEL_SERVICE_NAME')" | ||
:invalid="invalidState.name" | ||
:invalid-text="invalidTexts.name" | ||
class="input-form" | ||
required | ||
> | ||
<p-text-input :value="name" | ||
:invalid="invalidState.name" | ||
class="text-input" | ||
block | ||
@update:value="setForm('name', $event)" | ||
/> | ||
</p-field-group> | ||
</div> | ||
</template> | ||
</p-button-modal> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters