Skip to content

Convert context menu on element edit page to disclosure menu #12946

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2f54cf5
Convert element context menu to disclosure menu
gcamacho079 Mar 10, 2023
ce587a9
Add context indicator with site and revision, change visible name of …
gcamacho079 Mar 10, 2023
c250f2b
Start adding site select using sementic element
gcamacho079 Mar 10, 2023
236ecb0
Start styling revision menu fields, start moving revisions into seman…
gcamacho079 Mar 10, 2023
601b874
Add current revision to select
gcamacho079 Mar 10, 2023
0c6b3ec
More all other revisions into select dropdown
gcamacho079 Mar 13, 2023
a97a5fc
Move drafts into select, remove fieldset wrapper
gcamacho079 Mar 13, 2023
bff8dd7
Get revision/draft redirect working on ElementEditor pages; TODO: mov…
gcamacho079 Mar 14, 2023
e268444
Go to selected revision/draft on submit; move all functionality into …
gcamacho079 Mar 14, 2023
1b58610
Update revision select menu when site select is updated; TODO add loa…
gcamacho079 Mar 14, 2023
f223f50
Add loading spinner to entire version field when site is changed; TOD…
gcamacho079 Mar 16, 2023
7220ae5
Remove old markup and add screen reader messages
gcamacho079 Mar 16, 2023
230fb80
Update twig template to use translations
gcamacho079 Mar 17, 2023
f107613
Disable GO button when new content is loading, ensure focus moves to …
gcamacho079 Mar 20, 2023
5ae7d27
Update label and padding styles in revision menu
gcamacho079 Mar 20, 2023
346d328
Build
gcamacho079 Mar 20, 2023
d30dd11
Hide site field when looking at a previous revision
gcamacho079 Mar 20, 2023
c6af79c
Fix button spacing
gcamacho079 Mar 21, 2023
34f62a7
ci and build
gcamacho079 Mar 21, 2023
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
311 changes: 160 additions & 151 deletions src/templates/_includes/revisionmenu.twig

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/translations/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@
'Global sets' => 'Global sets',
'Global' => 'Global',
'Globals' => 'Globals',
'Go' => 'Go',
'Go to Craft CMS' => 'Go to Craft CMS',
'Go to Updates' => 'Go to Updates',
'Got it' => 'Got it',
Expand Down Expand Up @@ -1401,6 +1402,7 @@
'Suspend' => 'Suspend',
'Suspended' => 'Suspended',
'Switch' => 'Switch',
'Switch version' => 'Switch version',
'Switching sites will lose unsaved changes. Are you sure you want to switch sites?' => 'Switching sites will lose unsaved changes. Are you sure you want to switch sites?',
'System Email Address' => 'System Email Address',
'System Messages' => 'System Messages',
Expand Down Expand Up @@ -1904,6 +1906,7 @@
'path/to/subfolder' => 'path/to/subfolder',
'revision' => 'revision',
'revisions' => 'revisions',
'Revisions' => 'Revisions',
'second' => 'second',
'seconds' => 'seconds',
'seven' => 'seven',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

100 changes: 61 additions & 39 deletions src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,61 @@ button {
background-color: transparentize($grey200, 0.5) !important;
}

.context-btn {
@include margin-left(var(--s));
}

.context-indicator {
--border-color: var(--gray-700);
display: flex;
border: 1px solid var(--border-color);
border-radius: var(--large-border-radius);
min-height: var(--ui-control-height);

.context-block {
display: flex;
}

.context-block__name,
.context-block__value {
display: flex;
justify-content: center;
align-items: center;
}

.context-block__name {
background-color: var(--border-color);
color: var(--white);
width: 2rem;

[data-icon] {
display: flex;
}
}

.context-block__value {
padding: 0 0.3rem;
}
}

.revision-menu__form {
display: grid;
gap: var(--s);
}

.revision-menu__field {
position: relative;
}

.revision-menu__field-inner {
display: grid;
gap: var(--s);

select {
width: 100%;
}
}

