Add 'Revert All Selection' feature #68
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.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { expect } from 'vitest';
|
||||
import { ScriptSelection } from '@/application/Context/State/Selection/Script/ScriptSelection';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ScriptSelectionChangeCommand } from '@/application/Context/State/Selection/Script/ScriptSelectionChange';
|
||||
import { ScriptSelectionChange, ScriptSelectionChangeCommand } from '@/application/Context/State/Selection/Script/ScriptSelectionChange';
|
||||
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
import { EventSourceStub } from './EventSourceStub';
|
||||
import { SelectedScriptStub } from './SelectedScriptStub';
|
||||
@@ -31,24 +33,22 @@ export class ScriptSelectionStub
|
||||
}
|
||||
|
||||
public isScriptSelected(scriptId: string, revert: boolean): boolean {
|
||||
const call = this.callHistory.find(
|
||||
(c) => c.methodName === 'processChanges'
|
||||
&& c.args[0].changes.some((change) => (
|
||||
change.newStatus.isSelected === true
|
||||
&& change.newStatus.isReverted === revert
|
||||
&& change.scriptId === scriptId)),
|
||||
);
|
||||
return call !== undefined;
|
||||
return this.isScriptChanged({
|
||||
scriptId,
|
||||
newStatus: {
|
||||
isSelected: true,
|
||||
isReverted: revert,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public isScriptDeselected(scriptId: string): boolean {
|
||||
const call = this.callHistory.find(
|
||||
(c) => c.methodName === 'processChanges'
|
||||
&& c.args[0].changes.some((change) => (
|
||||
change.newStatus.isSelected === false
|
||||
&& change.scriptId === scriptId)),
|
||||
);
|
||||
return call !== undefined;
|
||||
return this.isScriptChanged({
|
||||
scriptId,
|
||||
newStatus: {
|
||||
isSelected: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public processChanges(action: ScriptSelectionChangeCommand): void {
|
||||
@@ -86,4 +86,45 @@ export class ScriptSelectionStub
|
||||
}
|
||||
return this.isSelectedResult;
|
||||
}
|
||||
|
||||
public assertSelectionChanges(expectedChanges: readonly ScriptSelectionChange[]): void {
|
||||
const actualChanges = this.getAllChanges();
|
||||
expect(actualChanges).to.have.lengthOf(expectedChanges.length, formatAssertionMessage([
|
||||
`Expected number of changes to be ${expectedChanges.length}, but found ${actualChanges.length}`,
|
||||
`Expected changes (${expectedChanges.length}):`, toNumberedPrettyJson(expectedChanges),
|
||||
`Actual changes (${actualChanges.length}):`, toNumberedPrettyJson(actualChanges),
|
||||
]));
|
||||
const unexpectedChanges = actualChanges.filter(
|
||||
(actual) => !expectedChanges.some((expected) => isSameChange(actual, expected)),
|
||||
);
|
||||
expect(unexpectedChanges).to.have.lengthOf(0, formatAssertionMessage([
|
||||
`Found ${unexpectedChanges.length} unexpected changes.`,
|
||||
'Unexpected changes:', toNumberedPrettyJson(unexpectedChanges),
|
||||
'Expected changes:', toNumberedPrettyJson(expectedChanges),
|
||||
'Actual changes:', toNumberedPrettyJson(actualChanges),
|
||||
]));
|
||||
}
|
||||
|
||||
private isScriptChanged(expectedChange: ScriptSelectionChange): boolean {
|
||||
return this.getAllChanges().some((change) => isSameChange(change, expectedChange));
|
||||
}
|
||||
|
||||
private getAllChanges(): ScriptSelectionChange[] {
|
||||
const processChangesCalls = this.callHistory.filter((c) => c.methodName === 'processChanges');
|
||||
const changeCommands = processChangesCalls.map(
|
||||
(call) => call.args[0] as ScriptSelectionChangeCommand,
|
||||
);
|
||||
const changes = changeCommands.flatMap((command) => command.changes);
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
|
||||
function isSameChange(change: ScriptSelectionChange, otherChange: ScriptSelectionChange): boolean {
|
||||
return change.newStatus.isSelected === otherChange.newStatus.isSelected
|
||||
&& change.newStatus.isReverted === otherChange.newStatus.isReverted
|
||||
&& change.scriptId === otherChange.scriptId;
|
||||
}
|
||||
|
||||
function toNumberedPrettyJson<T>(array: readonly T[]): string {
|
||||
return array.map((item, index) => `${index + 1}: ${JSON.stringify(item, undefined, 2)}`).join('\n');
|
||||
}
|
||||
|
||||
@@ -16,12 +16,17 @@ export class ScriptStub extends BaseEntity<string> implements IScript {
|
||||
|
||||
public level? = RecommendationLevel.Standard;
|
||||
|
||||
private isReversible: boolean | undefined = undefined;
|
||||
|
||||
constructor(public readonly id: string) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public canRevert(): boolean {
|
||||
return Boolean(this.code.revert);
|
||||
if (this.isReversible === undefined) {
|
||||
return Boolean(this.code.revert);
|
||||
}
|
||||
return this.isReversible;
|
||||
}
|
||||
|
||||
public withLevel(value: RecommendationLevel | undefined): this {
|
||||
@@ -42,6 +47,11 @@ export class ScriptStub extends BaseEntity<string> implements IScript {
|
||||
return this;
|
||||
}
|
||||
|
||||
public withReversibility(isReversible: boolean): this {
|
||||
this.isReversible = isReversible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRevertCode(revertCode?: string): this {
|
||||
this.code = {
|
||||
execute: this.code.execute,
|
||||
|
||||
Reference in New Issue
Block a user