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

=table should not be applied on context #2736

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Bullet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface BulletProps {
// debugIndex?: number
isCursorGrandparent?: boolean
isCursorParent?: boolean
isInContextView?: boolean
}

const isIOSSafari = isTouch && isiPhone && isSafari()
Expand Down Expand Up @@ -394,6 +395,7 @@ const Bullet = ({
thoughtId,
isCursorGrandparent,
isCursorParent,
isInContextView,
// depth,
// debugIndex,
}: BulletProps) => {
Expand Down Expand Up @@ -525,7 +527,7 @@ const Bullet = ({

// calculate position of bullet for different font sizes
// Table column 1 needs more space between the bullet and thought for some reason
const width = 11 - (fontSize - 9) * 0.5 + (isTableCol1 ? fontSize / 4 : 0)
const width = 11 - (fontSize - 9) * 0.5 + (!isInContextView && isTableCol1 ? fontSize / 4 : 0)
const marginLeft = -width

// expand or collapse on click
Expand Down
12 changes: 11 additions & 1 deletion src/components/Thought.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,16 @@ const ThoughtContainer = ({
attributeEquals(state, head(rootedParentOf(state, parentOf(simplePath))), '=view', 'Table'),
)

const hideBullet = useHideBullet({ children, env, hideBulletProp, isEditing, simplePath, thoughtId })
const isInContextView = useSelector(state => {
/** Check if the thought is in the context view. */
const checkContextView = (currentPath: Path): boolean => {
if (currentPath.length <= 1) return false
return isContextViewActive(state, currentPath) || checkContextView(parentOf(currentPath))
RED-ROSE515 marked this conversation as resolved.
Show resolved Hide resolved
}
return checkContextView(path)
})

const hideBullet = useHideBullet({ children, env, hideBulletProp, isEditing, simplePath, isInContextView, thoughtId })
const style = useThoughtStyle({ children, env, styleProp, thoughtId })
const styleAnnotation = useSelector(
state =>
Expand Down Expand Up @@ -436,6 +445,7 @@ const ThoughtContainer = ({
publish={publish}
simplePath={simplePath}
thoughtId={thoughtId}
isInContextView={isInContextView}
// debugIndex={debugIndex}
// depth={depth}
/>
Expand Down
35 changes: 35 additions & 0 deletions src/components/__tests__/Bullet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import userEvent from '@testing-library/user-event'
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import { toggleContextViewActionCreator as toggleContextView } from '../../actions/toggleContextView'
import { toggleHiddenThoughtsActionCreator as toggleHiddenThoughts } from '../../actions/toggleHiddenThoughts'
import { HOME_TOKEN } from '../../constants'
import contextToPath from '../../selectors/contextToPath'
import { exportContext } from '../../selectors/exportContext'
import store from '../../stores/app'
import createTestApp, { cleanupTestApp } from '../../test-helpers/createTestApp'
import dispatch from '../../test-helpers/dispatch'
import findCursor from '../../test-helpers/queries/findCursor'
import getBulletByContext from '../../test-helpers/queries/getBulletByContext'
import { setCursorFirstMatchActionCreator as setCursor } from '../../test-helpers/setCursorFirstMatch'
import hashPath from '../../util/hashPath'

beforeEach(createTestApp)
afterEach(cleanupTestApp)
Expand Down Expand Up @@ -155,6 +158,38 @@ describe('render', () => {
const bullets = document.querySelectorAll('[data-bullet="parent"]')
expect(bullets.length).toBe(1)
})

it('render bullets in context view entries even when parent has =view/Table', async () => {
RED-ROSE515 marked this conversation as resolved.
Show resolved Hide resolved
await dispatch([
importText({
text: `
- a
- a1
- m
- x
- b
- =view
- Table
- b1
- m
- y
`,
}),
])

await act(vi.runOnlyPendingTimersAsync)

// Set cursor to a/a1/m
await dispatch([setCursor(['a', 'a1', 'm'])])

// Activate context view
await dispatch([toggleContextView()])

await act(vi.runOnlyPendingTimersAsync)
const path = hashPath(contextToPath(store.getState(), ['a', 'a1', 'm', 'b1']))
const bullet = document.querySelector(`[data-testid="bullet-${path}"]`)
expect(bullet).toBeInTheDocument()
})
})

describe('expansion', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/hooks/useHideBullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ const useHideBullet = ({
hideBulletProp,
isEditing,
simplePath,
isInContextView,
thoughtId,
}: {
children: Thought[]
env: LazyEnv | undefined
hideBulletProp: boolean | undefined
isEditing: boolean
simplePath: SimplePath
isInContextView: boolean
thoughtId: ThoughtId
}) => {
const hideBullet = useSelector(state => {
Expand All @@ -42,9 +44,14 @@ const useHideBullet = ({
thought.value !== '=grandchildren' && attributeEquals(state, head(simplePath), '=bullet', 'None')

/** Returns true if the bullet should be hidden because it is in table column 1 and is not the cursor. */
const hideBulletTable = () =>
!equalPath(simplePath, state.cursor) &&
attributeEquals(state, head(rootedParentOf(state, simplePath)), '=view', 'Table')
const hideBulletTable = () => {
// Don't hide bullets in context view
if (isInContextView) return false
RED-ROSE515 marked this conversation as resolved.
Show resolved Hide resolved
return (
!equalPath(simplePath, state.cursor) &&
attributeEquals(state, head(rootedParentOf(state, simplePath)), '=view', 'Table')
)
}

/** Returns true if the bullet should be hidden if zoomed. */
const hideBulletZoom = (): boolean => {
Expand Down
Loading