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

feat(TMC-25993): change default UIForm collapsible panel title #5426

Merged
merged 3 commits into from
Oct 16, 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
5 changes: 5 additions & 0 deletions .changeset/shiny-mirrors-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-forms': minor
---

feat: Better handle collapsible fieldset title for UIForm definitions by using schema title by default
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function getDrillKey(key) {
}

export function defaultTitle(formData, schema, options) {
if (schema.title) {
return schema.title;
}

const title = (schema.items || []).reduce((acc, item) => {
let value;
if (item.key) {
Expand Down Expand Up @@ -66,7 +70,7 @@ export function defaultTitle(formData, schema, options) {
return schema.options.emptyTitleFallback;
}

return schema.title;
return '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function customTitle(value, schema) {
}

const schema = {
title: 'Basic',
description: 'This is description',
items: [
{
Expand Down Expand Up @@ -68,7 +67,10 @@ const defaultTitleMockData = {

const props = {
id: 'my-fieldset',
schema,
schema: {
...schema,
title: 'Basic',
},
value,
onChange: jest.fn(),
};
Expand All @@ -91,7 +93,7 @@ describe('CollapsibleFieldset', () => {
<CollapsibleFieldset {...props} value={{ ...value, isClosed: true }} />
</WidgetContext.Provider>,
);
expect(screen.getByText('Jimmy, Somsanith')).toBeInTheDocument();
expect(screen.getByText('Basic')).toBeInTheDocument();
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false');
});
it('should render a custom title', () => {
Expand Down Expand Up @@ -182,11 +184,11 @@ describe('CollapsibleFieldset', () => {
});

describe('defaultTitle', () => {
it('should return schema.title by default if no emptyTitleFallback has been provided in options', () => {
it('should return schema.title by default', () => {
// given not used in an array you have the schema.title
expect(defaultTitle({}, { title: 'Comment' })).toBe('Comment');
// given no value, you have the schema.title
expect(defaultTitle({}, schema)).toBe(schema.title);
expect(defaultTitle({}, schema)).toBe('');
});

it('should return if emptyTitleFallback has been provided and computed title is empty', () => {
Expand Down Expand Up @@ -218,7 +220,6 @@ describe('defaultTitle', () => {
});
it('should support recursive call on deeper objects', () => {
const complexSchema = {
title: 'Basic',
items: [
{
key: ['type'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports[`CollapsibleFieldset should render 1`] = `
<span
class="theme-headerTitle"
>
Jimmy, Somsanith
Basic
</span>
</button>
<div
Expand Down
Loading