Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion client/src/components/CodeBlock/CodeFull/CodeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const CodeContainer = ({
)
.then((data) => {
setTokenInfo({
data: mapTokenInfo(data.data),
data: mapTokenInfo(data.data, relativePath),
hoverableRange,
tokenRange,
lineNumber,
Expand Down
2 changes: 2 additions & 0 deletions client/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import CloudApp from './CloudApp';
import polyfills from './utils/polyfills';
polyfills();

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
Expand Down
15 changes: 10 additions & 5 deletions client/src/mappers/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export const mapFileResult = (fileItem: FileItem) => {
};
};

export const mapTokenInfo = (tokenInfo: TokenInfoResponse['data']) => {
export const mapTokenInfo = (
tokenInfo: TokenInfoResponse['data'],
path: string,
) => {
const map: {
references: Record<string, any>;
definitions: Record<string, any>;
Expand Down Expand Up @@ -198,10 +201,12 @@ export const mapTokenInfo = (tokenInfo: TokenInfoResponse['data']) => {
});

const arrayFromObject = (obj: Record<string, any>) =>
Object.entries(obj).map(([file, data]) => ({
file,
data,
}));
Object.entries(obj)
.map(([file, data]) => ({
file,
data,
}))
.sort((a, b) => (a.file === path ? -1 : b.file === path ? 1 : 0));

return {
references: arrayFromObject(map.references),
Expand Down
16 changes: 16 additions & 0 deletions client/src/utils/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function polyfillFindLastIndex() {
if (!Array.prototype.findLastIndex) {
Array.prototype.findLastIndex = function (callback, thisArg) {
for (let i = this.length - 1; i >= 0; i--) {
if (callback.call(thisArg, this[i], i, this)) return i;
}
return -1;
};
}
}

const enablePolyfills = () => {
polyfillFindLastIndex();
};

export default enablePolyfills;