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

Support of ObjectId #19

Open
fberrez opened this issue Oct 27, 2023 · 2 comments
Open

Support of ObjectId #19

fberrez opened this issue Oct 27, 2023 · 2 comments

Comments

@fberrez
Copy link

fberrez commented Oct 27, 2023

Currently, there is no support of bson ObjectId. The purpose would be to implement it so it cans look like:

image
jaywcjlove added a commit that referenced this issue Oct 27, 2023
@jaywcjlove
Copy link
Member

@fberrez https://codesandbox.io/embed/https-github-com-uiwjs-react-json-view-issues-19-5rhzdj?fontsize=14&hidenavigation=1&theme=dark

import React from 'react';
import JsonView from '@uiw/react-json-view';

const object = {
  _id: "ObjectId('13212hakjdhajksd')",
  uid: "test1",
  attival_time: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
  __v: 0
}

export default function Demo() {
  return (
    <JsonView
      value={object}
      // keyName="root"
      displayObjectSize={false}
      style={{
        '--w-rjv-background-color': '#ffffff',
      }}
    >
      <JsonView.Quote render={() => <span />}/>
      <JsonView.String
        render={({ children, ...reset }, { type, value, keyName }) => {
          if (type === 'type') {
            return <span />
          }
          if (type === 'value' && /ObjectId\(['"](.*?)['"]\)/.test(value)) {
            return <span {...reset}>{children}</span>
          }
        }}
      />
      <JsonView.Date
        render={({ children, ...reset }, { type, value, keyName }) => {
          if (type === 'type') {
            return <span />
          }
        }}
      />
      <JsonView.Int
        render={({ children, ...reset }, { type, value, keyName }) => {
          if (type === 'type') {
            return <span />
          }
        }}
      />
    </JsonView>
  )
}

github-actions bot pushed a commit that referenced this issue Oct 27, 2023
@fberrez
Copy link
Author

fberrez commented Oct 27, 2023

Looks great but it seems that I have to convert first all the ObjectId I have in my mongo document. Thank you for the tip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants