Code Monkey home page Code Monkey logo

iot-cardboard-js's Introduction

build Storybook npm (tag)

Quick start πŸ“¦

What is iot-cardboard-js?

iot-cardboard-js or Cardboard is an open source React component library for creating internet of things (IoT) web experiences.

The components in Cardboard are also used for building the experiences in Azure Digital Twins 3D Scenes Studio, and can be leveraged by Azure Digital Twins customers in their own applications. Learn more about leveraging Cardboard components for 3D Scenes in the wiki.

The 3D visualization components in this library leverage the fantastic BabylonJS library under the hood. If you haven't used it yet, we can't say enough great things about the library, definitely check it out!

Viewer Mode image

Builder mode image

Storybook πŸ“–

This project is developed using Storybook - an open source tool for building UI components in isolation. Our hosted storybook showcases the current library of iot-cardboard-js components. Learn more about Storybook.

Note: stories which require authentication or API interaction can be found in the local development storybook.

Using iot-cardboard-js components πŸ”₯

Installing

Install our beta package from npm with:

npm install @microsoft/iot-cardboard-js@beta

Styles

Import the iot-cardboard-js themes stylesheet at the top level of your application to get theming for cardboard components via CSS custom properties (variables). These variables can be edited if you'd like to change theme colors.

import '@microsoft/iot-cardboard-js/themes.css';

Importing components via named exports

import {
    StandalonePropertyInspector,
    ADTAdapter,
    MsalAuthService,
    KeyValuePairCard,
    //...
} from '@microsoft/iot-cardboard-js';

This is the easiest method of importing components and, in most cases, will allow unused code to be tree shaken from our library. If, however, you only need a few modules from our library, you can use the direct import pattern to be more explicit about what code is imported.

Importing components via direct imports

Adapters, Classes, Constants, Hooks, and Services each have their own entry point and can be imported as follows.

Adapters:

import { AdtAdapter } from '@microsoft/iot-cardboard-js/Adapters'

Classes:

import { SearchSpan } from '@microsoft/iot-cardboard-js/Classes'

Constants:

import { IMockAdapter } from '@microsoft/iot-cardboard-js/Constants'

Hooks:

import { useGuid } from '@microsoft/iot-cardboard-js/Hooks'

Services:

import { MsalAuthService, getFileType } from '@microsoft/iot-cardboard-js/Services'

All Cards and Components have their own direct import path.

Cards:

import KeyValuePairCard from '@microsoft/iot-cardboard-js/Cards/KeyValuePairCard'

Components:

import StandalonePropertyInspector from '@microsoft/iot-cardboard-js/Components/StandalonePropertyInspector'

Examples

Storybook stories are the best way to learn how to use our components. Files ending in *.stories.tsx showcase components set up with mock data. While files ending in *.stories.local.tsx showcase components which authenticate and communicate with APIs. Stories are a great way to learn about the different ways to consume each of our components.

Check out the KeyValuePairCard stories for an example of this.

You can also see the code required to use a component by opening either the live or local storybook, selecting the docs tab at the top of a story, and clicking show code at the bottom right of a story panel. This opens a view of the code used to render that story!

Questions for maintainers πŸ™

If you have a question for one of the project maintainers, please post the question here. We'll get back to you as soon as possible!

Issue templates

Contributing πŸš€

Contributor License Agreement πŸ“ƒ

This project welcomes contributions and suggestions! Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

Code of conduct πŸ“

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks ℒ️

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

iot-cardboard-js's People

Contributors

abalogun-dev avatar brennacourtney avatar ccrowley96 avatar coryboyle avatar daniellemolinar95 avatar darsney avatar dependabot[bot] avatar iremgokce avatar jamiewilbraham avatar jl-g avatar microsoftopensource avatar montgomp avatar msnyder-msft avatar niusoff avatar pasanchmsft avatar ptallettms avatar samjosephgates avatar waywardhayward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iot-cardboard-js's Issues

Cannot edit/remove elements from behavior form

Describe the bug
When I try to edit or remove an element from behavior the callback functions are not working since onElementClick and onRemoveElement are not passed to SceneElements component in SceneBehaviorsForm. I fixed it in my current feature branch but feel free to fix it before.

To Reproduce
Steps to reproduce the behavior:

  1. Select a scene
  2. Got to behaviors
  3. Select a behavior to edit
  4. Go to elements tab and try to edit or remove that element from behavior

