GithubHelp home page GithubHelp logo

kickstartds / storybook-addon-jsonschema Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 2.63 MB

Displays associated JSON Schema documentation using a rich schema explorer interface, and adds a validating JSON Code Editor with semantic auto-complete to interact with your components, and copy configurations with ease.

Home Page: https://www.kickstartDS.com/docs/integration/storybook/schema

License: MIT License

JavaScript 37.10% TypeScript 50.68% CSS 12.22%
storybook-addon data-state json json-schema jsonschema controls addon-controls react storybook

storybook-addon-jsonschema's Issues

Is it impossible to update view when I change nested object?

https://www.kickstartds.com/storybook/?path=/story/base-header--default

in this example, when I change

"items": [
      {
        "label": "Sanity",
        "href": "/sanity",
        "id": "sanity"
      },
      {
        "label": "Integrations",
        "href": "/integrations",
        "id": "integrations"
      },
      {
        "label": "Blog",
        "href": "/blog",
        "id": "blog"
      }
    ]

to

"items": [
      {
        "label": "ABC TEST",
        "href": "/sanity",
        "id": "sanity"
      },
      {
        "label": "Integrations",
        "href": "/integrations",
        "id": "integrations"
      },
      {
        "label": "Blog",
        "href": "/blog",
        "id": "blog"
      }
    ]

it looks like there's not any changes.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/AdvertisementDataOverviewType",
  "definitions": {
    "AdvertisementOverviewViewType.Data.AsObject": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "subTitle": {
          "type": "string"
        },
        "price": {
          "type": "number"
        },
        "countsList": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Count.AsObject"
          }
        },
        "image": {
          "type": "string"
        },
        "targetUri": {
          "type": "string"
        },
        "publishedAt": {
          "type": "number"
        },
        "categoryId": {
          "type": "number"
        },
        "quickReportQuestion": {
          "$ref": "#/definitions/QuickReportQuestion.AsObject"
        },
        "userId": {
          "type": "number"
        },
        "meta": {
          "$ref": "#/definitions/AdvertisementOverviewViewType.Meta.AsObject"
        }
      },
      "required": [
        "title",
        "subTitle",
        "price",
        "countsList",
        "image",
        "targetUri",
        "publishedAt",
        "categoryId",
        "userId"
      ],
      "additionalProperties": false
    },
    "Count.AsObject": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/definitions/CountType"
        },
        "value": {
          "type": "number"
        },
        "image": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "value",
        "image"
      ],
      "additionalProperties": false
    },
    "CountType": {
      "type": "number",
      "enum": [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7
      ]
    },
    "QuickReportQuestion.AsObject": {
      "type": "object",
      "properties": {
        "content": {
          "type": "string"
        },
        "reportItemId": {
          "type": "number"
        }
      },
      "required": [
        "content",
        "reportItemId"
      ],
      "additionalProperties": false
    },
    "AdvertisementOverviewViewType.Meta.AsObject": {
      "type": "object",
      "properties": {
        "advertisement": {
          "$ref": "#/definitions/Advertisement.AsObject"
        }
      },
      "additionalProperties": false
    },
    "Advertisement.AsObject": {
      "type": "object",
      "properties": {
        "id": {
          "type": "number"
        }
      },
      "required": [
        "id"
      ],
      "additionalProperties": false
    }
  }
}

generated schema, and It looks like every ref objects read as anything.

스크린샷 2022-03-22 오전 2 20 25

Add working `Show me a working demo` example

We should add Circle CI jobs for automatic release (auto is already used as a part of the storybookjs/addon-kit) and publishing of the example Storybook on Netlify.

The deploy preview / configured url on Netlify can then be used for the Show me the demo page.

"Darkmode"-compatibility of views

Currently it's next to impossible to read some of the text we display in the addon, when the Storybook itself is themed to be dark, e.g.:
image

We should either a) make this dynamic in the addon, or use the correct token contextually, or b) just remove custom theming, isolating the views and always displaying them in light mode

Module not found: Error: Can't resolve 'crypto' in ".../node_modules/@kickstartds/json-schema-viewer/dist"

When trying to install this add-on to storybook, I am getting this error when running up or building
Module not found: Error: Can't resolve 'crypto' in ".../node_modules/@kickstartds/json-schema-viewer/dist"

There were actually several packages but by installing them in my project node_modules I was able to resolve most of them. However, it looks like this one needs to be polyfilled according to webpack

I am using webpack5, i have installed crypto-browserify and my storybook main looks like this:

const path = require('path');
const rootMain = require('../../../.storybook/main');
const toPath = (filePath) => path.join(process.cwd(), filePath);

