diff --git a/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx
new file mode 100644
index 0000000000..b2c027e499
--- /dev/null
+++ b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx
@@ -0,0 +1,36 @@
+import HistoryFileTreeItem from './history-file-tree-item'
+import iconTypeFromName from '../../../file-tree/util/icon-type-from-name'
+import Icon from '../../../../shared/components/icon'
+import { useSelectableEntity } from '../../context/history-file-tree-selectable'
+
+type HistoryFileTreeDocProps = {
+ name: string
+ id: string
+}
+
+export default function HistoryFileTreeDoc({
+ name,
+ id,
+}: HistoryFileTreeDocProps) {
+ const { props: selectableEntityProps } = useSelectableEntity(id)
+
+ return (
+
{}}
- refProviders={{}}
- reindexReferences={() => {}}
- setRefProviderEnabled={() => {}}
- setStartedFreeTrial={() => {}}
- />,
- fileTreeContainer
- )
+ ? createPortal(, fileTreeContainer)
: null}
diff --git a/services/web/frontend/js/features/history/context/history-file-tree-selectable.tsx b/services/web/frontend/js/features/history/context/history-file-tree-selectable.tsx
new file mode 100644
index 0000000000..a4dd5ad555
--- /dev/null
+++ b/services/web/frontend/js/features/history/context/history-file-tree-selectable.tsx
@@ -0,0 +1,87 @@
+import {
+ createContext,
+ type ReactNode,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react'
+import classNames from 'classnames'
+import _ from 'lodash'
+
+import usePreviousValue from '../../../shared/hooks/use-previous-value'
+import { Nullable } from '../../../../../types/utils'
+
+type Context = {
+ select: (id: string) => void
+ selectedFile: Nullable
+}
+
+const FileTreeSelectableContext = createContext({
+ select: () => {},
+ selectedFile: null,
+})
+
+type HistoryFileTreeSelectableProviderProps = {
+ onSelectFile: (id: string) => void
+ children: ReactNode
+}
+
+export function HistoryFileTreeSelectableProvider({
+ onSelectFile,
+ children,
+}: HistoryFileTreeSelectableProviderProps) {
+ const [selectedFile, setSelectedFile] =
+ useState(null)
+
+ const previousSelectedFile = usePreviousValue(selectedFile)
+
+ useEffect(() => {
+ if (!selectedFile) {
+ return
+ }
+
+ if (_.isEqual(selectedFile, previousSelectedFile)) {
+ return
+ }
+
+ onSelectFile(selectedFile)
+ }, [selectedFile, previousSelectedFile, onSelectFile])
+
+ const select = useCallback(id => {
+ setSelectedFile(id)
+ }, [])
+
+ const value = {
+ selectedFile,
+ select,
+ }
+
+ return (
+
+ {children}
+
+ )
+}
+
+export function useSelectableEntity(id: string) {
+ const { selectedFile, select } = useContext(FileTreeSelectableContext)
+
+ const handleClick = useCallback(() => {
+ select(id)
+ }, [id, select])
+
+ const isSelected = selectedFile === id
+
+ const props = useMemo(
+ () => ({
+ className: classNames({ selected: isSelected }),
+ 'aria-selected': isSelected,
+ onClick: handleClick,
+ }),
+ [handleClick, isSelected]
+ )
+
+ return { isSelected, props }
+}
diff --git a/services/web/frontend/js/features/history/controllers/history-file-tree-controller.js b/services/web/frontend/js/features/history/controllers/history-file-tree-controller.js
index 2775e66e8d..36c72a22f4 100644
--- a/services/web/frontend/js/features/history/controllers/history-file-tree-controller.js
+++ b/services/web/frontend/js/features/history/controllers/history-file-tree-controller.js
@@ -5,11 +5,5 @@ import HistoryFileTree from '../components/history-file-tree'
App.component(
'historyFileTreeReact',
- react2angular(rootContext.use(HistoryFileTree), [
- 'refProviders',
- 'setRefProviderEnabled',
- 'setStartedFreeTrial',
- 'reindexReferences',
- 'onSelect',
- ])
+ react2angular(rootContext.use(HistoryFileTree))
)
diff --git a/services/web/frontend/js/features/history/utils/file-tree.ts b/services/web/frontend/js/features/history/utils/file-tree.ts
index bea2596228..ff125534df 100644
--- a/services/web/frontend/js/features/history/utils/file-tree.ts
+++ b/services/web/frontend/js/features/history/utils/file-tree.ts
@@ -48,14 +48,11 @@ export function reducePathsToTree(
return currentFileTree
}
-type HistoryFileTree = {
+export type HistoryFileTree = {
docs?: Doc[]
folders: HistoryFileTree[]
name: string
- // `id` and `fileRefs` are both required from react file tree.
- // TODO: update react file tree to make the data optional so we can delete these keys
- id: ''
- fileRefs: []
+ _id: string
}
export function fileTreeDiffToFileTreeData(
@@ -68,7 +65,7 @@ export function fileTreeDiffToFileTreeData(
for (const file of fileTreeDiff) {
if (file.type === 'file') {
docs.push({
- _id: '',
+ _id: file.pathname as string,
name: file.name ?? '',
})
} else if (file.type === 'folder') {
@@ -83,8 +80,7 @@ export function fileTreeDiffToFileTreeData(
docs,
folders,
name: currentFolderName,
- id: '',
- fileRefs: [],
+ _id: currentFolderName,
}
}