/* status icons */
.checkmark-icon,
.alert-icon {
Expand Down Expand Up @@ -504,48 +559,15 @@ button {
}

.menu.revision-menu {
padding: 10px 24px;
padding: 18px 24px 20px;

hr {
margin: 10px -24px;
label {
font-weight: var(--font-weight-bold);
color: var(--medium-dark-text-color);
}

ul {
li {
&.sel {
margin: 0 -14px;
padding: 0 14px;
background: var(--gray-050);
border-radius: var(--large-border-radius);

.edited-desc {
display: flex;
align-items: center;
@include margin-left(10px);
border-top: 1px solid var(--hairline-color);
padding: 10px 0;
color: var(--light-text-color);
white-space: normal;

p {
margin: 0;
}

.btn {
@include margin-left(14px);
}
}
}

a {
padding-top: 7px;
border-radius: var(--large-border-radius);
}
}
}

.extralight {
margin-top: 2px;
.submit {
margin-top: var(--s);
}
}

Expand Down
88 changes: 88 additions & 0 deletions src/web/assets/cp/src/js/CP.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Craft.CP = Garnish.Base.extend(
$globalContainer: null,
$mainContainer: null,
$alerts: null,
$contextMenu: null,
$contextSubmit: null,
$crumbs: null,
$breadcrumbList: null,
$breadcrumbItems: null,
Expand All @@ -30,6 +32,8 @@ Craft.CP = Garnish.Base.extend(
$sidebar: null,
$contentContainer: null,
$edition: null,
$revisionBtn: null,
$revisionContainer: null,

$confirmUnloadForms: null,
$deltaForms: null,
Expand Down Expand Up @@ -89,6 +93,7 @@ Craft.CP = Garnish.Base.extend(
this.$sidebar = $('#sidebar');
this.$contentContainer = $('#content-container');
this.$collapsibleTables = $('table.collapsible');
this.$revisionBtn = this.$mainContainer.find('.context-btn');

this.isMobile = Garnish.isMobileBrowser();

Expand Down Expand Up @@ -134,6 +139,11 @@ Craft.CP = Garnish.Base.extend(
// Wait a frame before initializing any confirm-unload forms,
// so other JS that runs on ready() has a chance to initialize
Garnish.requestAnimationFrame(this.initSpecialForms.bind(this));

// Revision Menu
if (this.$revisionBtn.length) {
this.initContextMenu();
}
});

// Alerts
Expand Down Expand Up @@ -555,6 +565,84 @@ Craft.CP = Garnish.Base.extend(
Garnish.$bod.toggleClass('showing-sidebar');
},

updateRevisionForm: function (url) {
const revisionFieldSelector = '#revision-field';
const loadParam = `${url} #revision-field-inner`;
const $allRevisionsLink = this.$contextMenu.find('#revision-link');
const $revisionField = this.$contextMenu.find('#revision-field');
const $revisionFieldInner = this.$contextMenu.find(
'#revision-field-inner'
);
const $loadingSpinner = $revisionField.find('.spinner');
const $revisionSelect = $revisionField.find('#revision-select');
const $liveRegion = this.$contextMenu.find('[role="status"]');

// Activate loading visual
$revisionFieldInner.addClass('disabled');
$loadingSpinner.removeClass('hidden');

// Disable current field and submit btn
$revisionSelect.attr('aria-disabled', 'true');
this.$contextSubmit.attr('aria-disabled', 'true').addClass('disabled');

// Disable revision link
$allRevisionsLink.removeAttr('href').attr({
role: 'link',
'aria-disabled': true,
});

// Update screen reader message
$liveRegion.text(Craft.t('app', 'Loading'));

$(revisionFieldSelector).load(loadParam, () => {
// Check to see if focus was on select element
if (Garnish.getFocusedElement().length === 0) {
// Refocus newly added select
this.$contextMenu.find('#revision-select').trigger('focus');
}

this.$contextSubmit
.attr('aria-disabled', 'false')
.removeClass('disabled');
$revisionFieldInner.removeClass('disabled');
$revisionField.append(
'<div class="spinner spinner-absolute hidden" aria-hidden="true"></div>'
);
$liveRegion.text(Craft.t('app', 'Success'));
setTimeout(() => {
$liveRegion.empty();
}, 3000);
});
},

initContextMenu: function () {
this.$contextMenu = this.$revisionBtn.data('trigger').$container;
this.$contextSubmit = this.$contextMenu.find('.revision-menu__submit');
const $siteSelect = this.$contextMenu.find('#site-select');

// If all optgroups are hidden in site select, hide the field
const hideSiteSelect =
$siteSelect.find('optgroup:not(.hidden)').length === 0;

if (hideSiteSelect) {
$siteSelect.closest('.revision-menu__field').addClass('hidden');
}

this.addListener($siteSelect, 'change', (event) => {
const $selected = $siteSelect.find(':selected');
this.updateRevisionForm($selected.data('href'));
});

this.addListener(this.$contextSubmit, 'click', (event) => {
if ($(event.target).attr('aria-disabled') === 'true') return;

const $form = $(event.target).closest('.revision-menu__form');
const $selected = $form.find('#revision-select :selected');
const url = $selected.data('href');
window.location.href = url;
});
},

initTabs: function () {
if (this.tabManager) {
this.tabManager.destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js.map

Large diffs are not rendered by default.