diff --git a/.eslintignore b/.eslintignore index fe799b02..c323aa6f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,3 +4,4 @@ **/dist CHANGELOG.md docs +packages/*/template/* diff --git a/.prettierignore b/.prettierignore index fe799b02..70416a2d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ **/dist CHANGELOG.md docs +**/*.handlebars diff --git a/packages/cra-template-apps-starter-kit/LICENSE b/packages/cra-template-apps-starter-kit/LICENSE new file mode 100644 index 00000000..1f9985e0 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-Present Datadog, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/cra-template-apps-starter-kit/README.md b/packages/cra-template-apps-starter-kit/README.md new file mode 100644 index 00000000..afbf9083 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/README.md @@ -0,0 +1,25 @@ +# Datadog UI App React Starter Kit + +This is a [`create-react-app`](https://create-react-app.dev/) [custom template](https://create-react-app.dev/docs/custom-templates) that helps you get started building a Datadog UI App. + +## Getting Started + +### Using npx + +```sh +npx create-react-app starter-kit --template @datadog/apps-starter-kit +``` + +### Using npm + +```sh +npm init react-app starter-kit --template @datadog/apps-starter-kit +``` + +### Using yarn + +```sh +yarn create react-app starter-kit --template @datadog/apps-starter-kit +``` + +**Note**: This template currently uses v17 of React due to the `peerDependency` that `"@datadog/ui-extensions-react"` has on `17.0.2`; once the relevant `@types/` packages for React and ReactDOM are updated and we can move to v18 across the board, we will. diff --git a/packages/cra-template-apps-starter-kit/package.json b/packages/cra-template-apps-starter-kit/package.json new file mode 100644 index 00000000..2b8eb33d --- /dev/null +++ b/packages/cra-template-apps-starter-kit/package.json @@ -0,0 +1,34 @@ +{ + "name": "@datadog/cra-template-apps-starter-kit", + "version": "1.0.0", + "keywords": [ + "react", + "create-react-app", + "template", + "datadog" + ], + "description": "Datadog UI Apps Starter Kit", + "repository": { + "type": "git", + "url": "git+https://github.com/DataDog/apps.git", + "directory": "packages/cra-template-apps-starter-kit" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=16" + }, + "bugs": { + "url": "https://github.com/DataDog/apps/issues" + }, + "main": "template.json", + "files": [ + "template", + "template.json" + ], + "publishConfig": { + "access": "public" + }, + "scripts": { + "prepare": "exit 0" + } +} diff --git a/packages/cra-template-apps-starter-kit/template.json b/packages/cra-template-apps-starter-kit/template.json new file mode 100644 index 00000000..92f0f095 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template.json @@ -0,0 +1,21 @@ +{ + "package": { + "dependencies": { + "@datadog/ui-extensions-react": "0.31.0", + "@datadog/ui-extensions-sdk": "0.31.0", + "milligram": "^1.4.1", + "typeface-roboto": "^1.1.13" + }, + "eslintConfig": { + "extends": ["react-app", "react-app/jest"] + }, + "browserslist": { + "production": [">0.2%", "not dead", "not op_mini all"], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } + } +} diff --git a/packages/cra-template-apps-starter-kit/template/.prettierignore b/packages/cra-template-apps-starter-kit/template/.prettierignore new file mode 100644 index 00000000..0c50478f --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/.prettierignore @@ -0,0 +1,3 @@ +build +CHANGELOG.md +dist diff --git a/packages/cra-template-apps-starter-kit/template/LICENSE b/packages/cra-template-apps-starter-kit/template/LICENSE new file mode 100644 index 00000000..1f9985e0 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-Present Datadog, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/cra-template-apps-starter-kit/template/README.md b/packages/cra-template-apps-starter-kit/template/README.md new file mode 100644 index 00000000..aaed398d --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/README.md @@ -0,0 +1,70 @@ +# Datadog UI App React Starter Kit + +This project was generated via the [Datadog UI Apps Starter Kit](https://github.com/datadog/apps/packages/cra-template-apps-starter-kit) [`create-react-app`](https://create-react-app.dev/) [custom template](https://create-react-app.dev/docs/custom-templates). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can't go back!** + +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. + +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/packages/cra-template-apps-starter-kit/template/app_manifest.json b/packages/cra-template-apps-starter-kit/template/app_manifest.json new file mode 100644 index 00000000..22854671 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/app_manifest.json @@ -0,0 +1,98 @@ +{ + "schemaVersion": "v2", + "display_on_public_website": false, + "app_id": null, + "support_type": "partner", + "tile": { + "description": "A hello-world like application used as a starting point for apps", + "logo_media": { + "light": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Emojione_1F44B.svg/1024px-Emojione_1F44B.svg.png" + }, + "title": "Your first app!" + }, + "author": {}, + "pricing": [], + "legal_terms": {}, + "proxy_scopes": [], + "assets": { + "ui_extensions": { + "debug_mode_url": "http://localhost:3000", + "secured": false, + "main_url": "http://localhost:3000", + "api_version": "v1.0", + "features": [ + { + "name": "dashboard_custom_widget", + "options": { + "widgets": [ + { + "name": "Your first app", + "has_title": true, + "custom_widget_key": "your_first_app", + "source": "widget", + "options": [ + { + "enum": [ + "system.cpu.idle", + "system.load.1", + "system.load.5", + "system.load.15" + ], + "type": "string", + "name": "metric", + "label": "Your favorite metric" + }, + { + "enum": [ + "Chevre", + "Gruyere", + "Mozzarella" + ], + "type": "string", + "name": "favorite-cheese", + "label": "Your favorite cheese" + } + ], + "icon": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Emojione_1F44B.svg/1024px-Emojione_1F44B.svg.png" + } + ] + } + }, + { + "name": "dashboard_cog_menu", + "options": { + "items": [ + { + "action_type": "event", + "key": "open-confirmation", + "label": "Please confirm" + }, + { + "action_type": "event", + "key": "open-custom-modal", + "label": "Open a custom modal" + }, + { + "action_type": "event", + "key": "open-custom-panel", + "label": "Open a custom side panel with args" + } + ] + } + }, + { + "name": "modals", + "options": {} + }, + { + "name": "side_panels", + "options": {} + }, + { + "name": "widget_context_menu", + "options": { "items": [] } + } + ] + } + } +} diff --git a/packages/cra-template-apps-starter-kit/template/gitignore b/packages/cra-template-apps-starter-kit/template/gitignore new file mode 100644 index 00000000..b8fba009 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js +.eslintcache + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/packages/cra-template-apps-starter-kit/template/public/_redirects b/packages/cra-template-apps-starter-kit/template/public/_redirects new file mode 100644 index 00000000..2ccd43ba --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/public/_redirects @@ -0,0 +1,3 @@ +/widget /index.html 200 +/modal /index.html 200 +/panel /index.html 200 \ No newline at end of file diff --git a/packages/cra-template-apps-starter-kit/template/public/favicon.ico b/packages/cra-template-apps-starter-kit/template/public/favicon.ico new file mode 100644 index 00000000..a11777cc Binary files /dev/null and b/packages/cra-template-apps-starter-kit/template/public/favicon.ico differ diff --git a/packages/cra-template-apps-starter-kit/template/public/index.html b/packages/cra-template-apps-starter-kit/template/public/index.html new file mode 100644 index 00000000..0d815837 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/public/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + Datadog UI App + + + +
+ + diff --git a/packages/cra-template-apps-starter-kit/template/public/robots.txt b/packages/cra-template-apps-starter-kit/template/public/robots.txt new file mode 100644 index 00000000..e9e57dc4 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/packages/cra-template-apps-starter-kit/template/src/controller/dashboard-cog-menu.js b/packages/cra-template-apps-starter-kit/template/src/controller/dashboard-cog-menu.js new file mode 100644 index 00000000..fd920dd4 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/controller/dashboard-cog-menu.js @@ -0,0 +1,107 @@ +export const setupDashboardCogMenu = client => { + // provide cog menu items dynamically if needed + client.dashboard.cogMenu.onRequest(() => { + return { + items: [ + { + actionType: 'link', + href: 'https://google.com', + label: 'link to google', + key: 'link', + order: -1 + } + ] + }; + }); + + client.events.on('widget_settings_menu_click', context => { + if (context.menuItem.key === 'open-confirmation') { + client.modal.open({ + actionLabel: 'Yes', + cancelLabel: 'Nevermind', + title: 'Please verify!', + key: 'confirmation-modal', + actionLevel: 'danger', + message: 'Are you sure really sure?' + }); + } + + // open an iframe modal defined inline here in controller + if (context.menuItem.key === 'open-custom-modal') { + client.modal.open( + { + key: 'custom-modal', + size: 'lg', + source: 'modal' + }, + { + message: + 'Hi! I was sent here from the custom widget settings menu 👋', + options: context.widget.definition.options + } + ); + } + + // open an iframe side panel defined inline here in controller + if (context.menuItem.key === 'open-custom-panel') { + console.log('xxxx context', context); + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel', + title: 'Custom Sidepanel' + }, + { + message: + 'Hi! I was sent here from the custom widget settings menu 👋', + options: context.widget.definition.options + } + ); + } + }); + + // listen for cog menu click events + client.events.on('dashboard_cog_menu_click', context => { + if (context.menuItem.key === 'open-confirmation') { + client.modal.open({ + actionLabel: 'Yes', + cancelLabel: 'Nevermind', + title: 'Please verify!', + key: 'confirmation-modal', + actionLevel: 'danger', + message: 'Are you sure really sure?' + }); + } + + // open an iframe modal defined inline here in controller + if (context.menuItem.key === 'open-custom-modal') { + client.modal.open( + { + key: 'custom-modal', + size: 'lg', + source: 'modal' + }, + { + message: + 'Hi! I was sent here from the dashboard cog menu 👋' + } + ); + } + + // open an iframe side panel defined inline here in controller + if (context.menuItem.key === 'open-custom-panel') { + console.log('xxxx context', context); + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel', + title: 'Custom Sidepanel' + }, + { + message: + 'Hi! I was sent here from the dashboard cog menu 👋' + } + ); + } + }); +}; diff --git a/packages/cra-template-apps-starter-kit/template/src/controller/index.js b/packages/cra-template-apps-starter-kit/template/src/controller/index.js new file mode 100644 index 00000000..2003aa45 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/controller/index.js @@ -0,0 +1,26 @@ +import { init } from '@datadog/ui-extensions-sdk'; + +import { setupDashboardCogMenu } from './dashboard-cog-menu'; +import { setupModal } from './modal'; +import { setupWidgetCtxMenu } from './widget-ctx-menu'; + +export default function setup() { + const client = init(); + + setupModal(client); + setupWidgetCtxMenu(client); + setupDashboardCogMenu(client); + + const root = document.getElementById('root'); + + if (!root) { + return; + } + + root.innerHTML = ` +
+

The application controller is running in the background.

+ Click here to open your widget +
+ `; +} diff --git a/packages/cra-template-apps-starter-kit/template/src/controller/modal.js b/packages/cra-template-apps-starter-kit/template/src/controller/modal.js new file mode 100644 index 00000000..a11f6238 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/controller/modal.js @@ -0,0 +1,19 @@ +export const setupModal = client => { + // listen for modal events + client.events.on('modal_action', () => { + console.log('Confirmed!'); + }); + + client.events.on('modal_cancel', () => { + console.log('Denied!'); + }); + + client.events.on('modal_close', definition => { + console.log(`User exited modal ${definition.key}`); + }); + + // listen for a custom event sent from modal IFrame + client.events.onCustom('modal_button_click', count => { + console.log(`The user has clicked the button ${count} times`); + }); +}; diff --git a/packages/cra-template-apps-starter-kit/template/src/controller/widget-ctx-menu.js b/packages/cra-template-apps-starter-kit/template/src/controller/widget-ctx-menu.js new file mode 100644 index 00000000..6ad1e4b8 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/controller/widget-ctx-menu.js @@ -0,0 +1,40 @@ +export const setupWidgetCtxMenu = client => { + // provide widget context menu items dynamically + client.widgetContextMenu.onRequest(({ widget }) => { + return { + items: [ + { + href: `https://docs.datadoghq.com/dashboards/widgets/${widget.definition.type}/`, + actionType: 'link', + key: 'link-item', + label: `Read about ${widget.definition.type} widgets`, + order: 3 + }, + { + actionType: 'event', + // this key is used below to determine which action to take upon click + key: 'sidepanel-trigger', + label: `Open a sidepanel`, + order: 1 + } + ] + }; + }); + + // listen for ctx menu click events + + client.events.on('widget_context_menu_click', context => { + if (context.menuItem.key === 'sidepanel-trigger') { + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel' + }, + { + message: + 'Hi! I was sent here from the widget context menu 👋' + } + ); + } + }); +}; diff --git a/packages/cra-template-apps-starter-kit/template/src/index.jsx b/packages/cra-template-apps-starter-kit/template/src/index.jsx new file mode 100644 index 00000000..86f02247 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/index.jsx @@ -0,0 +1,24 @@ +const init = async () => { + switch (window.location.pathname) { + case '/widget': { + const widget = await import('./widget'); + return widget.default(); + } + case '/panel': { + const sidepanel = await import('./side-panel'); + return sidepanel.default(); + } + case '/modal': { + const modal = await import('./modal'); + return modal.default(); + } + default: { + const controller = await import('./controller'); + return controller.default(); + } + } +}; + +init(); + +export {}; diff --git a/packages/cra-template-apps-starter-kit/template/src/modal/index.jsx b/packages/cra-template-apps-starter-kit/template/src/modal/index.jsx new file mode 100644 index 00000000..0430298b --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/modal/index.jsx @@ -0,0 +1,57 @@ +import { useContext } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React, { useState } from 'react'; + +const client = init(); + +function Modal() { + const [clickCount, setClickCount] = useState(0); + const context = useContext(client); + const args = context?.args; + + const onClick = () => { + setClickCount(clickCount + 1); + + client.events.broadcast('modal_button_click', clickCount + 1); + }; + + return ( +
+

+ This modal was opened programatically from the main app + controller with these args +

+
+

+ {JSON.stringify(args)} +

+
+ +
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-starter-kit/template/src/side-panel/index.jsx b/packages/cra-template-apps-starter-kit/template/src/side-panel/index.jsx new file mode 100644 index 00000000..9cf99890 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/side-panel/index.jsx @@ -0,0 +1,37 @@ +import { useContext } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React from 'react'; + +const client = init(); + +function SidePanel() { + const context = useContext(client); + + const args = context?.args; + + return ( +
+

This side panel was opened programatically with these args

+
+

+ {JSON.stringify(args)} +

+
+
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-starter-kit/template/src/widget/index.jsx b/packages/cra-template-apps-starter-kit/template/src/widget/index.jsx new file mode 100644 index 00000000..183453b4 --- /dev/null +++ b/packages/cra-template-apps-starter-kit/template/src/widget/index.jsx @@ -0,0 +1,59 @@ +import 'milligram'; +import 'typeface-roboto'; +import { useCustomWidgetOptionString } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React, { useEffect, useState } from 'react'; + +const client = init(); + +function Widget() { + const metric = useCustomWidgetOptionString(client, 'metric'); + const [broadcastClickCount, setBroadcastClickCount] = useState(0); + + useEffect(() => { + client.events.onCustom('modal_button_click', setBroadcastClickCount); + }, []); + + const onOpenSidePanel = args => { + client.sidePanel.open( + { + source: 'panel', + key: 'custom-side-panel', + title: 'Custom Sidepanel' + }, + { metric } + ); + }; + + return ( +
+

Hello App Developer! 👋

+

Welcome to your first Datadog application.

+

+ Your favorite metric is: {metric} +

+

+ You can open a side panel programatically and pass to it your + favorite metric by clicking{' '} + {' '} +

+

+ The red button in the modal has been clicked:{' '} + {broadcastClickCount} time(s) +

+
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-typescript-starter-kit/LICENSE b/packages/cra-template-apps-typescript-starter-kit/LICENSE new file mode 100644 index 00000000..1f9985e0 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-Present Datadog, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/cra-template-apps-typescript-starter-kit/README.md b/packages/cra-template-apps-typescript-starter-kit/README.md new file mode 100644 index 00000000..91a056c3 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/README.md @@ -0,0 +1,25 @@ +# Datadog UI App React TypeScript Starter Kit + +This is a [`create-react-app`](https://create-react-app.dev/) [custom template](https://create-react-app.dev/docs/custom-templates) that helps you get started building a Datadog UI App. + +## Getting Started + +### Using npx + +```sh +npx create-react-app starter-kit --template @datadog/apps-typescript-starter-kit +``` + +### Using npm + +```sh +npm init react-app starter-kit --template @datadog/apps-typescript-starter-kit +``` + +### Using yarn + +```sh +yarn create react-app starter-kit --template @datadog/apps-typescript-starter-kit +``` + +**Note**: This template currently uses v17 of React due to the `peerDependency` that `"@datadog/ui-extensions-react"` has on `17.0.2`; once the relevant `@types/` packages for React and ReactDOM are updated and we can move to v18 across the board, we will. diff --git a/packages/cra-template-apps-typescript-starter-kit/package.json b/packages/cra-template-apps-typescript-starter-kit/package.json new file mode 100644 index 00000000..52d0c452 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/package.json @@ -0,0 +1,35 @@ +{ + "name": "@datadog/cra-template-apps-typescript-starter-kit", + "version": "1.0.0", + "keywords": [ + "react", + "create-react-app", + "template", + "typescript", + "datadog" + ], + "description": "Datadog UI Apps Starter Kit", + "repository": { + "type": "git", + "url": "git+https://github.com/DataDog/apps.git", + "directory": "packages/cra-template-apps-typescript-starter-kit" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=16" + }, + "bugs": { + "url": "https://github.com/DataDog/apps/issues" + }, + "main": "template.json", + "files": [ + "template", + "template.json" + ], + "publishConfig": { + "access": "public" + }, + "scripts": { + "prepare": "exit 0" + } +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template.json b/packages/cra-template-apps-typescript-starter-kit/template.json new file mode 100644 index 00000000..b882edca --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template.json @@ -0,0 +1,25 @@ +{ + "package": { + "dependencies": { + "@datadog/ui-extensions-react": "0.31.0", + "@datadog/ui-extensions-sdk": "0.31.0", + "@types/node": "^16.7.13", + "@types/react": "^17.0.43", + "@types/react-dom": "^17.0.14", + "milligram": "^1.4.1", + "typeface-roboto": "^1.1.13", + "typescript": "^4.4.2" + }, + "eslintConfig": { + "extends": ["react-app", "react-app/jest"] + }, + "browserslist": { + "production": [">0.2%", "not dead", "not op_mini all"], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } + } +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template/.prettierignore b/packages/cra-template-apps-typescript-starter-kit/template/.prettierignore new file mode 100644 index 00000000..0c50478f --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/.prettierignore @@ -0,0 +1,3 @@ +build +CHANGELOG.md +dist diff --git a/packages/cra-template-apps-typescript-starter-kit/template/LICENSE b/packages/cra-template-apps-typescript-starter-kit/template/LICENSE new file mode 100644 index 00000000..1f9985e0 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-Present Datadog, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/cra-template-apps-typescript-starter-kit/template/README.md b/packages/cra-template-apps-typescript-starter-kit/template/README.md new file mode 100644 index 00000000..b908388c --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/README.md @@ -0,0 +1,70 @@ +# Datadog UI App TypeScript+React Starter Kit + +This project was generated via the [Datadog UI Apps TypeScript Starter Kit](https://github.com/datadog/apps/packages/cra-template-apps-typescript-starter-kit) [`create-react-app`](https://create-react-app.dev/) [custom template](https://create-react-app.dev/docs/custom-templates). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can't go back!** + +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. + +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/packages/cra-template-apps-typescript-starter-kit/template/app_manifest.json b/packages/cra-template-apps-typescript-starter-kit/template/app_manifest.json new file mode 100644 index 00000000..22854671 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/app_manifest.json @@ -0,0 +1,98 @@ +{ + "schemaVersion": "v2", + "display_on_public_website": false, + "app_id": null, + "support_type": "partner", + "tile": { + "description": "A hello-world like application used as a starting point for apps", + "logo_media": { + "light": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Emojione_1F44B.svg/1024px-Emojione_1F44B.svg.png" + }, + "title": "Your first app!" + }, + "author": {}, + "pricing": [], + "legal_terms": {}, + "proxy_scopes": [], + "assets": { + "ui_extensions": { + "debug_mode_url": "http://localhost:3000", + "secured": false, + "main_url": "http://localhost:3000", + "api_version": "v1.0", + "features": [ + { + "name": "dashboard_custom_widget", + "options": { + "widgets": [ + { + "name": "Your first app", + "has_title": true, + "custom_widget_key": "your_first_app", + "source": "widget", + "options": [ + { + "enum": [ + "system.cpu.idle", + "system.load.1", + "system.load.5", + "system.load.15" + ], + "type": "string", + "name": "metric", + "label": "Your favorite metric" + }, + { + "enum": [ + "Chevre", + "Gruyere", + "Mozzarella" + ], + "type": "string", + "name": "favorite-cheese", + "label": "Your favorite cheese" + } + ], + "icon": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Emojione_1F44B.svg/1024px-Emojione_1F44B.svg.png" + } + ] + } + }, + { + "name": "dashboard_cog_menu", + "options": { + "items": [ + { + "action_type": "event", + "key": "open-confirmation", + "label": "Please confirm" + }, + { + "action_type": "event", + "key": "open-custom-modal", + "label": "Open a custom modal" + }, + { + "action_type": "event", + "key": "open-custom-panel", + "label": "Open a custom side panel with args" + } + ] + } + }, + { + "name": "modals", + "options": {} + }, + { + "name": "side_panels", + "options": {} + }, + { + "name": "widget_context_menu", + "options": { "items": [] } + } + ] + } + } +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template/gitignore b/packages/cra-template-apps-typescript-starter-kit/template/gitignore new file mode 100644 index 00000000..b8fba009 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js +.eslintcache + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/packages/cra-template-apps-typescript-starter-kit/template/public/_redirects b/packages/cra-template-apps-typescript-starter-kit/template/public/_redirects new file mode 100644 index 00000000..2ccd43ba --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/public/_redirects @@ -0,0 +1,3 @@ +/widget /index.html 200 +/modal /index.html 200 +/panel /index.html 200 \ No newline at end of file diff --git a/packages/cra-template-apps-typescript-starter-kit/template/public/favicon.ico b/packages/cra-template-apps-typescript-starter-kit/template/public/favicon.ico new file mode 100644 index 00000000..a11777cc Binary files /dev/null and b/packages/cra-template-apps-typescript-starter-kit/template/public/favicon.ico differ diff --git a/packages/cra-template-apps-typescript-starter-kit/template/public/index.html b/packages/cra-template-apps-typescript-starter-kit/template/public/index.html new file mode 100644 index 00000000..0d815837 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/public/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + Datadog UI App + + + +
+ + diff --git a/packages/cra-template-apps-typescript-starter-kit/template/public/robots.txt b/packages/cra-template-apps-typescript-starter-kit/template/public/robots.txt new file mode 100644 index 00000000..e9e57dc4 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/controller/dashboard-cog-menu.ts b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/dashboard-cog-menu.ts new file mode 100644 index 00000000..40456a60 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/dashboard-cog-menu.ts @@ -0,0 +1,115 @@ +import { + DDClient, + EventType, + ModalSize, + ModalActionLevel, + MenuItemType +} from '@datadog/ui-extensions-sdk'; + +export const setupDashboardCogMenu = (client: DDClient) => { + // provide cog menu items dynamically if needed + client.dashboard.cogMenu.onRequest(() => { + return { + items: [ + { + actionType: MenuItemType.LINK, + href: 'https://google.com', + label: 'link to google', + key: 'link', + order: -1 + } + ] + }; + }); + + client.events.on(EventType.WIDGET_SETTINGS_MENU_CLICK, context => { + if (context.menuItem.key === 'open-confirmation') { + client.modal.open({ + actionLabel: 'Yes', + cancelLabel: 'Nevermind', + title: 'Please verify!', + key: 'confirmation-modal', + actionLevel: ModalActionLevel.DANGER, + message: 'Are you sure really sure?' + }); + } + + // open an iframe modal defined inline here in controller + if (context.menuItem.key === 'open-custom-modal') { + client.modal.open( + { + key: 'custom-modal', + size: ModalSize.LARGE, + source: 'modal' + }, + { + message: + 'Hi! I was sent here from the custom widget settings menu 👋', + options: context.widget.definition.options + } + ); + } + + // open an iframe side panel defined inline here in controller + if (context.menuItem.key === 'open-custom-panel') { + console.log('xxxx context', context); + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel', + title: 'Custom Sidepanel' + }, + { + message: + 'Hi! I was sent here from the custom widget settings menu 👋', + options: context.widget.definition.options + } + ); + } + }); + + // listen for cog menu click events + client.events.on(EventType.DASHBOARD_COG_MENU_CLICK, context => { + if (context.menuItem.key === 'open-confirmation') { + client.modal.open({ + actionLabel: 'Yes', + cancelLabel: 'Nevermind', + title: 'Please verify!', + key: 'confirmation-modal', + actionLevel: ModalActionLevel.DANGER, + message: 'Are you sure really sure?' + }); + } + + // open an iframe modal defined inline here in controller + if (context.menuItem.key === 'open-custom-modal') { + client.modal.open( + { + key: 'custom-modal', + size: ModalSize.LARGE, + source: 'modal' + }, + { + message: + 'Hi! I was sent here from the dashboard cog menu 👋' + } + ); + } + + // open an iframe side panel defined inline here in controller + if (context.menuItem.key === 'open-custom-panel') { + console.log('xxxx context', context); + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel', + title: 'Custom Sidepanel' + }, + { + message: + 'Hi! I was sent here from the dashboard cog menu 👋' + } + ); + } + }); +}; diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/controller/index.ts b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/index.ts new file mode 100644 index 00000000..c06d15e9 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/index.ts @@ -0,0 +1,23 @@ +import { init } from '@datadog/ui-extensions-sdk'; + +import { setupDashboardCogMenu } from './dashboard-cog-menu'; +import { setupModal } from './modal'; +import { setupWidgetCtxMenu } from './widget-ctx-menu'; + +export default function setup() { + const client = init(); + setupModal(client); + setupWidgetCtxMenu(client); + setupDashboardCogMenu(client); + + const root = document.getElementById('root'); + if (!root) { + return; + } + root.innerHTML = ` +
+ The application controller is running in the background. +
+ Click here to open your widget + `; +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/controller/modal.ts b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/modal.ts new file mode 100644 index 00000000..9eaeb423 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/modal.ts @@ -0,0 +1,21 @@ +import { DDClient, EventType } from '@datadog/ui-extensions-sdk'; + +export const setupModal = (client: DDClient) => { + // listen for modal events + client.events.on(EventType.MODAL_ACTION, () => { + console.log('Confirmed!'); + }); + + client.events.on(EventType.MODAL_CANCEL, () => { + console.log('Denied!'); + }); + + client.events.on(EventType.MODAL_CLOSE, definition => { + console.log(`User exited modal ${definition.key}`); + }); + + // listen for a custom event sent from modal IFrame + client.events.onCustom('modal_button_click', (count: number) => { + console.log(`The user has clicked the button ${count} times`); + }); +}; diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/controller/widget-ctx-menu.ts b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/widget-ctx-menu.ts new file mode 100644 index 00000000..9d8465a2 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/controller/widget-ctx-menu.ts @@ -0,0 +1,42 @@ +import { MenuItemType, EventType, DDClient } from '@datadog/ui-extensions-sdk'; + +export const setupWidgetCtxMenu = (client: DDClient) => { + // provide widget context menu items dynamically + client.widgetContextMenu.onRequest(({ widget }) => { + return { + items: [ + { + href: `https://docs.datadoghq.com/dashboards/widgets/${widget.definition.type}/`, + actionType: MenuItemType.LINK, + key: 'link-item', + label: `Read about ${widget.definition.type} widgets`, + order: 3 + }, + { + actionType: MenuItemType.EVENT, + // this key is used below to determine which action to take upon click + key: 'sidepanel-trigger', + label: `Open a sidepanel`, + order: 1 + } + ] + }; + }); + + // listen for ctx menu click events + + client.events.on(EventType.WIDGET_CONTEXT_MENU_CLICK, context => { + if (context.menuItem.key === 'sidepanel-trigger') { + client.sidePanel.open( + { + key: 'custom-panel-from-controller', + source: 'panel' + }, + { + message: + 'Hi! I was sent here from the widget context menu 👋' + } + ); + } + }); +}; diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/index.tsx b/packages/cra-template-apps-typescript-starter-kit/template/src/index.tsx new file mode 100644 index 00000000..0e9508c0 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/index.tsx @@ -0,0 +1,23 @@ +const init = async () => { + switch (window.location.pathname) { + case '/widget': { + const widget = await import('./widget'); + return widget.default(); + } + case '/panel': { + const sidepanel = await import('./side-panel'); + return sidepanel.default(); + } + case '/modal': { + const modal = await import('./modal'); + return modal.default(); + } + default: { + const controller = await import('./controller'); + return controller.default(); + } + } +}; + +init(); +export {}; diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/modal/index.tsx b/packages/cra-template-apps-typescript-starter-kit/template/src/modal/index.tsx new file mode 100644 index 00000000..0430298b --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/modal/index.tsx @@ -0,0 +1,57 @@ +import { useContext } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React, { useState } from 'react'; + +const client = init(); + +function Modal() { + const [clickCount, setClickCount] = useState(0); + const context = useContext(client); + const args = context?.args; + + const onClick = () => { + setClickCount(clickCount + 1); + + client.events.broadcast('modal_button_click', clickCount + 1); + }; + + return ( +
+

+ This modal was opened programatically from the main app + controller with these args +

+
+

+ {JSON.stringify(args)} +

+
+ +
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/react-app-env.d.ts b/packages/cra-template-apps-typescript-starter-kit/template/src/react-app-env.d.ts new file mode 100644 index 00000000..6431bc5f --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/side-panel/index.tsx b/packages/cra-template-apps-typescript-starter-kit/template/src/side-panel/index.tsx new file mode 100644 index 00000000..9cf99890 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/side-panel/index.tsx @@ -0,0 +1,37 @@ +import { useContext } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React from 'react'; + +const client = init(); + +function SidePanel() { + const context = useContext(client); + + const args = context?.args; + + return ( +
+

This side panel was opened programatically with these args

+
+

+ {JSON.stringify(args)} +

+
+
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-typescript-starter-kit/template/src/widget/index.tsx b/packages/cra-template-apps-typescript-starter-kit/template/src/widget/index.tsx new file mode 100644 index 00000000..4d503b61 --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/template/src/widget/index.tsx @@ -0,0 +1,59 @@ +import 'milligram'; +import 'typeface-roboto'; +import { useCustomWidgetOptionString } from '@datadog/ui-extensions-react'; +import { init } from '@datadog/ui-extensions-sdk'; +import ReactDOM from 'react-dom'; +import React, { useEffect, useState } from 'react'; + +const client = init(); + +function Widget() { + const metric = useCustomWidgetOptionString(client, 'metric'); + const [broadcastClickCount, setBroadcastClickCount] = useState(0); + + useEffect(() => { + client.events.onCustom('modal_button_click', setBroadcastClickCount); + }, []); + + const onOpenSidePanel = (args: any) => { + client.sidePanel.open( + { + source: 'panel', + key: 'custom-side-panel', + title: 'Custom Sidepanel' + }, + { metric } + ); + }; + + return ( +
+

Hello App Developer! 👋

+

Welcome to your first Datadog application.

+

+ Your favorite metric is: {metric} +

+

+ You can open a side panel programatically and pass to it your + favorite metric by clicking{' '} + {' '} +

+

+ The red button in the modal has been clicked:{' '} + {broadcastClickCount} time(s) +

+
+ ); +} + +export default function render() { + ReactDOM.render( + {}, + document.getElementById('root') + ); +} diff --git a/packages/cra-template-apps-typescript-starter-kit/tsconfig.json b/packages/cra-template-apps-typescript-starter-kit/tsconfig.json new file mode 100644 index 00000000..702684db --- /dev/null +++ b/packages/cra-template-apps-typescript-starter-kit/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": ["src"] +} diff --git a/yarn.lock b/yarn.lock index 509ef225..c63d08c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1453,6 +1453,9 @@ dependencies: postcss-value-parser "^4.2.0" +"@datadog/cra-template-apps-starter-kit@file:/Users/eric.allen/Development/apps/packages/cra-template-apps-starter-kit": + version "1.0.0" + "@datadog/datadog-api-client@^1.0.0-beta.5", "@datadog/datadog-api-client@^1.0.0-beta.6": version "1.0.0-beta.9" resolved "https://registry.yarnpkg.com/@datadog/datadog-api-client/-/datadog-api-client-1.0.0-beta.9.tgz#90c87e54c40b01bfaed6d4df57e64026b0a19e1d" @@ -1503,6 +1506,18 @@ dependencies: protobufjs "^6.10.2" +"@datadog/ui-extensions-react@^0.31.0": + version "0.31.0" + resolved "https://registry.yarnpkg.com/@datadog/ui-extensions-react/-/ui-extensions-react-0.31.0.tgz#319b86c842a21598b744d79fc484511a447fd6de" + integrity sha512-+S68mtPevAWPVLCX2RIR5+9jW/pXXmY7mh3r2EKrKizEBa9D8rWdBeZpkI95I2+Q93cSzFj+sQGYnqLkk0L4mg== + +"@datadog/ui-extensions-sdk@^0.31.0": + version "0.31.0" + resolved "https://registry.yarnpkg.com/@datadog/ui-extensions-sdk/-/ui-extensions-sdk-0.31.0.tgz#057c5f0d5ea8a96fa43ecf7d4bc0904b445c2dd5" + integrity sha512-iBo6QhbPHSe3V2iSEx0N42ORUb+aLZFarAq0//375y3UqO5Bhbbru8QBIP1WTA2WO0Lvsr+BabYG6DgAiwGAVg== + dependencies: + "@datadog/framepost" "^0.3.0" + "@discoveryjs/json-ext@^0.5.0": version "0.5.7" resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" @@ -3533,7 +3548,7 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.12.tgz#0d4557fd3b94497d793efd4e7d92df2f83b4ef24" integrity sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A== -"@types/node@^16.9.1": +"@types/node@^16.11.26", "@types/node@^16.9.1": version "16.11.26" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.26.tgz#63d204d136c9916fb4dcd1b50f9740fe86884e47" integrity sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ== @@ -3583,7 +3598,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== -"@types/react-dom@*", "@types/react-dom@>=16.9.0", "@types/react-dom@^17.0.0": +"@types/react-dom@*", "@types/react-dom@>=16.9.0", "@types/react-dom@^17.0.0", "@types/react-dom@^17.0.14": version "17.0.14" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.14.tgz#c8f917156b652ddf807711f5becbd2ab018dea9f" integrity sha512-H03xwEP1oXmSfl3iobtmQ/2dHF5aBHr8aUMwyGZya6OW45G+xtdzmq6HkncefiBt5JU8DVyaWl/nWZbjZCnzAQ== @@ -3597,7 +3612,7 @@ dependencies: "@types/react" "*" -"@types/react@*", "@types/react@>=16.9.0", "@types/react@^17.0.0", "@types/react@^17.0.21": +"@types/react@*", "@types/react@>=16.9.0", "@types/react@^17.0.0", "@types/react@^17.0.21", "@types/react@^17.0.43": version "17.0.43" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.43.tgz#4adc142887dd4a2601ce730bc56c3436fdb07a55" integrity sha512-8Q+LNpdxf057brvPu1lMtC5Vn7J119xrP1aq4qiaefNioQUYANF/CYeK4NsKorSZyUGJ66g0IM+4bbjwx45o2A== @@ -16319,7 +16334,7 @@ typescript@4.5.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8" integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg== -typescript@^4.1.2, typescript@^4.1.3, typescript@^4.4.3, typescript@^4.5.4: +typescript@^4.1.2, typescript@^4.1.3, typescript@^4.4.3, typescript@^4.5.4, typescript@^4.6.3: version "4.6.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c" integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==