Skip to content

Commit

Permalink
fix: onPaste separate logic in KeyValue.vue
Browse files Browse the repository at this point in the history
Signed-off-by: andy.lee <[email protected]>
  • Loading branch information
a110605 committed May 5, 2024
1 parent bbc89cc commit 61e0227
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
9 changes: 0 additions & 9 deletions pkg/harvester/edit/harvesterhci.io.virtualmachineimage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,6 @@ export default {
@focusKey="focusKey"
@input="value.setLabels($event)"
>
<template #key="{ row, keyName, queueUpdate}">
<input
ref="key"
v-model="row[keyName]"
:placeholder="t('keyValue.keyPlaceholder')"
@input="queueUpdate"
/>
</template>
<template #value="{row, keyName, valueName, queueUpdate}">
<Select
v-if="internalAnnotations(row)"
Expand Down
2 changes: 1 addition & 1 deletion shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6916,7 +6916,7 @@ podAffinity:
keyValue:
keyPlaceholder: e.g. foo
valuePlaceholder: e.g. bar
protip: 'Paste lines of <em>key=value</em> or <em>key: value</em> into any key field for easy bulk entry'
protip: 'Paste lines of <em>key=value</em> or <em>key:value</em> into any key field for easy bulk entry'

registryMirror:
header: Mirrors
Expand Down
10 changes: 5 additions & 5 deletions shell/components/form/KeyValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default {
},
parserSeparators: {
type: Array,
default: () => [': ', '='],
default: () => [':', '='],
},
loading: {
default: false,
Expand Down Expand Up @@ -492,14 +492,14 @@ export default {
}
this.$emit('input', out);
},
onPaste(index, event, pastedValue) {
onPaste(index, event) {
const text = event.clipboardData.getData('text/plain');
const lines = text.split('\n');
const splits = lines.map((line) => {
const splitter = !line.includes(':') || ((line.indexOf('=') < line.indexOf(':')) && line.includes(':')) ? '=' : ':';
const splitter = this.parserSeparators.find(sep => line.includes(sep));
return line.split(splitter);
});
return splitter ? line.split(splitter) : '';
}).filter(split => split && split.length > 0);
if (splits.length === 0 || (splits.length === 1 && splits[0].length < 2)) {
return;
Expand Down

0 comments on commit 61e0227

Please sign in to comment.