Skip to content

Commit

Permalink
fix ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
molotgor committed Nov 27, 2024
1 parent 45911a9 commit dda7e05
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/components/JSONViewer/FileChoosing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const FileChoosing = ({
id: nanoid(),
parentIds: [],
key: filePath,
height: 22,
failed: false,
viewInstruction: '',
simpleFields: [],
Expand Down
22 changes: 13 additions & 9 deletions src/components/JSONViewer/TreeLeaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ const TreeLeaf = ({ treeNode, type }: { treeNode: TreeNode; type: PanelType }) =

useEffect(() => {
const observer = new ResizeObserver(entries => {
if (chunk)
JSONViewerStore.setChunkElement(
chunk,
treeNode.id,
entries[0].borderBoxSize?.length > 0
? entries[0].borderBoxSize[0].blockSize
: entries[0].contentRect.height,
type,
);
JSONViewerStore.setChunkElement(
chunk,
treeNode.id,
entries[0].borderBoxSize?.length > 0
? entries[0].borderBoxSize[0].blockSize
: entries[0].contentRect.height,
type,
);
});
if (leafRef.current) {
observer.observe(leafRef.current);
Expand All @@ -92,6 +91,11 @@ const TreeLeaf = ({ treeNode, type }: { treeNode: TreeNode; type: PanelType }) =
};
}, []);

useEffect(() => {
if (leafRef.current)
JSONViewerStore.setChunkElement(chunk, treeNode.id, leafRef.current.offsetHeight, type);
}, [leafRef.current]);

const toggleNode = () => {
if (open) {
setOpen(false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/JSONViewer/TreeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TreeList = ({ type }: { type: PanelType }) => {
dataNode.id,
)}`
: 'lastElement' in dataNode
? `${dataNode.chunk}-${dataNode.firstElement}-${dataNode.lastElement}`
? `${dataNode.chunk}-${dataNode.firstElement}-${dataNode.lastElement}-${dataNode.height}`
: dataNode.name
}`,
[],
Expand Down
37 changes: 20 additions & 17 deletions src/stores/JSONViewer/JSONViewerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export class JSONViewerStore {
() => this.openTreeNodes.default.values(),
() => {
this.initChunksData('default');
this.initChunksData('compare');
this.initChunksData('compare', false);
},
);

reaction(
() => this.openTreeNodes.compare.values(),
() => {
this.initChunksData('default');
this.initChunksData('default', false);
this.initChunksData('compare');
},
);
Expand Down Expand Up @@ -341,8 +341,8 @@ export class JSONViewerStore {
}
}

@action initChunksData(type: PanelType) {
this.clearChunksData(type);
@action initChunksData(type: PanelType, clear = true) {
if (clear) this.clearChunksData(type);
this.treeNodes[type]
.filter(node => node.parentIds.every(parentId => this.openTreeNodes[type].has(parentId)))
.forEach(node => {
Expand Down Expand Up @@ -497,10 +497,15 @@ export class JSONViewerStore {
)
.flatMap(node => [
...this.chunksHeights.default.filter(
chunkData => chunkData.lastElement === '' && chunkData.firstElement === node.id,
chunkData =>
chunkData.height > 0 &&
chunkData.lastElement === '' &&
chunkData.firstElement === node.id,
),
node,
...this.chunksHeights.default.filter(chunkData => chunkData.lastElement === node.id),
...this.chunksHeights.default.filter(
chunkData => chunkData.height > 0 && chunkData.lastElement === node.id,
),
]),
],
compare: [
Expand All @@ -511,10 +516,15 @@ export class JSONViewerStore {
)
.flatMap(node => [
...this.chunksHeights.compare.filter(
chunkData => chunkData.lastElement === '' && chunkData.firstElement === node.id,
chunkData =>
chunkData.height > 0 &&
chunkData.lastElement === '' &&
chunkData.firstElement === node.id,
),
node,
...this.chunksHeights.compare.filter(chunkData => chunkData.lastElement === node.id),
...this.chunksHeights.compare.filter(
chunkData => chunkData.height > 0 && chunkData.lastElement === node.id,
),
]),
],
};
Expand Down Expand Up @@ -569,15 +579,8 @@ export class JSONViewerStore {
);
for (let i = 0; i < newKeys.length; i++) {
const lastExisting =
sameKeys
.concat(exclusiveKeys)
.sort()
.findLast(key => key <= newKeys[i]) || '';
const firstExisting =
sameKeys
.concat(exclusiveKeys)
.sort()
.find(key => key >= newKeys[i]) || '';
[...keys1].reverse().find(key => Number(key) <= Number(newKeys[i])) || '';
const firstExisting = keys1.find(key => Number(key) >= Number(newKeys[i])) || '';
chunkFixed.push({
chunk: Number(newKeys[i]),
firstElement: chunks1[firstExisting]?.firstElement || '',
Expand Down

0 comments on commit dda7e05

Please sign in to comment.