frontend/src/components/NamespacesCreateYaml.vue
<!-- NamespacesCreateYaml.vue -->
<template>
<div v-if="show" class="modal-overlay" @click="closeModal">
<div class="modal-content yaml-editor" @click.stop>
<div class="modal-header">
<h3>Create Namespace from YAML</h3>
<button class="close-button" @click="closeModal">×</button>
</div>
<div class="modal-body">
<div v-if="error" class="error-message">{{ error }}</div>
<div class="yaml-container">
<textarea
v-model="yamlContent"
placeholder="Paste your Namespace YAML definition here..."
:disabled="isSubmitting"
class="yaml-textarea"
></textarea>
</div>
</div>
<div class="modal-footer">
<button
class="cancel-button"
@click="closeModal"
:disabled="isSubmitting"
>
Cancel
</button>
<button
class="create-button"
@click="createNamespaceFromYaml"
:disabled="isSubmitting || !yamlContent.trim()"
>
{{ isSubmitting ? 'Creating...' : 'Create Namespace' }}
</button>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
export default defineComponent({
name: 'CreateNamespaceYaml',
props: {
show: {
type: Boolean,
default: false
}
},
emits: ['close', 'create-namespace'],
setup(props, { emit }) {
// State
const yamlContent = ref('');
const isSubmitting = ref(false);
const error = ref('');
// Methods
const closeModal = () => {
if (!isSubmitting.value) {
emit('close');
}
};
const createNamespaceFromYaml = async () => {
isSubmitting.value = true;
error.value = '';
try {
const opts = {
yamlContent: yamlContent.value,
isYaml: true
};
emit('create-namespace', opts);
closeModal();
} catch (err: any) {
error.value = `Failed to create Namespace: ${err.message || err}`;
} finally {
isSubmitting.value = false;
}
};
return {
yamlContent,
isSubmitting,
error,
closeModal,
createNamespaceFromYaml
};
}
});
</script>
<style src="@/assets/css/MenuDialog.css" scoped></style>