Expected behavior
Callback methods should work in overflow menu

Screenshots
image

Browser (please complete the following information):

  • Browser [e.g. chrome, safari, edge]

Additional context
Add any other context about the problem here.

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Model viewer mode dialog UI squished in built app

Describe the bug
Radio button selector UI sizing is messed up when viewing component in Azure-IoT-DigitalTwins-Explorer/app project.

image

To Reproduce
Steps to reproduce the behavior:

  1. Install cardboard in Azure-IoT-DigitalTwins-Explorer/app project
  2. Run locally
  3. Open Theme dialog
  4. View UI

Expected behavior
Expected UI to match storybook UI shown below
image

Alert visual should have a clear distinction between present & not present

Describe the bug
A clear and concise description of what the bug is.

Request from @rinisbet

As soon as trigger expression for Alerts is != "", the blue badge preview (sans icon, see Alert config feedback in the other chat) should appear on the preview popover... no alert text showing of course until they start typing that

Reasoning: it's a true live view of the badge when the alert is "valid"

To Reproduce
Steps to reproduce the behavior:

  1. Go to Alerts tab (in new behavior creation)
  2. Enter text in trigger expression box
  3. No preview shows of alert configured (color & icon are still null)

Expected behavior
Alerts need default badge / color values. Bottom part of form should probably disappear when no trigger expression is active, indicating alert is not present

