forked from voxel51/fiftyone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove unused jsonview file * remove dep on searchable-json-view and bring in new json viewer * add new json viewer with highlighting * handle esc to clear search term and close json view * linting --------- Co-authored-by: Benjamin Kane <ben@voxel51.com>
- Loading branch information
1 parent
deaf08c
commit de5b773
Showing
9 changed files
with
196 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
app/packages/components/src/components/JSONPanel/highlight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { DataItemProps, defineEasyType } from "@textea/json-viewer"; | ||
import React, { useMemo } from "react"; | ||
|
||
const HighlightedText = ({ | ||
text, | ||
searchTerm, | ||
}: { | ||
text: string | number; | ||
searchTerm: string; | ||
}) => { | ||
const parts = useMemo( | ||
() => String(text ?? "").split(searchTerm), | ||
[text, searchTerm] | ||
); | ||
|
||
if (!String(text).includes(searchTerm)) { | ||
return <>{text}</>; | ||
} | ||
|
||
return ( | ||
<> | ||
{parts.map((part, index) => ( | ||
<React.Fragment key={index}> | ||
{part} | ||
{index !== parts.length - 1 && ( | ||
<span style={{ backgroundColor: "yellow", color: "black" }}> | ||
{searchTerm} | ||
</span> | ||
)} | ||
</React.Fragment> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export const KeyRenderer = (props: DataItemProps & { searchTerm: string }) => { | ||
const { searchTerm, path } = props; | ||
const leafPath = String(path.at(-1)); | ||
|
||
if (leafPath?.includes(searchTerm)) { | ||
return <HighlightedText text={leafPath} searchTerm={searchTerm} />; | ||
} | ||
|
||
return <>{leafPath}</>; | ||
}; | ||
|
||
export const KeyRendererWrapper = (searchTerm: string) => { | ||
const wrapper = (props: DataItemProps) => { | ||
return <KeyRenderer searchTerm={searchTerm} {...props} />; | ||
}; | ||
|
||
// show all keys (required in runtime by json-viewer) | ||
wrapper.when = () => true; | ||
return wrapper; | ||
}; | ||
|
||
const getHighlightedComponentString = (searchTerm: string) => | ||
defineEasyType({ | ||
is: (value) => { | ||
if (searchTerm?.length === 0 || typeof value !== "string") { | ||
return false; | ||
} | ||
|
||
return String(value).includes(searchTerm); | ||
}, | ||
type: "string", | ||
colorKey: "base09", | ||
Renderer: (props) => { | ||
const value = props.value as string; | ||
return <HighlightedText text={`"${value}"`} searchTerm={searchTerm} />; | ||
}, | ||
}); | ||
|
||
const isInt = (n: number) => n % 1 === 0; | ||
|
||
const getHighlightedComponentFloat = (searchTerm: string) => | ||
defineEasyType({ | ||
is: (value) => { | ||
if ( | ||
searchTerm?.length === 0 || | ||
typeof value !== "number" || | ||
isInt(value) || | ||
isNaN(value) | ||
) { | ||
return false; | ||
} | ||
|
||
return String(value).includes(searchTerm); | ||
}, | ||
type: "float", | ||
colorKey: "base0B", | ||
Renderer: (props) => { | ||
const value = props.value as number; | ||
return <HighlightedText text={value} searchTerm={searchTerm} />; | ||
}, | ||
}); | ||
|
||
const getHighlightedComponentInt = (searchTerm: string) => | ||
defineEasyType({ | ||
is: (value) => { | ||
if ( | ||
searchTerm?.length === 0 || | ||
typeof value !== "number" || | ||
isNaN(value) || | ||
!isInt(value) | ||
) { | ||
return false; | ||
} | ||
|
||
return String(value).includes(searchTerm); | ||
}, | ||
type: "int", | ||
colorKey: "base0F", | ||
Renderer: (props) => { | ||
const value = props.value as number; | ||
return <HighlightedText text={value} searchTerm={searchTerm} />; | ||
}, | ||
}); | ||
|
||
export const getValueRenderersForSearch = (searchTerm: string) => [ | ||
getHighlightedComponentString(searchTerm), | ||
getHighlightedComponentFloat(searchTerm), | ||
getHighlightedComponentInt(searchTerm), | ||
]; |
2 changes: 1 addition & 1 deletion
2
app/packages/components/src/components/JSONPanel/json.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright 2017-2022, Voxel51, Inc. | ||
* Copyright 2017-2024, Voxel51, Inc. | ||
*/ | ||
|
||
.lookerJSONPanel { | ||
|
2 changes: 1 addition & 1 deletion
2
app/packages/components/src/components/JSONPanel/panel.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright 2017-2022, Voxel51, Inc. | ||
* Copyright 2017-2024, Voxel51, Inc. | ||
*/ | ||
|
||
.lookerPanel { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
app/packages/core/src/plugins/SchemaIO/components/JSONView.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.