Show transient share confirmation
This commit is contained in:
1 parent
0293791167
commit
6a197ea0ba
6 files changed
+159
-4
No files matched your search
@@ -151,6 +151,29 @@ button:not(.tablinks):not(.action-btn):not(.editor-source-tab):not(.status-state
|
||||
color: var(--mu-green-dark);
|
||||
}
|
||||
|
||||
/* Short action confirmations follow the TRIMSP-NL pattern: visible beside the
|
||||
initiating control, non-blocking, and automatically dismissed. */
|
||||
.transient-warning {
|
||||
background: #fff1c9;
|
||||
border: 1px solid #c79824;
|
||||
border-radius: 7px;
|
||||
box-shadow: 0 7px 20px rgba(31, 39, 33, 0.17);
|
||||
box-sizing: border-box;
|
||||
color: #523c08;
|
||||
line-height: 1.35;
|
||||
max-width: min(380px, calc(100vw - 24px));
|
||||
opacity: 0;
|
||||
padding: 9px 12px;
|
||||
pointer-events: none;
|
||||
position: fixed;
|
||||
transition: opacity 0.2s ease;
|
||||
z-index: 2000;
|
||||
}
|
||||
|
||||
.transient-warning.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Persistent workflow actions.
|
||||
These controls apply across tabs, so they sit outside the Runs form and stay
|
||||
visible while the user edits parameters, constraints, or the MSR text. */
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
<button type="button" class="tablinks" onclick="openTab(event,'Jobs');renderJobStatus();" id="btnJobs">Results</button>
|
||||
<button type="button" class="help-button" onclick="showQuickStartHelp();"
|
||||
title="Quick Start / Help" aria-label="Quick Start / Help">?</button>
|
||||
<button type="button" class="help-button share-button" onclick="copyWebConfigurationLink();"
|
||||
<button type="button" class="help-button share-button" id="shareConfigButton"
|
||||
onclick="copyWebConfigurationLink();"
|
||||
title="Copy configuration link" aria-label="Copy configuration link">
|
||||
<svg class="share-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||
<circle cx="18" cy="5" r="2.5"></circle>
|
||||
|
||||
+13
-3
@@ -128,14 +128,24 @@ async function copyWebConfigurationLink() {
|
||||
throw new Error("Electron clipboard is unavailable");
|
||||
}
|
||||
clipboard.writeText(url);
|
||||
if (typeof showTransientWarning === "function") {
|
||||
showTransientWarning(
|
||||
"Configuration link copied.",
|
||||
document.getElementById("shareConfigButton"),
|
||||
3500
|
||||
);
|
||||
}
|
||||
if (typeof setFitStatus === "function") {
|
||||
setFitStatus("Configuration link copied.", { level: "success" });
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (typeof window !== "undefined" && typeof window.prompt === "function") {
|
||||
window.prompt("Copy configuration link:", url);
|
||||
return true;
|
||||
if (typeof showTransientWarning === "function") {
|
||||
showTransientWarning(
|
||||
"Could not copy configuration link.",
|
||||
document.getElementById("shareConfigButton"),
|
||||
3500
|
||||
);
|
||||
}
|
||||
if (typeof setFitStatus === "function") {
|
||||
setFitStatus("Could not copy configuration link.", { level: "error" });
|
||||
|
||||
@@ -1338,6 +1338,50 @@ function setAppNotice(summary, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
// Match TRIMSP-NL's lightweight confirmation beside the control that caused an
|
||||
// action. Reusing one element prevents repeated share clicks from stacking notices.
|
||||
var transientWarningTimeout = null;
|
||||
function showTransientWarning(message, targetElement, duration = 4000) {
|
||||
let warning = document.getElementById("transientWarning");
|
||||
if (!warning) {
|
||||
warning = document.createElement("div");
|
||||
warning.id = "transientWarning";
|
||||
warning.className = "transient-warning";
|
||||
document.body.appendChild(warning);
|
||||
}
|
||||
|
||||
warning.textContent = message;
|
||||
if (targetElement) {
|
||||
let rect = targetElement.getBoundingClientRect();
|
||||
let viewportMargin = 12;
|
||||
let targetGap = 8;
|
||||
let maximumLeft = Math.max(
|
||||
viewportMargin,
|
||||
window.innerWidth - warning.offsetWidth - viewportMargin
|
||||
);
|
||||
let left = Math.min(Math.max(viewportMargin, rect.left), maximumLeft);
|
||||
let top = rect.bottom + targetGap;
|
||||
|
||||
// Keep the fixed notification visible when the share button is close to
|
||||
// the right or bottom edge of a compact Electron window.
|
||||
if (top + warning.offsetHeight > window.innerHeight - viewportMargin) {
|
||||
top = rect.top - warning.offsetHeight - targetGap;
|
||||
}
|
||||
top = Math.max(
|
||||
viewportMargin,
|
||||
Math.min(top, window.innerHeight - warning.offsetHeight - viewportMargin)
|
||||
);
|
||||
warning.style.left = left + "px";
|
||||
warning.style.top = top + "px";
|
||||
}
|
||||
warning.classList.add("visible");
|
||||
|
||||
if (transientWarningTimeout) clearTimeout(transientWarningTimeout);
|
||||
transientWarningTimeout = setTimeout(function() {
|
||||
warning.classList.remove("visible");
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// Compatibility entry point for integrations that still call the old helper.
|
||||
// Application code uses setAppNotice() so severity and detailed text are explicit.
|
||||
function setFitStatus(message, options = {}) {
|
||||
|
||||
@@ -359,6 +359,13 @@ async function copyWebConfigurationLink() {
|
||||
if (typeof setFitStatus === "function") {
|
||||
setFitStatus("Configuration link copied.", { level: "success" });
|
||||
}
|
||||
if (typeof showTransientWarning === "function") {
|
||||
showTransientWarning(
|
||||
"Configuration link copied.",
|
||||
document.getElementById("shareConfigButton"),
|
||||
3500
|
||||
);
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
// Clipboard access can be blocked by browser policy. A prompt still gives
|
||||
|
||||
@@ -136,6 +136,74 @@ function testElectronMenuAndRendererAreConnected() {
|
||||
assert.strictEqual(typeof env.ipcListeners.openSharedConfiguration, "function");
|
||||
}
|
||||
|
||||
function testTransientWarningIsPositionedAndTimed() {
|
||||
const env = loadSharedConfigurationHelpers();
|
||||
const lib = env.sandbox;
|
||||
const classes = new Set();
|
||||
const warningElement = {
|
||||
classList: {
|
||||
add: function(name) { classes.add(name); },
|
||||
remove: function(name) { classes.delete(name); }
|
||||
},
|
||||
offsetHeight: 34,
|
||||
offsetWidth: 180,
|
||||
style: {}
|
||||
};
|
||||
env.elements.transientWarning = null;
|
||||
lib.document.createElement = function() { return warningElement; };
|
||||
lib.document.body = {
|
||||
appendChild: function(element) { env.elements.transientWarning = element; }
|
||||
};
|
||||
lib.window.innerWidth = 600;
|
||||
lib.window.innerHeight = 400;
|
||||
let timeoutDuration = 0;
|
||||
lib.setTimeout = function(callback, duration) {
|
||||
timeoutDuration = duration;
|
||||
return 1;
|
||||
};
|
||||
const target = {
|
||||
getBoundingClientRect: function() {
|
||||
return { left: 500, right: 530, top: 20, bottom: 50 };
|
||||
}
|
||||
};
|
||||
|
||||
lib.showTransientWarning("Configuration link copied.", target, 3500);
|
||||
|
||||
assert.strictEqual(warningElement.textContent, "Configuration link copied.");
|
||||
assert.strictEqual(warningElement.style.left, "408px");
|
||||
assert.strictEqual(warningElement.style.top, "58px");
|
||||
assert.strictEqual(classes.has("visible"), true);
|
||||
assert.strictEqual(timeoutDuration, 3500);
|
||||
}
|
||||
|
||||
async function testElectronShareProvidesVisibleConfirmation() {
|
||||
const env = loadSharedConfigurationHelpers();
|
||||
const lib = env.sandbox;
|
||||
env.elements.Runs = { querySelectorAll: function() { return []; } };
|
||||
env.elements.Params = { querySelectorAll: function() { return []; } };
|
||||
lib.prepCFG = function() {};
|
||||
lib.getFitComponentValues = function() { return ["Exponential"]; };
|
||||
env.elements.shareConfigButton = { id: "shareConfigButton" };
|
||||
let warning = null;
|
||||
let status = "";
|
||||
lib.showTransientWarning = function(message, target, duration) {
|
||||
warning = { message: message, target: target, duration: duration };
|
||||
};
|
||||
lib.setFitStatus = function(message) { status = message; };
|
||||
|
||||
const copied = await lib.copyWebConfigurationLink();
|
||||
|
||||
assert.strictEqual(copied, true);
|
||||
assert.strictEqual(warning.message, "Configuration link copied.");
|
||||
assert.strictEqual(warning.target, env.elements.shareConfigButton);
|
||||
assert.strictEqual(warning.duration, 3500);
|
||||
assert.match(
|
||||
env.electron.clipboard.readText(),
|
||||
/^http:\/\/musruser\.psi\.ch\/muSRFlow\/#c=/
|
||||
);
|
||||
assert.strictEqual(status, "Configuration link copied.");
|
||||
}
|
||||
|
||||
async function testSharedRestoreCannotChangeLocalPreferences() {
|
||||
const env = loadSharedConfigurationHelpers();
|
||||
const lib = env.sandbox;
|
||||
@@ -259,6 +327,8 @@ async function main() {
|
||||
testElectronCodecReadsWebCompatibleLinks();
|
||||
testSharedConfigurationIncludesDetectorMaps();
|
||||
testElectronMenuAndRendererAreConnected();
|
||||
testTransientWarningIsPositionedAndTimed();
|
||||
await testElectronShareProvidesVisibleConfirmation();
|
||||
await testSharedRestoreCannotChangeLocalPreferences();
|
||||
await testElectronDialogRestoresStateAndMarksEditorStale();
|
||||
await testUserCanCancelOverwritingEditorOwnership();
|
||||
|
||||
Reference in new issue
Block a user