mirror of https://github.com/rancher/dashboard.git
Revert: Add an id to track members of ArrayList.vue (#14742)
This reverts commit 6ee27db90d.
This commit is contained in:
parent
72eb857364
commit
81071b5027
|
|
@ -6,8 +6,6 @@ import { removeAt } from '@shell/utils/array';
|
||||||
import { TextAreaAutoGrow } from '@components/Form/TextArea';
|
import { TextAreaAutoGrow } from '@components/Form/TextArea';
|
||||||
import { clone } from '@shell/utils/object';
|
import { clone } from '@shell/utils/object';
|
||||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||||
import { randomStr } from '@shell/utils/string';
|
|
||||||
|
|
||||||
const DEFAULT_PROTIP = 'Tip: Paste lines into any list field for easy bulk entry';
|
const DEFAULT_PROTIP = 'Tip: Paste lines into any list field for easy bulk entry';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -116,12 +114,12 @@ export default {
|
||||||
const rows = ref([]);
|
const rows = ref([]);
|
||||||
|
|
||||||
for ( const value of input ) {
|
for ( const value of input ) {
|
||||||
rows.value.push({ value, id: randomStr() });
|
rows.value.push({ value });
|
||||||
}
|
}
|
||||||
if ( !rows.value.length && props.initialEmptyRow ) {
|
if ( !rows.value.length && props.initialEmptyRow ) {
|
||||||
const value = props.defaultAddValue ? clone(props.defaultAddValue) : '';
|
const value = props.defaultAddValue ? clone(props.defaultAddValue) : '';
|
||||||
|
|
||||||
rows.value.push({ value, id: randomStr() });
|
rows.value.push({ value });
|
||||||
}
|
}
|
||||||
|
|
||||||
const isView = computed(() => {
|
const isView = computed(() => {
|
||||||
|
|
@ -166,19 +164,9 @@ export default {
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.value,
|
() => props.value,
|
||||||
(newVal) => {
|
() => {
|
||||||
lastUpdateWasFromValue.value = true;
|
lastUpdateWasFromValue.value = true;
|
||||||
const newRows = (newVal || []).map((value) => {
|
rows.value = (props.value || []).map((v) => ({ value: v }));
|
||||||
const existingRow = rows.value.find((row) => row.value === value);
|
|
||||||
|
|
||||||
if (existingRow) {
|
|
||||||
return { value, id: existingRow.id };
|
|
||||||
} else {
|
|
||||||
return { value, id: randomStr() };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
rows.value = newRows;
|
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
);
|
);
|
||||||
|
|
@ -223,10 +211,7 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
add() {
|
add() {
|
||||||
this.rows.push({
|
this.rows.push({ value: clone(this.defaultAddValue) });
|
||||||
value: clone(this.defaultAddValue),
|
|
||||||
id: randomStr(),
|
|
||||||
});
|
|
||||||
if (this.defaultAddValue) {
|
if (this.defaultAddValue) {
|
||||||
this.queueUpdate();
|
this.queueUpdate();
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +301,7 @@ export default {
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-for="(row, idx) in rows"
|
v-for="(row, idx) in rows"
|
||||||
:key="row.id"
|
:key="idx"
|
||||||
:data-testid="`${componentTestid}-box${ idx }`"
|
:data-testid="`${componentTestid}-box${ idx }`"
|
||||||
class="box"
|
class="box"
|
||||||
:class="{'hide-remove-is-view': isView}"
|
:class="{'hide-remove-is-view': isView}"
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ describe('the ArrayList', () => {
|
||||||
|
|
||||||
expect(wrapper.find('[data-testid="array-list-remove-item-2"]').exists()).toBe(false);
|
expect(wrapper.find('[data-testid="array-list-remove-item-2"]').exists()).toBe(false);
|
||||||
expect((wrapper.emitted('remove')![0][0] as any).row.value).toStrictEqual('string 1');
|
expect((wrapper.emitted('remove')![0][0] as any).row.value).toStrictEqual('string 1');
|
||||||
expect(wrapper.vm.rows).toStrictEqual([{ id: '', value: 'string 0' }, { id: '', value: 'string 2' }]);
|
expect(wrapper.vm.rows).toStrictEqual([{ value: 'string 0' }, { value: 'string 2' }]);
|
||||||
expect(wrapper.emitted('update:value')![0][0]).toStrictEqual(['string 0', 'string 2']);
|
expect(wrapper.emitted('update:value')![0][0]).toStrictEqual(['string 0', 'string 2']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ describe('the ArrayList', () => {
|
||||||
const rowRemove = wrapper.find('[data-testid="array-list-remove-item-0"]');
|
const rowRemove = wrapper.find('[data-testid="array-list-remove-item-0"]');
|
||||||
const rowAdd = wrapper.find('[data-testid="array-list-button"]');
|
const rowAdd = wrapper.find('[data-testid="array-list-button"]');
|
||||||
|
|
||||||
expect(wrapper.vm.rows[0]).toStrictEqual({ id: '', value: value[0] });
|
expect(wrapper.vm.rows[0]).toStrictEqual({ value: value[0] });
|
||||||
|
|
||||||
expect(mainContainer.attributes('role')).toBe('group');
|
expect(mainContainer.attributes('role')).toBe('group');
|
||||||
expect(mainContainer.attributes('aria-label')).toBe('some-title');
|
expect(mainContainer.attributes('aria-label')).toBe('some-title');
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
import RulePath from '@shell/edit/networking.k8s.io.ingress/RulePath';
|
import RulePath from '@shell/edit/networking.k8s.io.ingress/RulePath';
|
||||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||||
import { random32 } from '@shell/utils/string';
|
import { random32 } from '@shell/utils/string';
|
||||||
import debounce from 'lodash/debounce';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
emits: ['update:value', 'remove'],
|
emits: ['update:value', 'remove'],
|
||||||
|
|
@ -42,19 +41,6 @@ export default {
|
||||||
ruleMode: this.value.asDefault ? 'asDefault' : 'setHost',
|
ruleMode: this.value.asDefault ? 'asDefault' : 'setHost',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
host: {
|
|
||||||
handler: debounce(function() {
|
|
||||||
this.update();
|
|
||||||
}, 500),
|
|
||||||
},
|
|
||||||
paths: {
|
|
||||||
handler: debounce(function() {
|
|
||||||
this.update();
|
|
||||||
}, 500),
|
|
||||||
deep: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
update() {
|
update() {
|
||||||
const http = { paths: this.paths };
|
const http = { paths: this.paths };
|
||||||
|
|
@ -96,6 +82,7 @@ export default {
|
||||||
|
|
||||||
path.focus();
|
path.focus();
|
||||||
}
|
}
|
||||||
|
this.update();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removePath(idx) {
|
removePath(idx) {
|
||||||
|
|
@ -103,6 +90,7 @@ export default {
|
||||||
|
|
||||||
neu.splice(idx, 1);
|
neu.splice(idx, 1);
|
||||||
this.paths = neu;
|
this.paths = neu;
|
||||||
|
this.update();
|
||||||
},
|
},
|
||||||
removeRule() {
|
removeRule() {
|
||||||
this.$emit('remove');
|
this.$emit('remove');
|
||||||
|
|
@ -130,6 +118,7 @@ export default {
|
||||||
:label="t('ingress.rules.requestHost.label')"
|
:label="t('ingress.rules.requestHost.label')"
|
||||||
:placeholder="t('ingress.rules.requestHost.placeholder')"
|
:placeholder="t('ingress.rules.requestHost.placeholder')"
|
||||||
:rules="rules.requestHost"
|
:rules="rules.requestHost"
|
||||||
|
@update:value="update"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|
@ -172,6 +161,7 @@ export default {
|
||||||
:ingress="ingress"
|
:ingress="ingress"
|
||||||
:rules="{path: rules.path, port: rules.port, target: rules.target}"
|
:rules="{path: rules.path, port: rules.port, target: rules.target}"
|
||||||
@remove="(e) => removePath(i)"
|
@remove="(e) => removePath(i)"
|
||||||
|
@update:value="update"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue