@@ -24,7 +24,6 @@ import { SectionFilterList } from '../lib/section-filter-list'
2424import { Octicon } from '../octicons'
2525import * as octicons from '../octicons/octicons.generated'
2626import memoizeOne from 'memoize-one'
27- import { getAuthors } from '../../lib/git/log'
2827import { Repository } from '../../models/repository'
2928import { formatDate } from '../../lib/format-date'
3029
@@ -107,18 +106,14 @@ interface IBranchListProps {
107106 readonly textbox ?: TextBox
108107
109108 /** Aria label for a specific row */
110- readonly getBranchAriaLabel : (
111- item : IBranchListItem ,
112- authorDate : Date | undefined
113- ) => string | undefined
109+ readonly getBranchAriaLabel : ( item : IBranchListItem ) => string | undefined
114110
115111 /**
116112 * Render function to apply to each branch in the list
117113 */
118114 readonly renderBranch : (
119115 item : IBranchListItem ,
120- matches : IMatches ,
121- authorDate : Date | undefined
116+ matches : IMatches
122117 ) => JSX . Element
123118
124119 /**
@@ -145,17 +140,8 @@ interface IBranchListProps {
145140 readonly onDeleteBranch ?: ( branchName : string ) => void
146141}
147142
148- interface IBranchListState {
149- readonly commitAuthorDates : ReadonlyMap < string , Date >
150- }
151-
152- const commitDateCache = new Map < string , Date > ( )
153-
154143/** The Branches list component. */
155- export class BranchList extends React . Component <
156- IBranchListProps ,
157- IBranchListState
158- > {
144+ export class BranchList extends React . Component < IBranchListProps > {
159145 private branchFilterList : SectionFilterList < IBranchListItem > | null = null
160146
161147 private getGroups = memoizeOne ( groupBranches )
@@ -167,7 +153,7 @@ export class BranchList extends React.Component<
167153 )
168154
169155 /**
170- * Generate a new object any time groups or commitAuthorDates changes
156+ * Generate a new object any time groups changes
171157 * in order to force the list to re-render.
172158 *
173159 * Note, change is determined by reference equality. This opaque object
@@ -179,14 +165,11 @@ export class BranchList extends React.Component<
179165 * Using a guid which we used to do works but is overkill.
180166 */
181167 private getInvalidationProp = memoizeOne (
182- (
183- _groups : ReturnType < typeof groupBranches > ,
184- _commitAuthorDates : IBranchListState [ 'commitAuthorDates' ]
185- ) => ( { } )
168+ ( _groups : ReturnType < typeof groupBranches > ) => ( { } )
186169 )
187170
188171 private get invalidationProp ( ) {
189- return this . getInvalidationProp ( this . groups , this . state . commitAuthorDates )
172+ return this . getInvalidationProp ( this . groups )
190173 }
191174
192175 private get groups ( ) {
@@ -203,62 +186,11 @@ export class BranchList extends React.Component<
203186 return this . getSelectedItem ( this . groups , this . props . selectedBranch )
204187 }
205188
206- public constructor ( props : IBranchListProps ) {
207- super ( props )
208- this . state = {
209- commitAuthorDates : new Map < string , Date > ( ) ,
210- }
211- }
212-
213189 public selectNextItem ( focus : boolean = false , direction : SelectionDirection ) {
214190 if ( this . branchFilterList !== null ) {
215191 this . branchFilterList . selectNextItem ( focus , direction )
216192 }
217193 }
218-
219- public componentDidUpdate ( prevProps : IBranchListProps ) {
220- if ( prevProps . allBranches !== this . props . allBranches ) {
221- this . populateCommitDates ( )
222- }
223- }
224-
225- private populateCommitDates = ( ) => {
226- const cached = new Map < string , Date > ( )
227- const missing = new Array < string > ( )
228- const uniqShas = new Set ( this . props . allBranches . map ( b => b . tip . sha ) )
229-
230- for ( const sha of uniqShas ) {
231- const date = commitDateCache . get ( sha )
232- if ( date ) {
233- cached . set ( sha , date )
234- } else {
235- missing . push ( sha )
236- }
237- }
238-
239- // Clean up the cache
240- for ( const sha of commitDateCache . keys ( ) ) {
241- if ( ! uniqShas . has ( sha ) ) {
242- commitDateCache . delete ( sha )
243- }
244- }
245-
246- this . setState ( { commitAuthorDates : cached } )
247-
248- if ( missing . length > 0 ) {
249- getAuthors ( this . props . repository , missing )
250- . then ( x => {
251- x . forEach ( ( { date } , i ) => commitDateCache . set ( missing [ i ] , date ) )
252- this . populateCommitDates ( )
253- } )
254- . catch ( e => log . error ( `Failed to populate commit dates` , e ) )
255- }
256- }
257-
258- public componentDidMount ( ) {
259- this . populateCommitDates ( )
260- }
261-
262194 public render ( ) {
263195 return (
264196 < SectionFilterList < IBranchListItem >
@@ -334,25 +266,18 @@ export class BranchList extends React.Component<
334266 }
335267
336268 private renderItem = ( item : IBranchListItem , matches : IMatches ) => {
337- return this . props . renderBranch (
338- item ,
339- matches ,
340- this . state . commitAuthorDates . get ( item . branch . tip . sha )
341- )
269+ return this . props . renderBranch ( item , matches )
342270 }
343271
344272 private renderRowFocusTooltip = (
345273 item : IBranchListItem
346274 ) : JSX . Element | string | null => {
347275 const { tip, name } = item . branch
348- const authorDate = this . state . commitAuthorDates . get ( tip . sha )
349276
350- const absoluteDate = authorDate
351- ? formatDate ( authorDate , {
352- dateStyle : 'full' ,
353- timeStyle : 'short' ,
354- } )
355- : null
277+ const absoluteDate = formatDate ( tip . author . date , {
278+ dateStyle : 'full' ,
279+ timeStyle : 'short' ,
280+ } )
356281
357282 const otherWorktreeName = this . inUseByOtherWorktreeName ( item )
358283 return (
@@ -400,10 +325,7 @@ export class BranchList extends React.Component<
400325 }
401326
402327 private getItemAriaLabel = ( item : IBranchListItem ) => {
403- return this . props . getBranchAriaLabel (
404- item ,
405- this . state . commitAuthorDates . get ( item . branch . tip . sha )
406- )
328+ return this . props . getBranchAriaLabel ( item )
407329 }
408330
409331 private getGroupAriaLabel = ( group : number ) => {
0 commit comments