Skip to content

Commit

Permalink
Adds experimental activity minibar on Commit Graph
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 29, 2023
1 parent 9e59258 commit 087828a
Show file tree
Hide file tree
Showing 11 changed files with 1,264 additions and 6 deletions.
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -2308,6 +2308,13 @@
"markdownDescription": "Specifies whether to show the _Commit Graph_ in the status bar",
"scope": "window",
"order": 100
},
"gitlens.graph.experimental.activityMinibar.enabled": {
"type": "boolean",
"default": false,
"markdownDescription": "Specifies whether to show an activity minibar above the _Commit Graph_",
"scope": "window",
"order": 100
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Expand Up @@ -388,6 +388,11 @@ export interface GraphConfig {
dateStyle: DateStyle | null;
defaultItemLimit: number;
dimMergeCommits: boolean;
experimental: {
activityMinibar: {
enabled: boolean;
};
};
highlightRowsOnRefHover: boolean;
scrollRowPadding: number;
showDetailsView: 'open' | 'selection' | false;
Expand Down
10 changes: 8 additions & 2 deletions src/plus/webviews/graph/graphWebview.ts
Expand Up @@ -559,7 +559,8 @@ export class GraphWebview extends WebviewBase<State> {
configuration.changed(e, 'graph.showGhostRefsOnRowHover') ||
configuration.changed(e, 'graph.pullRequests.enabled') ||
configuration.changed(e, 'graph.showRemoteNames') ||
configuration.changed(e, 'graph.showUpstreamStatus')
configuration.changed(e, 'graph.showUpstreamStatus') ||
configuration.changed(e, 'graph.experimental.activityMinibar.enabled')
) {
void this.notifyDidChangeConfiguration();
}
Expand Down Expand Up @@ -1563,6 +1564,7 @@ export class GraphWebview extends WebviewBase<State> {

private getComponentConfig(): GraphComponentConfig {
const config: GraphComponentConfig = {
activityMinibar: configuration.get('graph.experimental.activityMinibar.enabled'),
avatars: configuration.get('graph.avatars'),
dateFormat:
configuration.get('graph.dateFormat') ?? configuration.get('defaultDateFormat') ?? 'short+short',
Expand Down Expand Up @@ -1666,7 +1668,11 @@ export class GraphWebview extends WebviewBase<State> {
const dataPromise = this.container.git.getCommitsForGraph(
this.repository.path,
this._panel!.webview.asWebviewUri.bind(this._panel!.webview),
{ limit: limit, ref: ref },
{
include: { stats: configuration.get('graph.experimental.activityMinibar.enabled') },
limit: limit,
ref: ref,
},
);

// Check for GitLens+ access and working tree stats
Expand Down
1 change: 1 addition & 0 deletions src/plus/webviews/graph/protocol.ts
Expand Up @@ -123,6 +123,7 @@ export type GraphTag = Tag;
export type GraphBranch = Head;

export interface GraphComponentConfig {
activityMinibar?: boolean;
avatars?: boolean;
dateFormat: DateTimeFormat | string;
dateStyle: DateStyle;
Expand Down
37 changes: 37 additions & 0 deletions src/system/date.ts
Expand Up @@ -22,6 +22,8 @@ let defaultLocales: string[] | undefined;
let defaultRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;
let defaultShortRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;

const numberFormatCache = new Map<string | undefined, Intl.NumberFormat>();

export function setDefaultDateLocales(locales: string | string[] | null | undefined) {
if (typeof locales === 'string') {
if (locales === 'system') {
Expand All @@ -32,9 +34,13 @@ export function setDefaultDateLocales(locales: string | string[] | null | undefi
} else {
defaultLocales = locales ?? undefined;
}

defaultRelativeTimeFormat = undefined;
defaultShortRelativeTimeFormat = undefined;
dateTimeFormatCache.clear();

numberFormatCache.clear();

locale = undefined;
}

Expand Down Expand Up @@ -346,3 +352,34 @@ function formatWithOrdinal(n: number): string {
const v = n % 100;
return `${n}${ordinals[(v - 20) % 10] ?? ordinals[v] ?? ordinals[0]}`;
}

export function formatNumeric(
value: number,
style?: 'decimal' | 'currency' | 'percent' | 'unit' | null | undefined,
locale?: string,
): string {
if (style == null) {
style = 'decimal';
}

const key = `${locale ?? ''}:${style}`;

let formatter = numberFormatCache.get(key);
if (formatter == null) {
const options: Intl.NumberFormatOptions = { localeMatcher: 'best fit', style: style };

let locales;
if (locale == null) {
locales = defaultLocales;
} else if (locale === 'system') {
locales = undefined;
} else {
locales = [locale];
}

formatter = new Intl.NumberFormat(locales, options);
numberFormatCache.set(key, formatter);
}

return formatter.format(value);
}
11 changes: 10 additions & 1 deletion src/system/iterable.ts
Expand Up @@ -107,14 +107,23 @@ export function find<T>(source: Iterable<T> | IterableIterator<T>, predicate: (i
return null;
}

export function findIndex<T>(source: Iterable<T> | IterableIterator<T>, predicate: (item: T) => boolean): number {
let i = 0;
for (const item of source) {
if (predicate(item)) return i;
i++;
}
return -1;
}

export function first<T>(source: Iterable<T> | IterableIterator<T>): T | undefined {
return source[Symbol.iterator]().next().value as T | undefined;
}

export function* flatMap<T, TMapped>(
source: Iterable<T> | IterableIterator<T>,
mapper: (item: T) => Iterable<TMapped>,
): Iterable<TMapped> {
): IterableIterator<TMapped> {
for (const item of source) {
yield* mapper(item);
}
Expand Down

0 comments on commit 087828a

Please sign in to comment.