Skip to content

Commit e867deb

Browse files
authored
feat: Add copy function for raw JSON in container and network detail views (#11141)
* feat: Add copy button for raw JSON in container and network detail views * refactor: Change CodemirrorPro component from disabled to readonly in container and network detail views * feat: Add readonly prop to CodemirrorPro component for enhanced editing control
1 parent af15659 commit e867deb

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

frontend/src/components/codemirror-pro/index.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script lang="ts" setup>
88
import { CSSProperties } from 'vue';
99
import { basicSetup, EditorView } from 'codemirror';
10-
import { EditorState } from '@codemirror/state';
10+
import { EditorState, Extension } from '@codemirror/state';
1111
import { oneDark } from '@codemirror/theme-one-dark';
1212
import { StreamLanguage } from '@codemirror/language';
1313
import { nginx } from './nginx';
@@ -27,6 +27,10 @@ const props = defineProps({
2727
type: Boolean,
2828
default: false,
2929
},
30+
readonly: {
31+
type: Boolean,
32+
default: false,
33+
},
3034
modelValue: {
3135
type: String,
3236
default: '',
@@ -119,7 +123,7 @@ const initCodeMirror = () => {
119123
},
120124
});
121125
122-
const extensions = [
126+
const extensions: Extension[] = [
123127
defaultTheme,
124128
oneDark,
125129
basicSetup,
@@ -131,6 +135,7 @@ const initCodeMirror = () => {
131135
}),
132136
placeholder(props.placeholder),
133137
EditorView.editable.of(!props.disabled),
138+
EditorState.readOnly.of(props.readonly),
134139
];
135140
136141
if (props.lineWrapping) {

frontend/src/views/container/container/inspect/index.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@
149149
</el-tab-pane>
150150

151151
<el-tab-pane :label="$t('commons.button.view')" name="view">
152-
<CodemirrorPro v-model="rawJson" :height-diff="240" :disabled="true" mode="json" />
152+
<div class="mb-2 flex justify-start">
153+
<el-button type="primary" @click="handleCopyRawJson" icon="DocumentCopy" size="default">
154+
{{ $t('commons.button.copy') }}
155+
</el-button>
156+
</div>
157+
<CodemirrorPro v-model="rawJson" :height-diff="240" :readonly="true" mode="json" />
153158
</el-tab-pane>
154159
</el-tabs>
155160

@@ -165,6 +170,7 @@
165170
import { ref } from 'vue';
166171
import CodemirrorPro from '@/components/codemirror-pro/index.vue';
167172
import { routerToFileWithPath } from '@/utils/router';
173+
import { copyText } from '@/utils/util';
168174
import i18n from '@/lang';
169175
170176
const visible = ref(false);
@@ -263,6 +269,10 @@ const handleJumpToFile = (path: string) => {
263269
}
264270
};
265271
272+
const handleCopyRawJson = () => {
273+
copyText(rawJson.value);
274+
};
275+
266276
defineExpose({
267277
acceptParams,
268278
});

frontend/src/views/container/network/detail/index.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@
9393
</el-tab-pane>
9494

9595
<el-tab-pane :label="$t('commons.button.view')" name="raw">
96-
<CodemirrorPro v-model="rawJson" :height-diff="240" :disabled="true" mode="json" />
96+
<div class="mb-2 flex justify-start">
97+
<el-button type="primary" @click="handleCopyRawJson" icon="DocumentCopy" size="default">
98+
{{ $t('commons.button.copy') }}
99+
</el-button>
100+
</div>
101+
<CodemirrorPro v-model="rawJson" :height-diff="240" :readonly="true" mode="json" />
97102
</el-tab-pane>
98103
</el-tabs>
99104

@@ -108,6 +113,7 @@
108113
<script lang="ts" setup>
109114
import { ref, computed } from 'vue';
110115
import CodemirrorPro from '@/components/codemirror-pro/index.vue';
116+
import { copyText } from '@/utils/util';
111117
112118
const visible = ref(false);
113119
const activeTab = ref('overview');
@@ -173,6 +179,10 @@ const containerList = computed(() => {
173179
}));
174180
});
175181
182+
const handleCopyRawJson = () => {
183+
copyText(rawJson.value);
184+
};
185+
176186
defineExpose({
177187
acceptParams,
178188
});

0 commit comments

Comments
 (0)