Skip to content

Commit 3291964

Browse files
committed
Fixes graph row selection issues
1 parent a438e87 commit 3291964

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

src/webviews/apps/plus/graph/graph-header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
10231023
?valid=${this.searchValid}
10241024
?more=${this.appState.searchResults?.paging?.hasMore ?? false}
10251025
?searching=${this.appState.searching}
1026-
?filter=${this.appState.filter.filter}
1026+
?filter=${this.hostState.defaultSearchMode === 'filter'}
10271027
value=${this.appState.filter.query}
10281028
errorMessage=${this.appState.searchResultsError?.error ?? ''}
10291029
?resultsHidden=${this.appState.searchResultsHidden}

src/webviews/apps/plus/graph/graph-wrapper/graph-wrapper-element.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GraphMissingRefsMetadata,
1313
GraphRefMetadataItem,
1414
} from '../../../../plus/graph/protocol';
15+
import type { GraphWrapperInitProps, GraphWrapperProps, GraphWrapperSubscriberProps } from './graph-wrapper.react';
1516
import { GraphWrapperReact } from './graph-wrapper.react';
1617

1718
// @customElement('gl-graph-wrapper-element')
@@ -38,8 +39,8 @@ export class WebGraph extends LitElement {
3839
private graphRef: GraphContainer | null = null;
3940

4041
// State updater function provided by the React component
41-
@state()
42-
private stateUpdater: ((props: any) => void) | null = null;
42+
// @state()
43+
private stateUpdater: ((props: Partial<GraphWrapperSubscriberProps>) => void) | null = null;
4344

4445
// Properties that match GraphWrapperProps
4546
@property({ type: String })
@@ -79,7 +80,7 @@ export class WebGraph extends LitElement {
7980
loading?: boolean;
8081

8182
@property({ type: Object })
82-
selectedRows?: Record<string, boolean>;
83+
selectedRows?: GraphWrapperProps['selectedRows'];
8384

8485
@property({ type: Boolean })
8586
windowFocused?: boolean;
@@ -124,10 +125,10 @@ export class WebGraph extends LitElement {
124125
}
125126

126127
// Update the React component's state when properties change
127-
override updated(_changedProperties: Map<string, any>): void {
128+
override updated(changedProperties: Map<string, unknown>): void {
128129
if (this.stateUpdater) {
129130
// Only update if we have a state updater and properties have changed
130-
const props = this.getProps();
131+
const props = this.getProps(changedProperties);
131132
this.stateUpdater(props);
132133
}
133134
}
@@ -145,15 +146,13 @@ export class WebGraph extends LitElement {
145146
// Get the initial props
146147
const props = this.getProps();
147148

148-
// Add the subscriber function to allow the React component to provide a state updater
149-
props.subscriber = (updater: (props: any) => void) => {
150-
this.stateUpdater = updater;
151-
};
152-
153149
// Mount the React component
154150
this.reactRoot.render(
155151
createElement(GraphWrapperReact, {
156152
...props,
153+
subscriber: (updater: (props: Partial<GraphWrapperSubscriberProps>) => void) => {
154+
this.stateUpdater = updater;
155+
},
157156
onChangeColumns: this.handleChangeColumns.bind(this),
158157
onGraphMouseLeave: this.handleGraphMouseLeave.bind(this),
159158
onChangeRefsVisibility: this.handleChangeRefsVisibility.bind(this),
@@ -167,17 +166,22 @@ export class WebGraph extends LitElement {
167166
onGraphRowHovered: this.handleGraphRowHovered.bind(this),
168167
onGraphRowUnhovered: this.handleGraphRowUnhovered.bind(this),
169168
onRowContextMenu: this.handleRowContextMenu.bind(this),
170-
}),
169+
} as GraphWrapperInitProps),
171170
);
172171
}
173172

174173
// Collect all props to pass to the React component
175-
private getProps(): any {
174+
private getProps(_changedProperties?: Map<string, unknown>): Partial<GraphWrapperSubscriberProps> {
175+
// TODO: look at only sending changed properties
176+
// if (changedProperties != null) {
177+
// return Object.fromEntries(changedProperties.entries());
178+
// }
179+
176180
return {
177181
activeRow: this.activeRow,
178182
avatars: this.avatars,
179183
columns: this.columns,
180-
context: this.context,
184+
context: this.context as GraphWrapperSubscriberProps['context'],
181185
config: this.config,
182186
downstreams: this.downstreams,
183187
rows: this.rows,

src/webviews/apps/plus/graph/graph-wrapper/graph-wrapper.react.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,18 @@ const emptySelectionContext: SelectionContext = {
186186

187187
interface GraphWrapperAPI {
188188
setRef: (refObject: GraphContainer) => void;
189-
subscriber?: (updater: (props: Readonly<GraphWrapperEvents & GraphWrapperProps & GraphWrapperAPI>) => void) => void;
190189
}
191190

191+
export type GraphWrapperSubscriberProps = GraphWrapperProps & GraphWrapperAPI;
192+
export type GraphWrapperInitProps = GraphWrapperProps &
193+
GraphWrapperEvents &
194+
GraphWrapperAPI & {
195+
subscriber?: (updater: (props: Partial<GraphWrapperSubscriberProps>) => void) => void;
196+
};
197+
192198
const emptyRows: GraphRow[] = [];
193199
// eslint-disable-next-line @typescript-eslint/naming-convention
194-
export function GraphWrapperReact(initProps: Readonly<GraphWrapperEvents & GraphWrapperProps & GraphWrapperAPI>) {
200+
export function GraphWrapperReact(initProps: GraphWrapperInitProps) {
195201
const [graph, _graphRef] = useState<GraphContainer | null>(null);
196202
const [context, setContext] = useState(initProps.context);
197203
const [props, setProps] = useState(initProps);
@@ -205,7 +211,7 @@ export function GraphWrapperReact(initProps: Readonly<GraphWrapperEvents & Graph
205211
// if (newProps.context !== context) {
206212
// setContext(newProps.context);
207213
// }
208-
setProps(newProps);
214+
setProps({ ...props, ...newProps });
209215
// Other state updates can be added here as needed
210216
});
211217
}

src/webviews/apps/plus/graph/graph-wrapper/graph-wrapper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { html, LitElement } from 'lit';
77
import { customElement, query } from 'lit/decorators.js';
88
import { ifDefined } from 'lit/directives/if-defined.js';
99
import type { GitGraphRowType } from '../../../../../git/models/graph';
10+
import { debounce } from '../../../../../system/decorators/debounce';
1011
import {
1112
DoubleClickedCommandType,
1213
GetMissingAvatarsCommand,
@@ -71,6 +72,7 @@ export class GlGraphWrapper extends SignalWatcher(LitElement) {
7172
this._ipc.sendCommand(GetMoreRowsCommand, { id: sha });
7273
}
7374

75+
@debounce(250)
7476
private onColumnsChanged(event: CustomEventType<'graph-changecolumns'>) {
7577
this._ipc.sendCommand(UpdateColumnsCommand, {
7678
config: event.detail.settings,
@@ -101,6 +103,7 @@ export class GlGraphWrapper extends SignalWatcher(LitElement) {
101103
this._ipc.sendCommand(UpdateGraphConfigurationCommand, { changes: changes });
102104
}
103105

106+
@debounce(250)
104107
private onSelectionChanged({ detail: rows }: CustomEventType<'graph-changeselection'>) {
105108
const selection = rows.filter(r => r != null).map(r => ({ id: r.sha, type: r.type as GitGraphRowType }));
106109
this._telemetry.sendEvent({ name: 'graph/row/selected', data: { rows: selection.length } });
@@ -223,7 +226,7 @@ export class GlGraphWrapper extends SignalWatcher(LitElement) {
223226
// eslint-disable-next-line lit/no-this-assign-in-render
224227
this.ref = ref;
225228
}}
226-
.filter=${{ ...this.graphAppState.filter }}
229+
.filter=${this.graphAppState.filter}
227230
@changecolumns=${this.onColumnsChanged}
228231
@changegraphconfiguration=${this.onGraphConfigurationChanged}
229232
@changerefsvisibility=${this.onRefsVisibilityChanged}

0 commit comments

Comments
 (0)