Skip to content

Commit 52051c7

Browse files
committed
feat: show save button directly when editing configs
1 parent a1133a4 commit 52051c7

3 files changed

Lines changed: 85 additions & 23 deletions

File tree

blocks/edit/da-title/da-title.css

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ da-dialog {
3333
line-height: 16px;
3434
padding: 5px 14px;
3535
text-decoration: none;
36+
cursor: pointer;
3637
}
3738

3839
.con-button.blue {
@@ -186,12 +187,39 @@ da-dialog {
186187
background: #EFEFEF;
187188
}
188189

190+
.da-title-action {
191+
display: none;
192+
}
193+
189194
.da-title-actions.is-open .da-title-action {
190195
display: unset;
191196
}
192197

193-
.da-title-action {
194-
display: none;
198+
.da-title-actions.config .da-title-action {
199+
display: unset;
200+
}
201+
202+
.da-title-actions.config .da-title-action:not(.blue) {
203+
background: var(--s2-gray-200);
204+
border-color: var(--s2-gray-200);
205+
color: var(--s2-gray-700);
206+
cursor: default;
207+
}
208+
209+
.da-title-actions.config .da-title-action.is-sending {
210+
color: transparent;
211+
position: relative;
212+
overflow: hidden;
213+
}
214+
215+
.da-title-actions.config .da-title-action.is-sending::after {
216+
content: '';
217+
position: absolute;
218+
width: 22px;
219+
height: 22px;
220+
background: url('/blocks/edit/img/Smock_Send_18_N.svg') center/22px no-repeat;
221+
filter: brightness(0) invert(1);
222+
animation: animated-background 1s linear infinite;
195223
}
196224

197225
.da-title-action-send {

blocks/edit/da-title/da-title.js

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class DaTitle extends LitElement {
3737
collabUsers: { attribute: false },
3838
previewPrefix: { attribute: false },
3939
livePrefix: { attribute: false },
40+
hasChanges: { attribute: false },
4041
_actionsVis: { state: true },
4142
_status: { state: true },
4243
_fixedActions: { state: true },
@@ -47,7 +48,13 @@ export default class DaTitle extends LitElement {
4748
super.connectedCallback();
4849
this.shadowRoot.adoptedStyleSheets = [sheet];
4950
this._actionsVis = [];
51+
this.hasChanges = false;
5052
inlinesvg({ parent: this.shadowRoot, paths: ICONS });
53+
54+
if (this._isConfigView) {
55+
this._actionsVis = ['save'];
56+
}
57+
5158
if (this.details.view === 'sheet') {
5259
this.collabStatus = window.navigator.onLine
5360
? 'connected'
@@ -68,6 +75,7 @@ export default class DaTitle extends LitElement {
6875
}
6976

7077
handleError(json, action, icon) {
78+
// eslint-disable-next-line no-console
7179
console.log('handleError', json, action, icon);
7280
this._status = { ...json.error, action };
7381
icon.classList.remove('is-sending');
@@ -93,8 +101,14 @@ export default class DaTitle extends LitElement {
93101
async handleAction(action) {
94102
this.toggleActions();
95103
this._status = null;
96-
const sendBtn = this.shadowRoot.querySelector('.da-title-action-send-icon');
97-
sendBtn.classList.add('is-sending');
104+
105+
const sendBtn = this.shadowRoot.querySelector(
106+
this._isConfigView ? '.da-title-action' : '.da-title-action-send-icon',
107+
);
108+
109+
if (sendBtn) {
110+
sendBtn.classList.add('is-sending');
111+
}
98112

99113
const { hash } = window.location;
100114
const pathname = hash.replace('#', '');
@@ -104,13 +118,21 @@ export default class DaTitle extends LitElement {
104118
const dasSave = await saveToDa(pathname, this.sheet);
105119
if (!dasSave.ok) return;
106120
}
107-
if (this.details.view === 'config') {
121+
122+
if (this._isConfigView) {
108123
const daConfigResp = await saveDaConfig(pathname, this.sheet);
124+
125+
if (sendBtn) {
126+
sendBtn.classList.remove('is-sending');
127+
}
128+
109129
if (!daConfigResp.ok) {
110130
// eslint-disable-next-line no-console
111131
console.log('Saving configuration failed because:', daConfigResp.status, await daConfigResp.text());
112-
return;
132+
} else {
133+
this.hasChanges = false;
113134
}
135+
return;
114136
}
115137
if (action === 'preview' || action === 'publish') {
116138
const cdn = await getCdnConfig(pathname);
@@ -141,7 +163,7 @@ export default class DaTitle extends LitElement {
141163
window.open(`${toOpenInAem}?nocache=${Date.now()}`, toOpenInAem);
142164
}
143165
if (this.details.view === 'edit' && action === 'publish') saveDaVersion(pathname);
144-
sendBtn.classList.remove('is-sending');
166+
if (sendBtn) sendBtn.classList.remove('is-sending');
145167
}
146168

147169
async handleRoleRequest() {
@@ -189,15 +211,14 @@ export default class DaTitle extends LitElement {
189211
}
190212

191213
async toggleActions() {
192-
// toggle off if already on
193-
if (this._actionsVis.length > 0) {
194-
this._actionsVis = [];
214+
// Config view doesn't toggle
215+
if (this._isConfigView) {
195216
return;
196217
}
197218

198-
// toggle on for config
199-
if (this.details.view === 'config') {
200-
this._actionsVis = ['save'];
219+
// toggle off if already on
220+
if (this._actionsVis.length > 0) {
221+
this._actionsVis = [];
201222
return;
202223
}
203224

@@ -217,12 +238,17 @@ export default class DaTitle extends LitElement {
217238
return !this.permissions.some((permission) => permission === 'write');
218239
}
219240

241+
get _isConfigView() {
242+
return this.details.view === 'config';
243+
}
244+
220245
renderActions() {
221246
return html`${this._actionsVis.map((action) => html`
222247
<button
223248
@click=${() => this.handleAction(action)}
224-
class="con-button blue da-title-action"
225-
aria-label="Send">
249+
class="con-button da-title-action ${this._isConfigView && !this.hasChanges ? '' : 'blue'}"
250+
aria-label="${action}"
251+
?disabled=${this._isConfigView && !this.hasChanges}>
226252
${action.charAt(0).toUpperCase() + action.slice(1)}
227253
</button>
228254
`)}`;
@@ -290,14 +316,16 @@ export default class DaTitle extends LitElement {
290316
<div class="da-title-collab-actions-wrapper">
291317
${this.collabStatus ? this.renderCollab() : nothing}
292318
${this._status ? this.renderError() : nothing}
293-
<div class="da-title-actions ${this._fixedActions ? 'is-fixed' : ''} ${this._actionsVis.length > 0 ? 'is-open' : ''}">
319+
<div class="da-title-actions ${this._fixedActions ? 'is-fixed' : ''} ${!this._isConfigView && this._actionsVis.length > 0 ? 'is-open' : ''} ${this._isConfigView ? 'config' : ''}">
294320
${this.renderActions()}
295-
<button
296-
@click=${this.toggleActions}
297-
class="con-button blue da-title-action-send"
298-
aria-label="Send">
299-
<span class="da-title-action-send-icon"></span>
300-
</button>
321+
${this._isConfigView ? nothing : html`
322+
<button
323+
@click=${this.toggleActions}
324+
class="con-button blue da-title-action-send"
325+
aria-label="Send">
326+
<span class="da-title-action-send-icon"></span>
327+
</button>
328+
`}
301329
</div>
302330
</div>
303331
</div>

blocks/sheet/utils/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export const saveSheets = async (sheets) => {
1919
const debouncedSaveSheets = debounce(saveSheets, DEBOUNCE_TIME);
2020

2121
export function handleSave(jexcel, view) {
22-
if (view !== 'config') {
22+
if (view === 'config') {
23+
const daTitle = document.querySelector('da-title');
24+
25+
if (daTitle) {
26+
daTitle.hasChanges = true;
27+
}
28+
} else {
2329
debouncedSaveSheets(jexcel);
2430
}
2531
}

0 commit comments

Comments
 (0)