summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilutin Kristofic <milutin@google.com>2024-04-04 19:57:35 +0200
committerPaladox none <thomasmulhall410@yahoo.com>2024-04-16 14:29:10 +0000
commitd63912e27f45e9684a8a3025977eadc86c350c3d (patch)
tree656651c1ca79d5a6c2f1ea1f491609763e0c193e
parent605f985e3dcdb332408ccb41a5dd850b6208f734 (diff)
Show Edit File Actions for commit message
You can open commit message and edit it in EDIT MODE. But there isn't ACTIONS dropdown on commit message row. This change is adding this, but dropdown has only OPEN actions since other actions doesn't make sense for commit message. Google-Bug-Id: b/332835638 Release-Notes: skip Change-Id: I1a63c09ae0c78ac0fd74a15f441c13df43740c2e (cherry picked from commit 8851831c48f4e2a3e0c6ced47b35376bc0e3d6d3)
-rw-r--r--polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.ts22
-rw-r--r--polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.ts35
-rw-r--r--polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls.ts19
3 files changed, 62 insertions, 14 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.ts b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.ts
index dc75a16a18..48e3118447 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.ts
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.ts
@@ -1489,7 +1489,11 @@ export class GrFileList extends LitElement {
this.editMode,
() => html`
<gr-edit-file-controls
- class=${this.computeClass('', file.__path)}
+ class=${this.computeClass(
+ '',
+ file.__path,
+ /* showForCommitMessage */ true
+ )}
.filePath=${file.__path}
></gr-edit-file-controls>
`
@@ -2276,11 +2280,17 @@ export class GrFileList extends LitElement {
return delta > 0 ? 'added' : 'removed';
}
- private computeClass(baseClass?: string, path?: string) {
- const classes = [];
- if (baseClass) classes.push(baseClass);
- if (isMagicPath(path)) classes.push('invisible');
- return classes.join(' ');
+ // Private but used in tests.
+ computeClass(baseClass = '', path?: string, showForCommitMessage = false) {
+ const classes = [baseClass];
+ if (
+ !(showForCommitMessage && path === SpecialFilePath.COMMIT_MESSAGE) &&
+ isMagicPath(path)
+ ) {
+ classes.push('invisible');
+ }
+
+ return classes.join(' ').trim();
}
private computePathClass(path: string | undefined) {
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.ts b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.ts
index 1cfbb83a24..eec829a63f 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.ts
@@ -39,6 +39,7 @@ import {
import {
createDefaultDiffPrefs,
DiffViewMode,
+ SpecialFilePath,
} from '../../../constants/constants';
import {
assertIsDefined,
@@ -2259,11 +2260,41 @@ suite('gr-file-list tests', () => {
element.editMode = true;
await element.updateComplete;
- // Commit message should not have edit controls.
+ // Commit message can have edit controls.
const editControls = Array.from(
queryAll(element, '.row:not(.header-row)')
).map(row => row.querySelector('gr-edit-file-controls'));
- assert.isTrue(editControls[0]!.classList.contains('invisible'));
+ assert.isFalse(editControls[0]!.classList.contains('invisible'));
+ });
+ });
+
+ suite('computeClass', () => {
+ test('works', () => {
+ assert.equal(
+ element.computeClass(
+ '',
+ SpecialFilePath.MERGE_LIST,
+ /* showForCommitMessage */ true
+ ),
+ 'invisible'
+ );
+ assert.equal(
+ element.computeClass(
+ '',
+ SpecialFilePath.COMMIT_MESSAGE,
+ /* showForCommitMessage */ true
+ ),
+ ''
+ );
+ assert.equal(
+ element.computeClass(
+ '',
+ SpecialFilePath.COMMIT_MESSAGE,
+ /* showForCommitMessage */ false
+ ),
+ 'invisible'
+ );
+ assert.equal(element.computeClass('', 'file.java'), '');
});
});
});
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls.ts b/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls.ts
index 7e49a1201c..e343a0172a 100644
--- a/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls.ts
+++ b/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls.ts
@@ -11,6 +11,7 @@ import {LitElement, css, html} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {fire} from '../../../utils/event-util';
import {DropdownLink} from '../../../types/common';
+import {SpecialFilePath} from '../../../constants/constants';
interface EditAction {
label: string;
@@ -76,12 +77,18 @@ export class GrEditFileControls extends LitElement {
_computeFileActions(actions: EditAction[]): DropdownLink[] {
// TODO(kaspern): conditionally disable some actions based on file status.
- return actions.map(action => {
- return {
- name: action.label,
- id: action.id,
- };
- });
+ return actions
+ .filter(
+ action =>
+ this.filePath !== SpecialFilePath.COMMIT_MESSAGE ||
+ action.label === GrEditConstants.Actions.OPEN.label
+ )
+ .map(action => {
+ return {
+ name: action.label,
+ id: action.id,
+ };
+ });
}
}