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: fixed selected component #14315

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('ColumnElement', () => {
expect(onEditMock).toHaveBeenCalledTimes(1);
expect(onEditMock).toHaveBeenCalledWith({
...mockTableColumn,
componentId: subformLayoutMock.component1Id,
headerContent: subformLayoutMock.component1.textResourceBindings.title,
cellContent: { query: subformLayoutMock.component1.dataModelBindings.simpleBinding },
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import { textMock } from '@studio/testing/mocks/i18nMock';
import userEvent from '@testing-library/user-event';
import { subformLayoutMock } from '../../../../../testing/subformLayoutMock';
Expand Down Expand Up @@ -86,6 +86,26 @@ describe('EditColumnElementComponentSelect', () => {
}),
).toBeInTheDocument();
});

it('should make sure that selected component selected still selected', async () => {
const mockOnSelectComponent = jest.fn();
const selectedComponentId = [subformLayoutMock.component1Id];
renderEditColumnElementComponentSelect({
onSelectComponent: mockOnSelectComponent,
selectedComponentId,
});

const componentSelect = screen.getByRole('combobox', {
name: textMock('ux_editor.properties_panel.subform_table_columns.choose_component'),
});

expect(componentSelect).toBeInTheDocument();
expect(componentSelect).toHaveValue(selectedComponentId[0]);
await waitFor(() => {
expect(mockOnSelectComponent).not.toHaveBeenCalled();
});
expect(componentSelect).toHaveValue(selectedComponentId[0]);
});
});

const renderEditColumnElementComponentSelect = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export const EditColumnElement = ({
(comp) => comp.textResourceBindings?.title && comp.dataModelBindings?.simpleBinding,
);

const getSelectedComponentId = components.find((comp) => comp.id === tableColumn.componentId);

const selectComponent = (values: string[]) => {
const selectedComponentId = values[0];
const selectedComponent = components.find((comp) => comp.id === selectedComponentId);

const updatedTableColumn = {
...sourceColumn,
...tableColumn,
componentId: selectedComponent.id,
headerContent: selectedComponent.textResourceBindings?.title,
cellContent: { query: selectedComponent.dataModelBindings?.simpleBinding },
};
Expand All @@ -74,6 +77,7 @@ export const EditColumnElement = ({
<EditColumnElementComponentSelect
components={componentsWithLabelAndDataModel}
onSelectComponent={selectComponent}
selectedComponentId={getSelectedComponentId ? [getSelectedComponentId.id] : []}
/>
<StudioTextfield
label={
Expand Down Expand Up @@ -119,10 +123,12 @@ const EditColumnElementHeader = ({ columnNumber }: EditColumnElementHeaderProps)
export type EditColumnElementComponentSelectProps = {
components: FormItem[];
onSelectComponent: (values: string[]) => void;
selectedComponentId?: string[];
};
export const EditColumnElementComponentSelect = ({
components,
onSelectComponent,
selectedComponentId,
}: EditColumnElementComponentSelectProps) => {
const { t } = useTranslation();

Expand All @@ -148,6 +154,7 @@ export const EditColumnElementComponentSelect = ({
size='sm'
onValueChange={onSelectComponent}
id='columncomponentselect'
value={selectedComponentId}
>
{subformComponentOptions}
</StudioCombobox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type TableColumnCellContent = {
export type TableColumn = {
headerContent: string;
cellContent: TableColumnCellContent;
componentId?: string;
};
Loading