Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-7206: Fixes an issue where API keys of the removed components are… #5634

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,14 @@ export default class WebformBuilder extends Component {
else if (parent.formioComponent && parent.formioComponent.removeChildComponent) {
parent.formioComponent.removeChildComponent(component);
}
if (component.input && componentInstance && componentInstance.parent) {
_.unset(componentInstance._data, componentInstance.key);
if (component.input && componentInstance && parent.formioComponent) {
const parentDefaultValue = _.get(parent.formioComponent, 'component.defaultValue', null);
if (Array.isArray(parentDefaultValue)) {
parentDefaultValue.forEach(v => _.unset(v, componentInstance.key));
}
else if (typeof parentDefaultValue === 'object') {
_.unset(parentDefaultValue, componentInstance.key);
}
alexandraRamanenka marked this conversation as resolved.
Show resolved Hide resolved
}
const rebuild = parent.formioComponent.rebuild() || Promise.resolve();
rebuild.then(() => {
Expand Down
77 changes: 45 additions & 32 deletions src/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,40 +257,53 @@ describe('WebformBuilder tests', function() {

it('Should remove deleted components keys from default value', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('datagrid');
builder.setForm({
display: 'form',
type: 'form',
components: [
{
label: 'Data Grid',
reorder: false,
addAnotherPosition: 'bottom',
layoutFixed: false,
enableRowGroups: false,
initEmpty: false,
tableView: false,
defaultValue: [
{
textField: '',
},
],
validateWhenHidden: false,
key: 'dataGrid',
type: 'datagrid',
input: true,
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
validateWhenHidden: false,
key: 'textField',
type: 'textfield',
input: true,
},
],
},
],
}).then(() => {
const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0];
textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));

setTimeout(() => {
const dataGridDefaultValue = builder.editForm.getComponent('defaultValue');
dataGridDefaultValue.removeRow(0);

setTimeout(() => {
Harness.saveComponent();
setTimeout(() => {
const dataGridContainer = builder.webform.element.querySelector('[ref="dataGrid-container"]');
Harness.buildComponent('textfield', dataGridContainer);

setTimeout(() => {
Harness.saveComponent();

setTimeout(() => {
const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0];
textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));

setTimeout(() => {
const dataGrid = builder.webform.getComponent(['dataGrid']);
assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key');
done();
}, 300);
});
}, 300);
}, 300);
}, 350);
}, 350);
const dataGrid = builder.webform.getComponent(['dataGrid']);
assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key');
done();
}, 300);
}).catch(done);
});
});
Expand Down
Loading