Skip to content

Commit

Permalink
fix: expand/collapse of k8s resource section
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Nov 11, 2021
1 parent 8da5665 commit 767c408
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
8 changes: 7 additions & 1 deletion src/components/molecules/SectionRenderer/SectionHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {useState} from 'react';
import {MinusSquareOutlined} from '@ant-design/icons';

import {SectionCustomComponent, SectionInstance} from '@models/navigator';

import {MinusSquareOutlined} from '@ant-design/icons';

import * as S from './styled';

interface SectionHeaderProps {
Expand All @@ -19,6 +22,7 @@ interface SectionHeaderProps {
expandSection: () => void;
collapseSection: () => void;
CustomNameDisplay?: SectionCustomComponent;
CustomNameSuffix?: SectionCustomComponent;
disableHoverStyle: boolean;
}

Expand All @@ -39,6 +43,7 @@ function SectionHeader(props: SectionHeaderProps) {
expandSection,
collapseSection,
CustomNameDisplay,
CustomNameSuffix,
disableHoverStyle,
} = props;
const [isHovered, setIsHovered] = useState<boolean>(false);
Expand Down Expand Up @@ -68,6 +73,7 @@ function SectionHeader(props: SectionHeaderProps) {
>
{name}
{itemsLength > 0 && <S.ItemsLength>{itemsLength}</S.ItemsLength>}
{CustomNameSuffix && <CustomNameSuffix sectionInstance={sectionInstance} />}
</S.Name>
{isHovered && isSectionInitialized && (
<S.Collapsible>
Expand Down
3 changes: 2 additions & 1 deletion src/components/molecules/SectionRenderer/SectionRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SectionRenderer<ItemType, ScopeType>(props: SectionRendererProps<ItemTy

const dispatch = useAppDispatch();

const {NameDisplay, EmptyDisplay} = useSectionCustomization(sectionBlueprint.customization);
const {NameDisplay, EmptyDisplay, NameSuffix} = useSectionCustomization(sectionBlueprint.customization);

const collapsedSectionIds = useAppSelector(state => state.navigator.collapsedSectionIds);

Expand Down Expand Up @@ -175,6 +175,7 @@ function SectionRenderer<ItemType, ScopeType>(props: SectionRendererProps<ItemTy
expandSection={expandSection}
collapseSection={collapseSection}
CustomNameDisplay={NameDisplay ? NameDisplay.Component : undefined}
CustomNameSuffix={NameSuffix ? NameSuffix.Component : undefined}
disableHoverStyle={Boolean(sectionBlueprint.customization?.disableHoverStyle)}
/>
{sectionInstance &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {SectionCustomization} from '@models/navigator';

export function useSectionCustomization(customization: SectionCustomization = {}) {
const NameDisplay = useMemo(() => ({Component: customization.nameDisplay?.component}), [customization.nameDisplay]);
const NameSuffix = useMemo(() => ({Component: customization.nameSuffix?.component}), [customization.nameSuffix]);
const EmptyDisplay = useMemo(
() => ({Component: customization.emptyDisplay?.component}),
[customization.emptyDisplay]
);

return {NameDisplay, EmptyDisplay};
return {NameDisplay, EmptyDisplay, NameSuffix};
}
3 changes: 3 additions & 0 deletions src/models/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export interface SectionCustomization {
nameDisplay?: {
component: SectionCustomComponent;
};
nameSuffix?: {
component: SectionCustomComponent;
};
emptyDisplay?: {
component: SectionCustomComponent;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ResourceKindHandlers} from '@src/kindhandlers';
import sectionBlueprintMap from '@src/navsections/sectionBlueprintMap';

import K8sResourceSectionEmptyDisplay from './K8sResourceSectionEmptyDisplay';
import K8sResourceSectionNameDisplay from './K8sResourceSectionNameDisplay';
import K8sResourceSectionNameSuffix from './K8sResourceSectionNameSuffix';
import {makeResourceKindNavSection} from './ResourceKindSectionBlueprint';

const childSectionNames = navSectionNames.representation[navSectionNames.K8S_RESOURCES];
Expand Down Expand Up @@ -98,8 +98,8 @@ const K8sResourceSectionBlueprint: SectionBlueprint<K8sResource, K8sResourceScop
emptyDisplay: {
component: K8sResourceSectionEmptyDisplay,
},
nameDisplay: {
component: K8sResourceSectionNameDisplay,
nameSuffix: {
component: K8sResourceSectionNameSuffix,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ import {isInPreviewModeSelector} from '@redux/selectors';
import Colors, {BackgroundColors} from '@styles/Colors';

const S = {
Container: styled.div`
Container: styled.span`
display: flex;
align-items: center;
`,
TitleSpan: styled.span`
padding: 2px 16px;
font-size: 24px;
`,
PreviewOutputTag: styled(Tag)`
font-size: 12px;
font-weight: 600;
background: ${BackgroundColors.previewModeBackground};
color: ${Colors.blackPure};
margin-top: 3px;
margin-bottom: 10px;
`,
};

function K8sResourceSectionNameDisplay() {
function K8sResourceSectionNameSuffix() {
const isInPreviewMode = useAppSelector(isInPreviewModeSelector);

return (
<S.Container>
<S.TitleSpan>K8s Resources</S.TitleSpan>
{isInPreviewMode && <S.PreviewOutputTag>Preview Output</S.PreviewOutputTag>}
</S.Container>
);
if (isInPreviewMode) {
return (
<S.Container>
<S.PreviewOutputTag>Preview Output</S.PreviewOutputTag>
</S.Container>
);
}

return null;
}

export default K8sResourceSectionNameDisplay;
export default K8sResourceSectionNameSuffix;

0 comments on commit 767c408

Please sign in to comment.