From 79587a299b68718c09a23d4fba52d10e77f748fe Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:07:56 +0200 Subject: [PATCH 1/6] feat: add Chart.yaml as item of helm chart section --- .../HelmChartSectionBlueprint.ts | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts index 06e56099d3..6661bf2f9a 100644 --- a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts +++ b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts @@ -1,10 +1,10 @@ import {HELM_CHART_SECTION_NAME, ROOT_FILE_ENTRY} from '@constants/constants'; -import {HelmValuesMapType} from '@models/appstate'; +import {HelmChartMapType, HelmValuesMapType} from '@models/appstate'; import {HelmChart, HelmValuesFile} from '@models/helm'; import {SectionBlueprint} from '@models/navigator'; -import {selectHelmValuesFile} from '@redux/reducers/main'; +import {selectFile, selectHelmValuesFile} from '@redux/reducers/main'; import sectionBlueprintMap from '../sectionBlueprintMap'; import HelmChartQuickAction from './HelmChartQuickAction'; @@ -16,6 +16,13 @@ export type ValuesFilesScopeType = { isFolderOpen: boolean; }; +type HelmChartScopeType = { + helmChartMap: HelmChartMapType; + selectedPath: string | undefined; + previewValuesFileId: string | undefined; + isInClusterMode: boolean; +}; + export function makeHelmChartSectionBlueprint(helmChart: HelmChart) { const valuesFilesSectionBlueprint: SectionBlueprint = { name: 'Values Files', @@ -73,14 +80,51 @@ export function makeHelmChartSectionBlueprint(helmChart: HelmChart) { }, }; - const helmChartSectionBlueprint: SectionBlueprint = { + const helmChartSectionBlueprint: SectionBlueprint = { name: helmChart.name, id: helmChart.id, containerElementId: 'helm-sections-container', rootSectionId: HELM_CHART_SECTION_NAME, childSectionIds: [valuesFilesSectionBlueprint.id], - getScope: () => { - return {}; + getScope: state => { + const kubeConfigPath = state.config.projectConfig?.kubeConfig?.path || state.config.kubeConfig.path; + return { + helmChartMap: state.main.helmChartMap, + isInClusterMode: kubeConfigPath + ? Boolean(state.main.previewResourceId && state.main.previewResourceId.endsWith(kubeConfigPath)) + : false, + previewValuesFileId: state.main.previewValuesFileId, + selectedPath: state.main.selectedPath, + }; + }, + builder: { + getRawItems: scope => { + const chart: HelmChart | undefined = scope.helmChartMap[helmChart.id]; + return chart ? [chart] : []; + }, + }, + itemBlueprint: { + getName: () => 'Chart.yaml', + getInstanceId: chart => chart.id, + builder: { + getMeta: chart => ({ + filePath: chart.filePath, + }), + isSelected: (chart, scope) => { + return scope.selectedPath === chart.filePath; + }, + isDisabled: (rawItem, scope) => + Boolean((scope.previewValuesFileId && scope.previewValuesFileId !== rawItem.id) || scope.isInClusterMode), + }, + instanceHandler: { + onClick: (instance, dispatch) => { + const filePath: string | undefined = instance.meta?.filePath; + if (!filePath) { + return; + } + dispatch(selectFile({filePath})); + }, + }, }, customization: { counterDisplayMode: 'none', From 14737031e4c48538fbb43b83ad41d19fcb090fed Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:24:13 +0200 Subject: [PATCH 2/6] feat: option for indenting sections --- .../ItemRenderer/ItemRenderer.tsx | 5 +++- .../SectionRenderer/ItemRenderer/styled.tsx | 6 ++++- .../SectionRenderer/SectionHeader.tsx | 15 ++++++++++-- .../SectionRenderer/SectionRenderer.tsx | 24 ++++++++++++++++++- .../molecules/SectionRenderer/styled.tsx | 6 ++++- src/models/navigator.ts | 2 ++ 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/components/molecules/SectionRenderer/ItemRenderer/ItemRenderer.tsx b/src/components/molecules/SectionRenderer/ItemRenderer/ItemRenderer.tsx index c9f979612c..211acbcffb 100644 --- a/src/components/molecules/SectionRenderer/ItemRenderer/ItemRenderer.tsx +++ b/src/components/molecules/SectionRenderer/ItemRenderer/ItemRenderer.tsx @@ -24,11 +24,13 @@ export type ItemRendererProps = { isLastItem: boolean; isSectionCheckable: boolean; sectionContainerElementId: string; + indentation: number; options?: ItemRendererOptions; }; function ItemRenderer(props: ItemRendererProps) { - const {itemId, blueprint, level, isLastItem, isSectionCheckable, sectionContainerElementId, options} = props; + const {itemId, blueprint, level, isLastItem, isSectionCheckable, sectionContainerElementId, indentation, options} = + props; const {instanceHandler} = blueprint; const dispatch = useAppDispatch(); @@ -80,6 +82,7 @@ function ItemRenderer(props: ItemRendererProps diff --git a/src/components/molecules/SectionRenderer/ItemRenderer/styled.tsx b/src/components/molecules/SectionRenderer/ItemRenderer/styled.tsx index 758f3918e1..3027de8798 100644 --- a/src/components/molecules/SectionRenderer/ItemRenderer/styled.tsx +++ b/src/components/molecules/SectionRenderer/ItemRenderer/styled.tsx @@ -12,6 +12,7 @@ type ItemContainerProps = { level: number; isLastItem: boolean; hasOnClick: boolean; + $indentation: number; $isSectionCheckable: boolean; $hasCustomNameDisplay: boolean; }; @@ -21,7 +22,10 @@ export const ItemContainer = styled.span` align-items: center; width: 100%; user-select: none; - padding-left: ${props => (props.$isSectionCheckable ? '32px;' : '26px;')} + ${props => { + const defaultIndentation = props.$isSectionCheckable ? 32 : 26; + return `padding-left: ${defaultIndentation + props.$indentation}px;`; + }} padding-right: 8px; margin-bottom: 2px; ${props => props.hasOnClick && `cursor: pointer;`} diff --git a/src/components/molecules/SectionRenderer/SectionHeader.tsx b/src/components/molecules/SectionRenderer/SectionHeader.tsx index 25075b71c4..38fa87bb93 100644 --- a/src/components/molecules/SectionRenderer/SectionHeader.tsx +++ b/src/components/molecules/SectionRenderer/SectionHeader.tsx @@ -15,13 +15,23 @@ interface SectionHeaderProps { isCollapsed: boolean; isLastSection: boolean; level: number; + indentation: number; expandSection: () => void; collapseSection: () => void; } function SectionHeader(props: SectionHeaderProps) { - const {name, sectionInstance, sectionBlueprint, isCollapsed, isLastSection, level, expandSection, collapseSection} = - props; + const { + name, + sectionInstance, + sectionBlueprint, + isCollapsed, + isLastSection, + level, + indentation, + expandSection, + collapseSection, + } = props; const dispatch = useAppDispatch(); const [isHovered, setIsHovered] = useState(false); @@ -82,6 +92,7 @@ function SectionHeader(props: SectionHeaderProps) { isHovered={isHovered} isCheckable={Boolean(sectionBlueprint.builder?.makeCheckable)} $hasCustomNameDisplay={Boolean(NameDisplay.Component)} + $indentation={indentation} > {sectionInstance.checkable && sectionInstance.isInitialized && diff --git a/src/components/molecules/SectionRenderer/SectionRenderer.tsx b/src/components/molecules/SectionRenderer/SectionRenderer.tsx index 81d10b93e2..d369dc9d25 100644 --- a/src/components/molecules/SectionRenderer/SectionRenderer.tsx +++ b/src/components/molecules/SectionRenderer/SectionRenderer.tsx @@ -17,11 +17,12 @@ type SectionRendererProps = { sectionBlueprint: SectionBlueprint; level: number; isLastSection: boolean; + parentIndentation?: number; itemRendererOptions?: ItemRendererOptions; }; function SectionRenderer(props: SectionRendererProps) { - const {sectionBlueprint, level, isLastSection, itemRendererOptions} = props; + const {sectionBlueprint, level, isLastSection, itemRendererOptions, parentIndentation} = props; const {itemBlueprint, name: sectionName, id: sectionId} = sectionBlueprint; @@ -46,6 +47,23 @@ function SectionRenderer(props: SectionRendererProps) { const collapsedSectionIds = useAppSelector(state => state.navigator.collapsedSectionIds); + const sectionIndentation = useMemo(() => { + const indentation = sectionBlueprint.customization?.indentation; + if (!parentIndentation && !indentation) { + return undefined; + } + if (parentIndentation && !indentation) { + return parentIndentation; + } + if (!parentIndentation && indentation) { + return indentation; + } + if (parentIndentation && indentation) { + return parentIndentation + indentation; + } + return undefined; + }, [parentIndentation, sectionBlueprint.customization?.indentation]); + const isCollapsedMode = useMemo(() => { if (!sectionInstance?.id) { return 'expanded'; @@ -188,6 +206,7 @@ function SectionRenderer(props: SectionRendererProps) { level={level} expandSection={expandSection} collapseSection={collapseSection} + indentation={sectionIndentation || 0} /> {sectionInstance && sectionInstance.isVisible && @@ -204,6 +223,7 @@ function SectionRenderer(props: SectionRendererProps) { isSectionCheckable={Boolean(sectionInstance.checkable)} sectionContainerElementId={sectionBlueprint.containerElementId} options={itemRendererOptions} + indentation={sectionIndentation || 0} /> ))} {sectionInstance?.isVisible && @@ -231,6 +251,7 @@ function SectionRenderer(props: SectionRendererProps) { isSectionCheckable={Boolean(sectionInstance.checkable)} sectionContainerElementId={sectionBlueprint.containerElementId} options={itemRendererOptions} + indentation={sectionIndentation || 0} /> )) ) : ( @@ -248,6 +269,7 @@ function SectionRenderer(props: SectionRendererProps) { sectionBlueprint={child} level={level + 1} isLastSection={child.id === lastVisibleChildSectionId} + parentIndentation={sectionIndentation} /> ))} diff --git a/src/components/molecules/SectionRenderer/styled.tsx b/src/components/molecules/SectionRenderer/styled.tsx index 457a5baf1c..72a8927b8b 100644 --- a/src/components/molecules/SectionRenderer/styled.tsx +++ b/src/components/molecules/SectionRenderer/styled.tsx @@ -8,6 +8,7 @@ type NameContainerProps = { isHovered?: boolean; isCheckable?: boolean; $hasCustomNameDisplay: boolean; + $indentation: number; }; type SectionContainerProps = { @@ -28,7 +29,10 @@ export const NameContainer = styled.span` display: flex; align-items: center; width: 100%; - ${props => props.isCheckable && `padding-left: 24px;`} + ${props => { + const defaultIndentation = props.isCheckable ? 24 : 0; + return `padding-left: ${defaultIndentation + props.$indentation}px;`; + }} ${props => !props.isHovered && 'padding-right: 30px;'} ${props => props.$hasCustomNameDisplay && 'padding: 0;'} `; diff --git a/src/models/navigator.ts b/src/models/navigator.ts index 013970de5d..5bfa4f7b5d 100644 --- a/src/models/navigator.ts +++ b/src/models/navigator.ts @@ -65,6 +65,8 @@ export interface SectionCustomization { }; /** If no value is provided, default value will be "descendants" */ counterDisplayMode?: 'descendants' | 'items' | 'subsections' | 'none'; + /** Number of pixels to indent this section, by default all sections/susections are aligned */ + indentation?: number; emptyGroupText?: string; disableHoverStyle?: boolean; beforeInitializationText?: string; From b83ff9197ece43eca8aa3ca9801f9d4cbfb25797 Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:28:10 +0200 Subject: [PATCH 3/6] chore: add indentation to helm chart sections --- .../HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts index 6661bf2f9a..31957372fa 100644 --- a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts +++ b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts @@ -55,6 +55,7 @@ export function makeHelmChartSectionBlueprint(helmChart: HelmChart) { }, customization: { counterDisplayMode: 'items', + indentation: 8, }, itemBlueprint: { getName: rawItem => rawItem.name, @@ -128,6 +129,7 @@ export function makeHelmChartSectionBlueprint(helmChart: HelmChart) { }, customization: { counterDisplayMode: 'none', + indentation: 8, }, }; From 159a0d1c5981427bad3060f00b6a6e80b312c7ee Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:31:02 +0200 Subject: [PATCH 4/6] feat: option for custom section name color --- src/components/molecules/SectionRenderer/SectionHeader.tsx | 1 + src/components/molecules/SectionRenderer/styled.tsx | 6 ++++-- src/models/navigator.ts | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/molecules/SectionRenderer/SectionHeader.tsx b/src/components/molecules/SectionRenderer/SectionHeader.tsx index 38fa87bb93..35e1844fa0 100644 --- a/src/components/molecules/SectionRenderer/SectionHeader.tsx +++ b/src/components/molecules/SectionRenderer/SectionHeader.tsx @@ -91,6 +91,7 @@ function SectionHeader(props: SectionHeaderProps) { diff --git a/src/components/molecules/SectionRenderer/styled.tsx b/src/components/molecules/SectionRenderer/styled.tsx index 72a8927b8b..cce2fe5603 100644 --- a/src/components/molecules/SectionRenderer/styled.tsx +++ b/src/components/molecules/SectionRenderer/styled.tsx @@ -5,10 +5,11 @@ import styled from 'styled-components'; import Colors, {FontColors} from '@styles/Colors'; type NameContainerProps = { - isHovered?: boolean; - isCheckable?: boolean; $hasCustomNameDisplay: boolean; $indentation: number; + isHovered?: boolean; + isCheckable?: boolean; + $nameColor?: string; }; type SectionContainerProps = { @@ -35,6 +36,7 @@ export const NameContainer = styled.span` }} ${props => !props.isHovered && 'padding-right: 30px;'} ${props => props.$hasCustomNameDisplay && 'padding: 0;'} + ${props => props.$nameColor && `color: ${props.$nameColor};`} `; export const SectionContainer = styled.li` diff --git a/src/models/navigator.ts b/src/models/navigator.ts index 5bfa4f7b5d..4c066c2849 100644 --- a/src/models/navigator.ts +++ b/src/models/navigator.ts @@ -67,6 +67,7 @@ export interface SectionCustomization { counterDisplayMode?: 'descendants' | 'items' | 'subsections' | 'none'; /** Number of pixels to indent this section, by default all sections/susections are aligned */ indentation?: number; + nameColor?: string; emptyGroupText?: string; disableHoverStyle?: boolean; beforeInitializationText?: string; From c12345575904e73c25d01066be0cf5f50d4b9110 Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:39:53 +0200 Subject: [PATCH 5/6] refactor: fix nameColor + set color for helm chart --- src/components/molecules/SectionRenderer/SectionHeader.tsx | 2 +- src/components/molecules/SectionRenderer/SectionRenderer.tsx | 2 +- src/components/molecules/SectionRenderer/styled.tsx | 5 ++--- .../HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts | 3 +++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/molecules/SectionRenderer/SectionHeader.tsx b/src/components/molecules/SectionRenderer/SectionHeader.tsx index 35e1844fa0..1fa18fac35 100644 --- a/src/components/molecules/SectionRenderer/SectionHeader.tsx +++ b/src/components/molecules/SectionRenderer/SectionHeader.tsx @@ -91,7 +91,6 @@ function SectionHeader(props: SectionHeaderProps) { @@ -119,6 +118,7 @@ function SectionHeader(props: SectionHeaderProps) { $isSelected={sectionInstance.isSelected && isCollapsed} $isHighlighted={sectionInstance.isSelected && isCollapsed} $isCheckable={Boolean(sectionInstance.checkable)} + $nameColor={sectionBlueprint.customization?.nameColor} $level={level} onClick={toggleCollapse} > diff --git a/src/components/molecules/SectionRenderer/SectionRenderer.tsx b/src/components/molecules/SectionRenderer/SectionRenderer.tsx index d369dc9d25..8dab493eb9 100644 --- a/src/components/molecules/SectionRenderer/SectionRenderer.tsx +++ b/src/components/molecules/SectionRenderer/SectionRenderer.tsx @@ -219,7 +219,7 @@ function SectionRenderer(props: SectionRendererProps) { itemId={itemId} blueprint={itemBlueprint} level={level + 1} - isLastItem={isLastVisibleItemId(itemId)} + isLastItem={isLastVisibleItemId(itemId) && !childSectionIds} isSectionCheckable={Boolean(sectionInstance.checkable)} sectionContainerElementId={sectionBlueprint.containerElementId} options={itemRendererOptions} diff --git a/src/components/molecules/SectionRenderer/styled.tsx b/src/components/molecules/SectionRenderer/styled.tsx index cce2fe5603..2abac6db28 100644 --- a/src/components/molecules/SectionRenderer/styled.tsx +++ b/src/components/molecules/SectionRenderer/styled.tsx @@ -9,7 +9,6 @@ type NameContainerProps = { $indentation: number; isHovered?: boolean; isCheckable?: boolean; - $nameColor?: string; }; type SectionContainerProps = { @@ -36,7 +35,6 @@ export const NameContainer = styled.span` }} ${props => !props.isHovered && 'padding-right: 30px;'} ${props => props.$hasCustomNameDisplay && 'padding: 0;'} - ${props => props.$nameColor && `color: ${props.$nameColor};`} `; export const SectionContainer = styled.li` @@ -86,6 +84,7 @@ type NameProps = { $isHighlighted?: boolean; $isCheckable?: boolean; $level: number; + $nameColor?: string; }; export const Name = styled.span` @@ -110,7 +109,7 @@ export const Name = styled.span` if (props.$isSelected) { return `color: ${Colors.blackPure};`; } - return `color: ${Colors.whitePure};`; + return props.$nameColor ? `color: ${props.$nameColor}` : `color: ${Colors.whitePure};`; }} `; diff --git a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts index 31957372fa..6c4bce2122 100644 --- a/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts +++ b/src/navsections/HelmChartSectionBlueprint/HelmChartSectionBlueprint.ts @@ -6,6 +6,8 @@ import {SectionBlueprint} from '@models/navigator'; import {selectFile, selectHelmValuesFile} from '@redux/reducers/main'; +import Colors from '@styles/Colors'; + import sectionBlueprintMap from '../sectionBlueprintMap'; import HelmChartQuickAction from './HelmChartQuickAction'; @@ -56,6 +58,7 @@ export function makeHelmChartSectionBlueprint(helmChart: HelmChart) { customization: { counterDisplayMode: 'items', indentation: 8, + nameColor: Colors.grey400, }, itemBlueprint: { getName: rawItem => rawItem.name, From abafe4c474eea93adece436a6958be7a873ba2b7 Mon Sep 17 00:00:00 2001 From: Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:41:59 +0200 Subject: [PATCH 6/6] fix: left menu icon selection state --- src/components/organisms/PaneManager/MenuButton.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/components/organisms/PaneManager/MenuButton.tsx b/src/components/organisms/PaneManager/MenuButton.tsx index 43a6af0e38..2b35c01dfe 100644 --- a/src/components/organisms/PaneManager/MenuButton.tsx +++ b/src/components/organisms/PaneManager/MenuButton.tsx @@ -55,10 +55,6 @@ const MenuButton: React.FC = props => { shallowEqual ); - const isAnyHelmValuesFileSelected = useMemo(() => { - return Object.values(helmValuesMap).some(v => v.isSelected); - }, [helmValuesMap]); - const isAnySectionSelected = useMemo(() => { if (!sectionInstanceByName) { return false; @@ -69,11 +65,8 @@ const MenuButton: React.FC = props => { const style: React.CSSProperties = {}; const hasGradientBackground = useMemo(() => { - return Boolean( - (isAnySectionSelected || (shouldWatchSelectedPath && selectedPath && !isAnyHelmValuesFileSelected)) && - (!isSelected || !isActive) - ); - }, [isAnySectionSelected, shouldWatchSelectedPath, selectedPath, isAnyHelmValuesFileSelected, isSelected, isActive]); + return Boolean((isAnySectionSelected || (shouldWatchSelectedPath && selectedPath)) && (!isSelected || !isActive)); + }, [isAnySectionSelected, shouldWatchSelectedPath, selectedPath, isSelected, isActive]); if (hasGradientBackground) { if (isHovered) {