From beb503ae81303d63abb821f2b0c66e41633b4705 Mon Sep 17 00:00:00 2001 From: ericf-axosoft <90025366+ericf-axosoft@users.noreply.github.com> Date: Tue, 20 Sep 2022 10:03:58 +0200 Subject: [PATCH] Feature/hide graph column (#2216) * Add simple dropdown for hiding graph columns * Fixed lint errors and cleaned the code * Modified combobox list to show only the graph columns that can be hidden * Refactoring: removed "getGraphColConfigModel" function * Fixed ids/keys prefix used for the columns combo Co-authored-by: Miggy Eusebio --- src/config.ts | 1 + src/webviews/apps/plus/graph/GraphWrapper.tsx | 95 +++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/config.ts b/src/config.ts index 35f8de1..00b6045 100644 --- a/src/config.ts +++ b/src/config.ts @@ -375,6 +375,7 @@ export interface AdvancedConfig { export interface GraphColumnConfig { width: number; + isHidden: boolean; } export interface GraphConfig { diff --git a/src/webviews/apps/plus/graph/GraphWrapper.tsx b/src/webviews/apps/plus/graph/GraphWrapper.tsx index b112c98..75f3877 100644 --- a/src/webviews/apps/plus/graph/GraphWrapper.tsx +++ b/src/webviews/apps/plus/graph/GraphWrapper.tsx @@ -64,11 +64,11 @@ const getStyleProps = ( }; const defaultGraphColumnsSettings: GKGraphColumnsSettings = { - commitAuthorZone: { width: 110 }, - commitDateTimeZone: { width: 130 }, - commitMessageZone: { width: 130 }, - commitZone: { width: 170 }, - refZone: { width: 150 }, + commitAuthorZone: { width: 110, isHidden: false }, + commitDateTimeZone: { width: 130, isHidden: false }, + commitMessageZone: { width: 130, isHidden: false }, + commitZone: { width: 170, isHidden: false }, + refZone: { width: 150, isHidden: false }, }; const getGraphColSettingsModel = (config?: GraphComponentConfig): GKGraphColumnsSettings => { @@ -77,6 +77,7 @@ const getGraphColSettingsModel = (config?: GraphComponentConfig): GKGraphColumns for (const column of Object.keys(config.columns)) { columnsSettings[column] = { width: config.columns[column].width, + isHidden: config.columns[column].isHidden, }; } } @@ -141,6 +142,33 @@ const getClientPlatform = (): GraphPlatform => { const clientPlatform = getClientPlatform(); +const graphColumns: {[Key in GraphZoneType]: {name: string; hideable: boolean}} = { + refZone: { + name: 'Branch / Tag', + hideable: false, + }, + commitZone: { + name: 'Graph', + hideable: false, + }, + commitMessageZone: { + name: 'Commit Message', + hideable: false, + }, + commitAuthorZone: { + name: 'Author', + hideable: true, + }, + commitDateTimeZone: { + name: 'Commit Date / Time', + hideable: true, + }, + commitShaZone: { + name: 'Sha', + hideable: true, + }, +}; + // eslint-disable-next-line @typescript-eslint/naming-convention export function GraphWrapper({ subscriber, @@ -193,6 +221,8 @@ export function GraphWrapper({ const [subscriptionSnapshot, setSubscriptionSnapshot] = useState(subscription); // repo selection UI const [repoExpanded, setRepoExpanded] = useState(false); + // column setting UI + const [columnSettingsExpanded, setColumnSettingsExpanded] = useState(false); useEffect(() => { if (mainRef.current === null) return; @@ -247,13 +277,29 @@ export function GraphWrapper({ onMissingAvatars?.(emails); }; + const handleSelectColumn = (graphZoneType: GraphZoneType) => { + onColumnChange?.(graphZoneType, { + ...graphColSettings[graphZoneType], + isHidden: !graphColSettings[graphZoneType]?.isHidden, + }); + }; + + const handleToggleColumnSettings = () => { + setColumnSettingsExpanded(!columnSettingsExpanded); + }; + const handleMoreCommits = () => { setIsLoading(true); onMoreCommits?.(); }; const handleOnColumnResized = (graphZoneType: GraphZoneType, columnSettings: GKGraphColumnSetting) => { - onColumnChange?.(graphZoneType, { width: columnSettings.width }); + if (columnSettings.width) { + onColumnChange?.(graphZoneType, { + width: columnSettings.width, + isHidden: columnSettings.isHidden, + }); + } }; const handleSelectGraphRows = (graphRows: GraphRow[]) => { @@ -535,6 +581,43 @@ export function GraphWrapper({ showing {graphRows.length} item{graphRows.length ? 's' : ''} )} +
+ +
+ { + Object.entries(graphColumns).map(([graphZoneType, column]) => column.hideable && ( + handleSelectColumn(graphZoneType as GraphZoneType)} + > + {column.name} {!graphColSettings[graphZoneType]?.isHidden && } + + )) + } +
+
{isLoading && (