Skip to content

Commit

Permalink
#6261 Add settng to collapse elements on designer by default after JS…
Browse files Browse the repository at this point in the history
…ON loading

Fixes #6261
  • Loading branch information
novikov82 committed Dec 18, 2024
1 parent 2d735a4 commit 59799ab
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,12 @@ export class SurveyCreatorModel extends Base
this.expandCollapseManager.expandCollapseElements("drag-start", true, this.survey.pages);
}
public getElementExpandCollapseState(element: Question | PageModel | PanelModel, reason: ElementGetExpandCollapseStateEventReason, defaultValue: boolean): boolean {
if (this.expandCollapseButtonVisibility == "never") return false;
if (reason === "loading") {
if (element instanceof Question) defaultValue = this.collapseQuestions;
if (element instanceof PanelModel) defaultValue = this.collapsePanels;
if (element instanceof PageModel) defaultValue = this.collapsePages;
}
const options: ElementGetExpandCollapseStateEvent = {
element: element,
reason: reason,
Expand Down Expand Up @@ -3923,6 +3929,10 @@ export class SurveyCreatorModel extends Base
*/
@property({ defaultValue: "never" }) expandCollapseButtonVisibility?: "never" | "onhover" | "always";

collapsePages = false;
collapsePanels = false;
collapseQuestions = false;

expandOnDragTimeOut: number = 1000;

selectFromStringEditor: boolean;
Expand Down
4 changes: 4 additions & 0 deletions packages/survey-creator-core/src/creator-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,8 @@ export interface ICreatorOptions {
* - `"never"` - Hides the expand/collapse buttons.
*/
expandCollapseButtonVisibility?: "never" | "onhover" | "always";

collapsePages?: boolean;
collapsePanels?: boolean;
collapseQuestions?: boolean;
}
75 changes: 75 additions & 0 deletions packages/survey-creator-core/tests/tabs/designer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,81 @@ test("expand/collapse event - loading", () => {
expect(panelAdorner.collapsed).toBeFalsy();
});

test("expand/collapse properties - loading", () => {
surveySettings.animationEnabled = false;
const creator = new CreatorTester();
creator.expandCollapseButtonVisibility = "onhover";

var designerPlugin = <TabDesignerPlugin>(
creator.getPlugin("designer")
);

const json = {
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1"
},
{
"type": "panel",
"name": "panel1"
}
]
}
]
};
creator.JSON = json;
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeFalsy();

creator.collapsePages = true;
creator.collapsePanels = false;
creator.collapseQuestions = false;
creator.JSON = json;
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeTruthy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeFalsy();

creator.collapsePages = false;
creator.collapseQuestions = true;
creator.collapsePanels = false;
creator.JSON = json;
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeTruthy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeFalsy();

creator.collapsePages = false;
creator.collapseQuestions = false;
creator.collapsePanels = true;
creator.JSON = json;
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeTruthy();

creator.expandCollapseButtonVisibility = "never";
creator.collapsePages = true;
creator.collapseQuestions = true;
creator.collapsePanels = true;
creator.JSON = json;
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeFalsy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeFalsy();

creator.expandCollapseButtonVisibility = "always";
creator.collapsePages = false;
creator.collapseQuestions = false;
creator.collapsePanels = false;
const collapseAll = designerPlugin.model.surfaceToolbar.getActionById("collapseAll");
collapseAll.action(collapseAll);
expect(new PageAdorner(creator, creator.survey.pages[0]).collapsed).toBeTruthy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined).collapsed).toBeTruthy();
expect(new QuestionAdornerViewModel(creator, creator.survey.getAllPanels()[0] as any, undefined).collapsed).toBeTruthy();
});

test("Check adorners lock questions for expand/collapse all", (): any => {
surveySettings.animationEnabled = false;
const creator = new CreatorTester();
Expand Down

0 comments on commit 59799ab

Please sign in to comment.