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 design of page creation #1549

Merged
merged 3 commits into from
Feb 28, 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
30 changes: 21 additions & 9 deletions src/components/vue-form-builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -388,28 +388,30 @@
<b-modal
id="addPageModal"
ref="addPageModal"
:ok-title="$t('Save')"
:cancel-title="$t('Cancel')"
header-class="pb-2"
size="lg"
:ok-title="$t('SAVE')"
:cancel-title="$t('CANCEL')"
cancel-variant="btn btn-outline-secondary"
ok-variant="btn btn-secondary ml-2"
:title="$t('Add New Page')"
header-close-content="&times;"
data-cy="add-page-modal"
:ok-disabled="!addPageName || !!checkPageName(addPageName)"
@ok="addPage"
@hide="addPageName = ''"
@show="addPageName = ''; showAddPageValidations=false;"
>
<required />
<template #modal-title>
<h5 class="modal-title">{{ $t('Create New Page') }}</h5>
<small class="modal-subtitle mb-n2">{{ $t('Create a new page in your screen') }}</small>
</template>
<form-input
ref="addPageInput"
v-model="addPageName"
:name="$t('Page Name')"
:label="$t('Page Name') + ' *'"
:helper="$t('The name of the new page to add')"
validation="required"
:error="checkPageName(addPageName)"
data-cy="add-page-name"
required
aria-required="true"
/>
</b-modal>
Expand Down Expand Up @@ -588,6 +590,7 @@ export default {
}

return {
showAddPageValidations: false,
openedPages: [0],
currentPage: 0,
selected: null,
Expand Down Expand Up @@ -763,7 +766,13 @@ export default {
onClick(page) {
this.$refs.tabsBar.openPageByIndex(page);
},
checkPageName(value) {
checkPageName(value, force = false) {
if (!force && !this.showAddPageValidations) {
return null;
}
if (!value.trim()) {
return this.$t("The Page Name field is required.");
}
const pageNames = this.config
.map((config) => config.name)
.filter((name) => name !== this.originalPageName);
Expand Down Expand Up @@ -1136,7 +1145,9 @@ export default {
this.updateState();
},
addPage(e) {
if (this.$refs.addPageInput.validator.errorCount) {
this.showAddPageValidations = true;
const error = this.checkPageName(this.addPageName, true);
if (error) {
e.preventDefault();
return;
}
Expand All @@ -1151,6 +1162,7 @@ export default {
items: []
});
this.addPageName = "";
this.currentPage = this.config.length - 1;
this.updateState();

// open new page
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/specs/pagesDropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("Page Dropdown", () => {
// Define Page 2
cy.get("[data-cy=add-page-name]").clear().type("Page_2");
cy.get("[data-cy=add-page-modal] button.btn").eq(1).click();
cy.wait(300);
cy.get('[data-cy=controls-FormButton]:contains("Page")').drag(
"[data-cy=screen-drop-zone]",
{ position: "bottom" }
Expand Down
Loading