-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathDeprecatePackageModal.vue
More file actions
176 lines (157 loc) · 5.74 KB
/
DeprecatePackageModal.vue
File metadata and controls
176 lines (157 loc) · 5.74 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<script setup lang="ts">
import type { NewOperation } from '~/composables/useConnector'
const props = withDefaults(
defineProps<{
packageName: string
version?: string
}>(),
{ version: '' },
)
const { t } = useI18n()
const { isConnected, state, addOperation, approveOperation, executeOperations, refreshState } =
useConnector()
const deprecateMessage = ref('')
const deprecateVersion = ref(props.version)
const isDeprecating = shallowRef(false)
const deprecateSuccess = shallowRef(false)
const deprecateError = shallowRef<string | null>(null)
const connectorModal = useModal('connector-modal')
const modalTitle = computed(() =>
deprecateVersion.value
? `${$t('package.deprecation.modal.title')} ${props.packageName}@${deprecateVersion.value}`
: `${$t('package.deprecation.modal.title')} ${props.packageName}`,
)
async function handleDeprecate() {
const message = deprecateMessage.value.trim()
if (!message || !isConnected.value) return
isDeprecating.value = true
deprecateError.value = null
try {
const params: Record<string, string> = {
pkg: props.packageName,
message,
}
if (deprecateVersion.value.trim()) {
params.version = deprecateVersion.value.trim()
}
const command = params.version
? `npm deprecate ${props.packageName}@${params.version} "${message}"`
: `npm deprecate ${props.packageName} "${message}"`
const operation = await addOperation({
type: 'package:deprecate',
params,
description: params.version
? `Deprecate ${props.packageName}@${params.version}`
: `Deprecate ${props.packageName}`,
command,
} as NewOperation)
if (!operation) {
throw new Error('Failed to create operation')
}
await approveOperation(operation.id)
await executeOperations()
await refreshState()
const completedOp = state.value.operations.find(op => op.id === operation.id)
if (completedOp?.status === 'completed') {
deprecateSuccess.value = true
} else if (completedOp?.status === 'failed') {
if (completedOp.result?.requiresOtp) {
close()
connectorModal.open()
} else {
deprecateError.value = completedOp.result?.stderr || t('deprecate.modal.failed')
}
} else {
close()
connectorModal.open()
}
} catch (err) {
deprecateError.value = err instanceof Error ? err.message : t('deprecate.modal.failed')
} finally {
isDeprecating.value = false
}
}
const dialogRef = ref<HTMLDialogElement>()
function open() {
deprecateError.value = null
deprecateSuccess.value = false
deprecateMessage.value = ''
deprecateVersion.value = props.version ?? ''
dialogRef.value?.showModal()
}
function close() {
dialogRef.value?.close()
}
defineExpose({ open, close })
</script>
<template>
<Modal ref="dialogRef" :modal-title="modalTitle" id="deprecate-package-modal" class="max-w-md">
<!-- Success state -->
<div v-if="deprecateSuccess" class="space-y-4">
<div
class="flex items-center gap-3 p-4 bg-green-500/10 border border-green-500/20 rounded-lg"
>
<span class="i-carbon-checkmark-filled text-green-500 w-6 h-6" aria-hidden="true" />
<div>
<p class="font-mono text-sm text-fg">{{ $t('package.deprecation.modal.success') }}</p>
<p class="text-xs text-fg-muted">
{{ $t('package.deprecation.modal.success_detail') }}
</p>
</div>
</div>
<button
type="button"
class="w-full px-4 py-2 font-mono text-sm text-fg-muted bg-bg-subtle border border-border rounded-md transition-colors duration-200 hover:text-fg hover:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
@click="close"
>
{{ $t('common.close') }}
</button>
</div>
<!-- Form (only shown when connected; parent only opens modal when isConnected) -->
<div v-else class="space-y-4">
<div>
<label for="deprecate-message" class="block text-sm font-medium text-fg mb-1">
{{ $t('package.deprecation.modal.reason') }}
</label>
<textarea
id="deprecate-message"
v-model="deprecateMessage"
rows="3"
class="w-full px-3 py-2 font-mono text-sm bg-bg border border-border rounded-md text-fg placeholder:text-fg-muted focus:outline-none focus:ring-2 focus:ring-fg/50"
:placeholder="$t('package.deprecation.modal.reason_placeholder')"
/>
</div>
<div>
<label for="deprecate-version" class="block text-sm font-medium text-fg mb-1">
{{ $t('package.deprecation.modal.version') }}
</label>
<input
id="deprecate-version"
v-model="deprecateVersion"
type="text"
class="w-full px-3 py-2 font-mono text-sm bg-bg border border-border rounded-md text-fg placeholder:text-fg-muted focus:outline-none focus:ring-2 focus:ring-fg/50"
:placeholder="$t('package.deprecation.modal.version_placeholder')"
/>
</div>
<div
v-if="deprecateError"
role="alert"
class="p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md"
>
{{ deprecateError }}
</div>
<button
type="button"
:disabled="isDeprecating || !deprecateMessage.trim()"
class="w-full px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md transition-colors duration-200 hover:bg-fg/90 disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
@click="handleDeprecate"
>
{{
isDeprecating
? $t('package.deprecation.modal.deprecating')
: $t('package.deprecation.action')
}}
</button>
</div>
</Modal>
</template>