This commit introduces 'Revert: None - Selected' toggle, enabling users to revert all reversible scripts with a single action, improving user safety and control over script effects. This feature addresses user-reported concerns about the ease of reverting script changes. This feature should enhance the user experience by streamlining the revert process along with providing essential information about script reversibility. Key changes: - Add buttons to revert all selected scripts or setting all selected scripts to non-revert state. - Add tooltips with detailed explanations about consequences of modifying revert states, includinginformation about irreversible script changes. Supporting changes: - Align items on top menu vertically for better visual consistency. - Rename `SelectionType` to `RecommendationStatusType` for more clarity. - Rename `IReverter` to `Reverter` to move away from `I` prefix convention. - The `.script` CSS class was duplicated in `TheScriptsView.vue` and `TheScriptsArea.vue`, leading to style collisions in the development environment. The class has been renamed to component-specific classes to avoid such issues in the future.
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
|
import { ReadonlyScriptSelection, ScriptSelection } from '@/application/Context/State/Selection/Script/ScriptSelection';
|
|
import { ScriptSelectionChange } from '@/application/Context/State/Selection/Script/ScriptSelectionChange';
|
|
import { RevertStatusType } from './RevertStatusType';
|
|
|
|
export function setCurrentRevertStatus(
|
|
desiredRevertStatus: boolean,
|
|
selection: ScriptSelection,
|
|
) {
|
|
const scriptRevertStatusChanges = getScriptRevertStatusChanges(
|
|
selection.selectedScripts,
|
|
desiredRevertStatus,
|
|
);
|
|
if (scriptRevertStatusChanges.length === 0) {
|
|
return;
|
|
}
|
|
selection.processChanges({ changes: scriptRevertStatusChanges });
|
|
}
|
|
|
|
export function getCurrentRevertStatus(
|
|
selection: ReadonlyScriptSelection,
|
|
): RevertStatusType {
|
|
const allScriptRevertStatuses = filterReversibleScripts(selection.selectedScripts)
|
|
.map((selectedScript) => selectedScript.revert);
|
|
if (!allScriptRevertStatuses.length) {
|
|
return RevertStatusType.NoReversibleScripts;
|
|
}
|
|
if (allScriptRevertStatuses.every((revertStatus) => revertStatus)) {
|
|
return RevertStatusType.AllScriptsReverted;
|
|
}
|
|
if (allScriptRevertStatuses.every((revertStatus) => !revertStatus)) {
|
|
return RevertStatusType.NoScriptsReverted;
|
|
}
|
|
return RevertStatusType.SomeScriptsReverted;
|
|
}
|
|
|
|
function getScriptRevertStatusChanges(
|
|
selectedScripts: readonly SelectedScript[],
|
|
desiredRevertStatus: boolean,
|
|
): ScriptSelectionChange[] {
|
|
const reversibleSelectedScripts = filterReversibleScripts(selectedScripts);
|
|
const selectedScriptsRequiringChange = filterScriptsRequiringRevertStatusChange(
|
|
reversibleSelectedScripts,
|
|
desiredRevertStatus,
|
|
);
|
|
const revertStatusChanges = mapToScriptSelectionChanges(
|
|
selectedScriptsRequiringChange,
|
|
desiredRevertStatus,
|
|
);
|
|
return revertStatusChanges;
|
|
}
|
|
|
|
function filterReversibleScripts(selectedScripts: readonly SelectedScript[]) {
|
|
return selectedScripts.filter(
|
|
(selectedScript) => selectedScript.script.canRevert(),
|
|
);
|
|
}
|
|
|
|
function filterScriptsRequiringRevertStatusChange(
|
|
selectedScripts: readonly SelectedScript[],
|
|
desiredRevertStatus: boolean,
|
|
) {
|
|
return selectedScripts.filter(
|
|
(selectedScript) => selectedScript.revert !== desiredRevertStatus,
|
|
);
|
|
}
|
|
|
|
function mapToScriptSelectionChanges(
|
|
scriptsNeedingChange: readonly SelectedScript[],
|
|
newRevertStatus: boolean,
|
|
): ScriptSelectionChange[] {
|
|
return scriptsNeedingChange.map((script): ScriptSelectionChange => ({
|
|
scriptId: script.id,
|
|
newStatus: {
|
|
isSelected: true,
|
|
isReverted: newRevertStatus,
|
|
},
|
|
}));
|
|
}
|