Screenshots
Enter text in trigger expression (alert doesn't show)

image

Select a badge icon (alert shows only badge, no color)

image

Click on color icon picker (alert shows badge & color)
image

Pull request template

Is your feature request related to a problem? Please describe.
Clearer pull requests with images, config information, and consistent structure to describe changes

Describe the solution you'd like

  • Reminder to link issues
  • Reminder to add to kanban project
  • Section for images
  • Section for summary of changes
  • Section for any config, URLs, or information to test the pull request

Split out status color indicator & alert icon into isolated component

Is your feature request related to a problem? Please describe.
Status visuals & alert components should us a shared component in the different places these are rendered. This will ensure style consistency.

Something like StatusAlertIndicator

The status indicator would take in a list of status values.
The alert indicator would take in the icon and color value.

Both should make little assumption about where they are rendered, they should only render themselves and let the parent compose them in the right spot.

image
image
image

Feat: Color picker styling should align with icon picker

Is your feature request related to a problem? Please describe.
The color picker uses the default fluent picker which doesn't quite match with the styling of the icon picker when items are selected or being tabbed.

Designs
https://www.figma.com/file/LsmZeVOZJgwZs75HPTQmgU/3D-Scenes-Mock-Screens?node-id=44214%3A160541
image

Actual
image

Describe the solution you'd like
The focus targets should be squared off and not shrink the colored circles when selected

Network request wrapper to avoid duplicating request params and headers

The code below is duplicated in multiple places. @jl-g suggested refactoring the network requests to reduce code duplication.

const axiosData = await axios({
    method: 'get',
    url: this.adtProxyServerURL,
    headers: {
        'Content-Type': 'application/json',
        authorization: 'Bearer ' + token,
        'x-adt-host': this.adtHostUrl,
        'x-adt-endpoint': 'models'
    },
    params: {
        'api-version': '2020-10-31'
    }
});

Widget ids not updated correctly in the config file & On click on edit widget in the list, it the widget form picks up wrong widget to edit

Describe the bug
On "Widgets" tab, when I click on non-first widget item to edit, the WidgetForm is filled with the information of the first widget in that list. It is because of the "id" of the widgets are all "" empty string, so it picks up the first instance to edit.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Widgets in a behavior
  2. Click on "Edit" icon on ellipsis menu on one of the non-first widget item in the list
  3. See error

Expected behavior
The WidgetForm should pick up the right widget with its id to edit

Screenshots
image
image

image
image

Browser (please complete the following information):

  • Browser [e.g. chrome, safari, edge]

Additional context
Add any other context about the problem here.

Adding widget to existing behavior does not get saved

Describe the bug
When you try to add a widget to an existing behavior (edit flow) it does not get saved.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Behaviors list
  2. Click on an existing behavior
  3. Click on the Widgets tab
  4. Add a behavior with any content
  5. Save it
  6. Click Update Behavior
  7. Navigate back to the widgets tab on that behavior
  8. See that the widget is not persisted

Expected behavior
Newly added widget should still be there when I come back after choosing to update

Search on widget library does not do anything

Describe the bug
When searching in the widget library it does not filter the list items

To Reproduce
Steps to reproduce the behavior:

  1. Go to Behaviors list
  2. Click on a behavior
  3. Navigate to the Widgets tab
  4. Click on 'Add Widget'
  5. Type something in the search box
  6. See nothing happen

Expected behavior
When typing text, the list of widget types should get filtered.

Screenshots
image

Mock adapter update: Instant mock adapter and data seeding option to create useful snapshot tests

  • Create option to set mock adapter timeout to 0. This will ensure that snapshot tests contain more than card loading state
  • Create option to seed mock data to keep data stable between builds. This will ensure that snapshot tests don't flag diffs on data changing between builds ie. diffs should only show purposeful changes
  • Change mock adapter constructor parameter to strongly typed object with optional props and intelligent defaults

Improve loading of ADTInstances component

Improve ADTInstances component not to block while loading
Leverage this component in flights after we handle loading not blocking while the instances load, and handle environments that are set if people dont have access to them

Key Value Pair card bug: Objects are not valid as a React child

Bug when rendering certain twin properties.

Repro link: with new eid & twinid updates -> visit this link https://explorer.digitaltwins.azure.net/flights?eid=https%3A%2F%2FSmartCitiesExplorerDemo.api.aue.digitaltwins.azure.net&twinid=SmartPoleE.1 and select relationship EVChargerE.1 in the table

image

react-dom.development.js:13413 Uncaught Error: Objects are not valid as a React child (found: object with keys {addressCountry, $metadata}). If you meant to render a collection of children, use an array instead.
    in div (created by KVP)
    in div (created by KVP)
    in KVP (created by KeyValuePairCard)
    in div (created by KeyValuePairCard)
    in div (created by BaseCard$1)
    in div (created by BaseCard$1)
    in div (created by ThemeProvider)
    in div (created by ThemeProvider)
    in ThemeProvider (created by ThemeProvider)
    in ThemeProvider (created by BaseCard$1)
    in I18nextProvider (created by I18nProviderWrapper)
    in I18nProviderWrapper (created by BaseCard$1)
    in BaseCard$1 (created by KeyValuePairCard)
    in KeyValuePairCard (created by Board)
    in div (created by Board)
    in div (created by Board)
    in div (created by ThemeProvider)
    in div (created by ThemeProvider)
    in ThemeProvider (created by ThemeProvider)
    in ThemeProvider (created by Board)
    in I18nextProvider (created by I18nProviderWrapper)
    in I18nProviderWrapper (created by Board)
    in Board (created by ADTHierarchyWithBoard)
    in div (created by ADTHierarchyWithBoard)
    in div (created by ADTHierarchyWithBoard)
    in ADTHierarchyWithBoard (at Twins.tsx:46)
    in div (at Twins.tsx:45)
    in Twins (at App.tsx:263)
    in Route (at App.tsx:260)
    in Switch (at App.tsx:259)
    in div (at App.tsx:250)
    in div (at App.tsx:249)
    in main (at App.tsx:220)
    in div (at App.tsx:180)
    in App (at src/index.tsx:15)
    in div (at ThemeProvider.tsx:32)
    in div (created by ThemeProvider)
    in ThemeProvider (at ThemeProvider.tsx:31)
    in ThemeProviderWrapper (at src/index.tsx:14)
    in I18nextProvider (at I18nProvider.tsx:27)
    in I18nProviderWrapper (at src/index.tsx:13)
    in Router (created by BrowserRouter)
    in BrowserRouter (at src/index.tsx:12)
    in StrictMode (at src/index.tsx:11)
    at throwOnInvalidObjectType (react-dom.development.js:13413)
    at reconcileChildFibers (react-dom.development.js:14313)
    at reconcileChildren (react-dom.development.js:16762)
    at updateHostComponent (react-dom.development.js:17302)
    at beginWork (react-dom.development.js:18627)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at beginWork$1 (react-dom.development.js:23203)
    at performUnitOfWork (react-dom.development.js:22154)
    at workLoopSync (react-dom.development.js:22130)
    at performSyncWorkOnRoot (react-dom.development.js:21756)
    at react-dom.development.js:11089
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
    at flushSyncCallbackQueue (react-dom.development.js:11072)
    at scheduleUpdateOnFiber (react-dom.development.js:21199)
    at dispatchAction (react-dom.development.js:15660)
    at setAdapterResult (index.es.js:56081)
    at index.es.js:56096
    at step (index.es.js:108)
    at Object.next (index.es.js:89)
    at fulfilled (index.es.js:79)

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Cannot find module '@microsoft/iot-cardboard-js' or its corresponding type declarations

Describe the bug
After installing recent iot-cardboard npm package I started getting the below error when I try to import from @microsoft/iot-cardboard-js:
Could not find a declaration file for module '@microsoft/iot-cardboard-js'. '/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/microsoft__iot-cardboard-js if it exists or add a new declaration (.d.ts) file containing `declare module '@microsoft/iot-cardboard-js

To Reproduce
Steps to reproduce the behavior:

  1. Go to your app (e.g. flights app) and try to install the @microsoft/iot-cardboard-js package by >npm install @microsoft/iot-cardboard-js (you can also test it with >npm run build in iot-cardboard project and copy and install the .tgz under build_artifacts folder to your app)
  2. Reload your project in VS Code
  3. See error in your app when you try to import any exported asset from @microsoft/iot-cardboard

Expected behavior
Should be able recognize @microsoft/iot-cardboard-js module to import anything from it

Screenshots
image

Browser (please complete the following information):

  • Chrome

Additional context
When I added the right path to types in package.json in iot-cardboard repo it solved the issue, because when you check the /dist folder after building all the modules are exported and type declarations are in the index.d.ts under /src. The fix is in my recent PR. Do not know when this change happened though, any idea @ccrowley96 ?:
image
image

UPDATE: it was due to how we import a vconfigDecFinal.json file from .storybook. I used exported variable in ts file instead.

Revise and merge interfaces

  • clean/merge duplications of the same interfaces/types in Interfaces.ts and Types.ts (e.g. IADTModel and DTModel interfaces have similar content)
  • revise DTDL.ts classes to use one main class property strongly typed with one of these cleaned interfaces, or see if we can extend from those interfaces when declaring these classes

The focus outline on the IconPicker is square instead of rounded

Describe the bug
When you tab onto the root button or items in the icon picker the focus line is a square instead of rounded.
image

To Reproduce
Steps to reproduce the behavior:

  1. Go to Alerts tab on the Behavior form
  2. Tab to the Icon button
  3. See the outline shows up in a square instead of circle

Expected behavior
Should be inset like the color picker border is when those are focused

Widget library dialog uses clickable divs instead of buttons

Describe the bug
The list items in the widget library dialog are clickable divs instead of buttons.
This is an accessibility issue for screen readers at least

To Reproduce
Steps to reproduce the behavior:

  1. Go to Behaviors list
  2. Click on a behavior
  3. Navigate to the Widgets tab
  4. Click on 'Add Widget'

Expected behavior
Clickable elements should be <button> tags

Screenshots

image

Nested cards / boards have duplicate H.O.Cs for theming and localization

Problem

  • We are creating a new theme / localization context for each base card, even if there is already a context higher in the component tree.
  • Components (such as JsonPreview, ModelSearch, etc) must be wrapped in base card to be themed / localized

Possible solution

  • When wrapping components in localization / theming higher order components (H.O.C), we should check if localization / theming contexts are already available, and use those contexts if possible, if not, the component is being rendered in a standalone fashion and we should add the localization / theming H.O.C
  • If we separate out localization / theming into a single H.O.C, we may be able to reuse this component and do the same check to see if the H.O.C exists for components as well as cards. This way, we can have themed / localized standalone components in storybook and elsewhere, even if the components aren't wrapped in basecard.
  • To add these H.O.C to components, we'll likely need to create a BaseComponent that wraps components, adding the theme / localization H.O.C if a context isn't already found.

image

Hovering list items in any element list causes major perf lag

Describe the bug
When you're on the Elements list or the Elements form (mesh tab) and hover items in the list, the perf of the app gets really laggy.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Elements list
  2. Click on a element with meshes
  3. Hover on items in the list of meshes
  4. watch the lag time between when the hover background shows up
    image

Cannot create behavior on new element in element form

Describe the bug
Cannot create behavior on new element from behaviors tab.

To Reproduce
Steps to reproduce the behavior:

  1. On Elements tab
  2. Click on 'Create element'
  3. Click on behavior pivot within elements for
  4. Click on 'Add behavior'
  5. Select 'Create behavior' from callout --> this throws (during element initial creation)

Expected behavior
Action is taken after clicking 'Create behavior in callout'

Screenshots
image

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.