Skip to content

Commit

Permalink
Updates graph typings and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed Mar 2, 2023
1 parent 4891099 commit d85178e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
10 changes: 6 additions & 4 deletions src/plus/webviews/graph/graphWebview.ts
Expand Up @@ -65,7 +65,7 @@ import { Repository, RepositoryChange, RepositoryChangeComparisonMode } from '..
import type { GitSearch } from '../../../git/search';
import { getSearchQueryComparisonKey } from '../../../git/search';
import { showRepositoryPicker } from '../../../quickpicks/repositoryPicker';
import type { StoredGraphFilters, StoredGraphIncludeOnlyRef } from '../../../storage';
import type { StoredGraphFilters, StoredGraphIncludeOnlyRef, StoredGraphRefType } from '../../../storage';
import {
executeActionCommand,
executeCommand,
Expand Down Expand Up @@ -1129,7 +1129,7 @@ export class GraphWebview extends WebviewBase<State> {
repoPath: string | undefined,
id: string | undefined,
type: GitGraphRowType | undefined,
) {
): GitStashReference | GitRevisionReference | undefined {
if (repoPath == null || id == null) return undefined;

switch (type) {
Expand Down Expand Up @@ -1890,7 +1890,9 @@ export class GraphWebview extends WebviewBase<State> {
storedExcludeRefs = updateRecordValue(
storedExcludeRefs,
ref.id,
visible ? undefined : { id: ref.id, type: ref.type, name: ref.name, owner: ref.owner },
visible
? undefined
: { id: ref.id, type: ref.type as StoredGraphRefType, name: ref.name, owner: ref.owner },
);
}

Expand Down Expand Up @@ -1920,7 +1922,7 @@ export class GraphWebview extends WebviewBase<State> {
for (const ref of refs) {
storedIncludeOnlyRefs[ref.id] = {
id: ref.id,
type: ref.type,
type: ref.type as StoredGraphRefType,
name: ref.name,
owner: ref.owner,
};
Expand Down
7 changes: 0 additions & 7 deletions src/plus/webviews/graph/protocol.ts
@@ -1,5 +1,4 @@
import type {
CommitDateTimeSource,
CssVariables,
ExcludeByType,
ExcludeRefsById,
Expand Down Expand Up @@ -74,12 +73,6 @@ export const enum GraphMinimapMarkerTypes {

export const supportedRefMetadataTypes: GraphRefMetadataType[] = Object.values(GraphRefMetadataTypes);

export type GraphCommitDateTimeSource = CommitDateTimeSource;
export enum GraphCommitDateTimeSources {
RowEntry = 'rowEntry',
Tooltip = 'tooltip',
}

export interface State {
windowFocused?: boolean;
repositories?: GraphRepository[];
Expand Down
21 changes: 11 additions & 10 deletions src/webviews/apps/plus/graph/GraphWrapper.tsx
Expand Up @@ -2,6 +2,7 @@ import type {
GraphColumnSetting,
GraphColumnsSettings,
GraphContainerProps,
GraphMarkerType,
GraphPlatform,
GraphRef,
GraphRefGroup,
Expand All @@ -10,7 +11,7 @@ import type {
GraphZoneType,
OnFormatCommitDateTime,
} from '@gitkraken/gitkraken-components';
import GraphContainer, { GRAPH_ZONE_TYPE, REF_ZONE_TYPE } from '@gitkraken/gitkraken-components';
import GraphContainer, { CommitDateTimeSources, commitZone, refZone } from '@gitkraken/gitkraken-components';
import { VSCodeCheckbox, VSCodeRadio, VSCodeRadioGroup } from '@vscode/webview-ui-toolkit/react';
import type { FormEvent, ReactElement } from 'react';
import React, { createElement, useEffect, useMemo, useRef, useState } from 'react';
Expand All @@ -25,7 +26,6 @@ import type {
GraphAvatars,
GraphColumnName,
GraphColumnsConfig,
GraphCommitDateTimeSource,
GraphComponentConfig,
GraphExcludedRef,
GraphExcludeTypes,
Expand All @@ -52,7 +52,6 @@ import {
DidChangeWorkingTreeNotificationType,
DidFetchNotificationType,
DidSearchNotificationType,
GraphCommitDateTimeSources,
GraphMinimapMarkerTypes,
} from '../../../../plus/webviews/graph/protocol';
import type { Subscription } from '../../../../subscription';
Expand Down Expand Up @@ -104,7 +103,7 @@ export interface GraphWrapperProps {
}

const getGraphDateFormatter = (config?: GraphComponentConfig): OnFormatCommitDateTime => {
return (commitDateTime: number, source?: GraphCommitDateTimeSource) =>
return (commitDateTime: number, source?: CommitDateTimeSources) =>
formatCommitDateTime(commitDateTime, config?.dateStyle, config?.dateFormat, source);
};

Expand Down Expand Up @@ -594,7 +593,7 @@ export function GraphWrapper({
};

const handleOnGraphRowHovered = (_event: any, graphZoneType: GraphZoneType, graphRow: GraphRow) => {
if (graphZoneType === REF_ZONE_TYPE || minimap.current == null) return;
if (graphZoneType === refZone || minimap.current == null) return;

minimap.current?.select(graphRow.date, true);
};
Expand Down Expand Up @@ -886,7 +885,7 @@ export function GraphWrapper({
graphZoneType: GraphZoneType,
row: GraphRow,
) => {
if (graphZoneType === REF_ZONE_TYPE || graphZoneType === GRAPH_ZONE_TYPE) return;
if (graphZoneType === refZone || graphZoneType === commitZone) return;

onDoubleClickRow?.(row, true);
};
Expand Down Expand Up @@ -1303,7 +1302,9 @@ export function GraphWrapper({
cssVariables={styleProps?.cssVariables}
dimMergeCommits={graphConfig?.dimMergeCommits}
enabledRefMetadataTypes={graphConfig?.enabledRefMetadataTypes}
enabledScrollMarkerTypes={graphConfig?.enabledScrollMarkerTypes}
enabledScrollMarkerTypes={
graphConfig?.enabledScrollMarkerTypes as GraphMarkerType[] | undefined
}
enableMultiSelection={graphConfig?.enableMultiSelection}
excludeRefsById={excludeRefsById}
excludeByType={excludeTypes}
Expand Down Expand Up @@ -1366,12 +1367,12 @@ function formatCommitDateTime(
date: number,
style: DateStyle = DateStyle.Absolute,
format: DateTimeFormat | string = 'short+short',
source?: GraphCommitDateTimeSource,
source?: CommitDateTimeSources,
): string {
switch (source) {
case GraphCommitDateTimeSources.Tooltip:
case CommitDateTimeSources.Tooltip:
return `${formatDate(date, format)} (${fromNow(date)})`;
case GraphCommitDateTimeSources.RowEntry:
case CommitDateTimeSources.RowEntry:
default:
return style === DateStyle.Relative ? fromNow(date) : formatDate(date, format);
}
Expand Down

0 comments on commit d85178e

Please sign in to comment.