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

fix: dynamic list collapsing issue #1248

Merged
merged 2 commits into from
Aug 26, 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
4 changes: 4 additions & 0 deletions packages/form-js-viewer/assets/form-js-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,10 @@
color: var(--color-warning);
}

.fjs-container .fjs-repeat-row-collapsed {
display: none;
}

.fjs-container .fjs-repeat-render-footer {
display: flex;
flex-direction: row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class RepeatRenderManager {
const showRemove = repeaterField.allowAddRemove && hasChildren;

const displayValues = isCollapsed ? values.slice(0, nonCollapsedItems) : values;
const hiddenValues = isCollapsed ? values.slice(nonCollapsedItems) : [];

const onDeleteItem = (index) => {
const updatedValues = values.slice();
Expand Down Expand Up @@ -89,6 +90,24 @@ export class RepeatRenderManager {
{...restProps}
/>
))}
{hiddenValues.length > 0 ? (
<div className="fjs-repeat-row-collapsed">
{hiddenValues.map((itemValue, itemIndex) => (
<RepetitionScaffold
key={itemIndex}
itemIndex={itemIndex + nonCollapsedItems}
itemValue={itemValue}
parentExpressionContextInfo={parentExpressionContextInfo}
repeaterField={repeaterField}
RowsRenderer={RowsRenderer}
indexes={indexes}
onDeleteItem={onDeleteItem}
showRemove={showRemove}
{...restProps}
/>
))}
</div>
) : null}
</>
);
}
Expand Down
33 changes: 33 additions & 0 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { spy } from 'sinon';

import { CustomFormFieldsModule } from './custom';

import { range } from 'lodash';

import conditionSchema from './condition.json';
import conditionErrorsSchema from './condition-errors.json';
import conditionErrorsDynamicListSchema from './condition-errors-dynamic-list.json';
Expand Down Expand Up @@ -507,6 +509,37 @@ describe('Form', function () {
});
});

it('should submit collapsed values', async function () {
// given
const data = {
list: range(1, 11).map((key) => ({ key })),
};

// when
await bootstrapForm({
container,
data,
schema: dynamicListVariablesSchema,
});

expect(form).to.exist;

const repeatRowContainers = container.querySelectorAll('.fjs-repeat-row-container');
expect(repeatRowContainers).to.have.length(10);

// then
expect(form.submit().data.list).to.have.length(10);

// but when
const collapseButton = container.querySelector('.fjs-repeat-render-collapse');
expect(collapseButton).to.exist;

fireEvent.click(collapseButton);

// then
expect(form.submit().data.list).to.have.length(10);
});

it('should hold proper interaction between table and dynamic list', async function () {
// given
const data = {
Expand Down
Loading