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

5413 - [Notebook] Various visual issues with renaming sections/pages #5475

Merged
merged 16 commits into from
Aug 18, 2022
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
34 changes: 34 additions & 0 deletions e2e/tests/functional/plugins/notebook/notebook.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ test.describe('Notebook section tests', () => {
//Delete 3rd section
//1st is selected and there is no default notebook
});
test.fixme('Section rename operations', async ({ page }) => {
// Create a new notebook
// Add a section
// Rename the section but do not confirm
// Keyboard press 'Escape'
// Verify that the section name reverts to the default name
// Rename the section but do not confirm
// Keyboard press 'Enter'
// Verify that the section name is updated
// Rename the section to "" (empty string)
// Keyboard press 'Enter' to confirm
// Verify that the section name reverts to the default name
// Rename the section to something long that overflows the text box
// Verify that the section name is not truncated while input is active
// Confirm the section name edit
// Verify that the section name is truncated now that input is not active
});
});

test.describe('Notebook page tests', () => {
Expand All @@ -107,6 +124,23 @@ test.describe('Notebook page tests', () => {
//Delete 3rd page
//First is now selected and there is no default notebook
});
test.fixme('Page rename operations', async ({ page }) => {
// Create a new notebook
// Add a page
// Rename the page but do not confirm
// Keyboard press 'Escape'
// Verify that the page name reverts to the default name
// Rename the page but do not confirm
// Keyboard press 'Enter'
// Verify that the page name is updated
// Rename the page to "" (empty string)
// Keyboard press 'Enter' to confirm
// Verify that the page name reverts to the default name
// Rename the page to something long that overflows the text box
// Verify that the page name is not truncated while input is active
// Confirm the page name edit
// Verify that the page name is truncated now that input is not active
});
});

test.describe('Notebook search tests', () => {
Expand Down
46 changes: 26 additions & 20 deletions src/plugins/notebook/components/PageComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<template v-if="!page.isLocked">
<div
class="c-list__item__name js-list__item__name"
:class="[{ 'c-input-inline': isSelected }]"
:data-id="page.id"
:contenteditable="true"
:contenteditable="isSelected"
@keydown.escape="updateName"
@keydown.enter="updateName"
@blur="updateName"
>{{ pageName }}</div>
Expand All @@ -32,8 +34,9 @@
</template>

<script>
import PopupMenu from './PopupMenu.vue';
import { KEY_ENTER, KEY_ESCAPE } from '../utils/notebook-key-code';
import RemoveDialog from '../utils/removeDialog';
import PopupMenu from './PopupMenu.vue';

export default {
components: {
Expand Down Expand Up @@ -107,36 +110,39 @@ export default {
removeDialog.show();
},
selectPage(event) {
const target = event.target;
const id = target.dataset.id;

if (!this.page.isLocked) {
const page = target.closest('.js-list__item');
const input = page.querySelector('.js-list__item__name');
const { target: { dataset: { id } } } = event;

if (page.className.indexOf('is-selected') > -1) {
input.classList.add('c-input-inline');
if (this.isSelected || !id) {
return;
}

return;
}
this.$emit('selectPage', id);
},
renamePage(target) {
if (!target) {
return;
}

if (!id) {
target.textContent = target.textContent ? target.textContent.trim() : `Unnamed ${this.pageTitle}`;

if (this.page.name === target.textContent) {
return;
}

this.$emit('selectPage', id);
this.$emit('renamePage', Object.assign(this.page, { name: target.textContent }));
},
updateName(event) {
const target = event.target;
const name = target.textContent.toString();
target.classList.remove('c-input-inline');
const { target, keyCode, type } = event;

if (name === '' || this.page.name === name) {
return;
if (keyCode === KEY_ESCAPE) {
target.textContent = this.page.name;
} else if (keyCode === KEY_ENTER || type === 'blur') {
this.renamePage(target);
}

this.$emit('renamePage', Object.assign(this.page, { name }));
target.scrollLeft = '0';

target.blur();
}
}
};
Expand Down
46 changes: 26 additions & 20 deletions src/plugins/notebook/components/SectionComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
>
<span
class="c-list__item__name js-list__item__name"
:class="[{ 'c-input-inline': isSelected && !section.isLocked }]"
:data-id="section.id"
contenteditable="true"
:contenteditable="isSelected && !section.isLocked"
@keydown.escape="updateName"
@keydown.enter="updateName"
@blur="updateName"
>{{ sectionName }}</span>
Expand All @@ -20,8 +22,9 @@
</template>

<script>
import PopupMenu from './PopupMenu.vue';
import { KEY_ENTER, KEY_ESCAPE } from '../utils/notebook-key-code';
import RemoveDialog from '../utils/removeDialog';
import PopupMenu from './PopupMenu.vue';

export default {
components: {
Expand Down Expand Up @@ -96,36 +99,39 @@ export default {
removeDialog.show();
},
selectSection(event) {
const target = event.target;
const id = target.dataset.id;

if (!this.section.isLocked) {
const section = target.closest('.js-list__item');
const input = section.querySelector('.js-list__item__name');
const { target: { dataset: { id } } } = event;

if (section.className.indexOf('is-selected') > -1) {
input.classList.add('c-input-inline');
if (this.isSelected || !id) {
return;
}

return;
}
this.$emit('selectSection', id);
},
renameSection(target) {
if (!target) {
return;
}

if (!id) {
target.textContent = target.textContent ? target.textContent.trim() : `Unnamed ${this.sectionTitle}`;

if (this.section.name === target.textContent) {
return;
}

this.$emit('selectSection', id);
this.$emit('renameSection', Object.assign(this.section, { name: target.textContent }));
},
updateName(event) {
const target = event.target;
target.classList.remove('c-input-inline');
const name = target.textContent.trim();
const { target, keyCode, type } = event;

if (name === '' || this.section.name === name) {
return;
if (keyCode === KEY_ESCAPE) {
target.textContent = this.section.name;
} else if (keyCode === KEY_ENTER || type === 'blur') {
this.renameSection(target);
}

this.$emit('renameSection', Object.assign(this.section, { name }));
target.scrollLeft = '0';

target.blur();
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/notebook/components/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}

&__name {
flex: 0 1 auto;
flex: 1 1 auto;
}

&__menu-indicator {
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/notebook/utils/notebook-key-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Key codes for `KeyboardEvent.keyCode`.
export const KEY_ENTER = 13;
export const KEY_ESCAPE = 27;
6 changes: 6 additions & 0 deletions src/styles/notebook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,9 @@ body.mobile {
}
}
}

.c-list__item {
&__name:focus {
text-overflow: clip;
}
}