module.exports = {
  ...rootMain,
  typescript:{
    check: false,
    checkOptions: {},
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      compilerOptions: {
        allowSyntheticDefaultImports: false,
        esModuleInterop: false,
      }
      // propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
    },
  },
  core: {
    ...rootMain.core,
    builder: 'webpack5',
    enableCrashReports: true, // 👈 Appends the crash reports to the telemetry events
  },

  stories: [
    ...rootMain.stories,
    '../src/app/**/*.stories.@(js|jsx|ts|tsx)',
    '../src/app/**/*.stories.mdx',
  ],

  staticDirs: [
    "../src/assets",
    "../src/public"
  ],

  addons: [...rootMain.addons, '@nrwl/react/plugins/storybook', '@kickstartds/storybook-addon-jsonschema'],
  webpackFinal: async (config, { configType }) => {
    console.log('THIS IS THE STORYBOOK WEBPACK FINAL')
    // apply any global webpack configs that might have been specified in .storybook/main.js
    if (rootMain.webpackFinal)
      config = await rootMain.webpackFinal(config, { configType });
    // add your own webpack tweaks if needed

    //added for material-ui theme font
    config.module.rules.push({
      test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
      use: [
        {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: 'assets/'
          }
        }
      ]
    });



    const value = {
      ...config,
      resolve: {
        ...config.resolve,
        fallback: {
          crypto: require.resolve('crypto-browserify')
        },
        alias: {
          ...config.resolve.alias,
          '@emotion/core': toPath('node_modules/@emotion/react'),
          'emotion-theming': toPath('node_modules/@emotion/react'),
        },
      },
    };
    console.log('THIS IS THE WEBPACK FINAL VALUE')
    console.log(JSON.stringify(value, null, 2))
    return value
  },
}; 

The logs show that the fallback is added to the config.

Im wondering

  1. Why is this complaining about crypto, i dont even see it in the node modules of the project?
  2. Is this something that needs to be resolved in this project or is there a work around that anyone has found?

Create reset state button for component / story

In the Controls panel you can reset the state of the story by clicking a small "Refresh"-Icon.

We should add something similar to the addon, to reset the state to its initial values. Handy if you're just tinkering with values, and don't feel like backtracking your changes made.

Upgrade react peer depenendency

The package currently only declares a peer dependency React 16 and 17 so when installing for React 18 repos, I get this following error. Can a peer for React 18 be added? Thank you!

npm ERR! While resolving: XXXXXXXX
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   dev react@"^18.2.0" from XXXXXXXX
npm ERR!   packages/XXXXXXXX
npm ERR!     XXXXXXXX
npm ERR!     node_modules/XXXXXXXX
npm ERR!       workspace packages/XXXXXXXX from the root project
npm ERR!       1 more (XXXXXXXX)
npm ERR!   peer react@"^16.8.0 || ^17.0.0 || ^18.0.0" from @storybook/[email protected]
npm ERR!   node_modules/@storybook/addons
npm ERR!     peer @storybook/addons@"^6.3.6" from @kickstartds/[email protected]
npm ERR!     node_modules/@kickstartds/storybook-addon-jsonschema
npm ERR!       dev @kickstartds/storybook-addon-jsonschema@"^1.0.6" from [email protected]
npm ERR!       XXXXXXXX
npm ERR!         [email protected]
npm ERR!         XXXXXXXX
npm ERR!   4 more (react-dom, @storybook/api, @storybook/components, @storybook/theming)
npm ERR!

Schema "AnyOf" generated as "anything"

I generate a schema of this type,

export type ViewTypeReducerType =
  AdvertisementOverviewViewType.AsObject
  | ButtonTextViewType.AsObject 
  | FleaMarketOverviewViewType.AsObject
  | EventOverviewViewType.AsObject
  | GeneralBusinessOverviewViewType.AsObject
  | GeneralOverviewViewType.AsObject
  | GeneralProgressviewViewType.AsObject
  | GeneralWatchOverviewViewType.AsObject
  | ImageBannerViewType.AsObject
  | NoticeOverviewViewType.AsObject
  | PopupOverviewViewType.AsObject
  | QuestionViewType.AsObject
  | RegionCheckInViewType.AsObject

and generated stuff was

"ViewTypeReducerType": {
      "anyOf": [
        {
          "type": "object",
          "required": [
            "type"
          ],

.....

, the anyOf of objects.

and generated result on storybook was,

스크린샷 2022-03-22 오후 2 31 38

is there any method to resolve anyof schema correctly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.