Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only re-render divider on hover #199

Merged
merged 3 commits into from Jul 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/SchemaRow/SchemaRow.tsx
Expand Up @@ -8,6 +8,7 @@ import {
SchemaNodeKind,
} from '@stoplight/json-schema-tree';
import { Box, Flex, Icon, Select, SpaceVals, VStack } from '@stoplight/mosaic';
import { Atom } from 'jotai';
import { useAtomValue, useUpdateAtom } from 'jotai/utils';
import last from 'lodash/last.js';
import * as React from 'react';
Expand Down Expand Up @@ -39,7 +40,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples, renderRootTreeLines } = useJSVOptionsContext();

const setHoveredNode = useUpdateAtom(hoveredNodeAtom);
const isHovering = useAtomValue(isNodeHoveredAtom(schemaNode));

const [isExpanded, setExpanded] = React.useState<boolean>(
!isMirroredNode(schemaNode) && nestingLevel <= defaultExpandedDepth,
Expand Down Expand Up @@ -156,7 +156,7 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
)}
</Flex>

{hasProperties && <Box bg={isHovering ? 'canvas-200' : undefined} h="px" flex={1} mx={3} />}
{hasProperties && <Divider atom={isNodeHoveredAtom(schemaNode)} />}

<Properties required={required} deprecated={deprecated} validations={validations} />
</Flex>
Expand Down Expand Up @@ -188,6 +188,12 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
);
});

const Divider = ({ atom }: { atom: Atom<boolean> }) => {
const isHovering = useAtomValue(atom);

return <Box bg={isHovering ? 'canvas-200' : undefined} h="px" flex={1} mx={3} />;
};

function shouldShowPropertyName(schemaNode: SchemaNode) {
return (
schemaNode.subpath.length === 2 &&
Expand Down