diff --git a/.circleci/config.yml b/.circleci/config.yml index 7b6b4a6f05..0dcca1d322 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,11 +2,15 @@ version: 2.1 executors: pw-focal-development: docker: - - image: mcr.microsoft.com/playwright:v1.25.2-focal + - image: mcr.microsoft.com/playwright:v1.39.0-focal environment: NODE_ENV: development # Needed to ensure 'dist' folder created and devDependencies installed - PERCY_POSTINSTALL_BROWSER: 'true' # Needed to store the percy browser in cache deps - PERCY_LOGLEVEL: 'debug' # Enable DEBUG level logging for Percy (Issue: https://github.com/nasa/openmct/issues/5742) + PERCY_POSTINSTALL_BROWSER: "true" # Needed to store the percy browser in cache deps + PERCY_LOGLEVEL: "debug" # Enable DEBUG level logging for Percy (Issue: https://github.com/nasa/openmct/issues/5742) + ubuntu: + machine: + image: ubuntu-2204:current + docker_layer_caching: true parameters: BUST_CACHE: description: "Set this with the CircleCI UI Trigger Workflow button (boolean = true) to bust the cache!" @@ -23,9 +27,8 @@ commands: - restore_cache_cmd: node-version: << parameters.node-version >> - node/install: - install-npm: true node-version: << parameters.node-version >> - - run: npm install --prefer-offline --no-audit --progress=false + - run: npm install --no-audit --progress=false restore_cache_cmd: description: "Custom command for restoring cache with the ability to bust cache. When BUST_CACHE is set to true, jobs will not restore cache" parameters: @@ -34,10 +37,10 @@ commands: steps: - when: condition: - equal: [false, << pipeline.parameters.BUST_CACHE >> ] + equal: [false, << pipeline.parameters.BUST_CACHE >>] steps: - restore_cache: - key: deps-{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} + key: deps--{{ arch }}--{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} save_cache_cmd: description: "Custom command for saving cache." parameters: @@ -45,7 +48,7 @@ commands: type: string steps: - save_cache: - key: deps-{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} + key: deps--{{ arch }}--{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} paths: - ~/.npm - node_modules @@ -53,23 +56,23 @@ commands: description: "Track important packages and files" steps: - run: | - mkdir /tmp/artifacts - printenv NODE_ENV >> /tmp/artifacts/NODE_ENV.txt + [[ $EUID -ne 0 ]] && (sudo mkdir -p /tmp/artifacts && sudo chmod 777 /tmp/artifacts) || (mkdir -p /tmp/artifacts && chmod 777 /tmp/artifacts) + printenv NODE_ENV >> /tmp/artifacts/NODE_ENV.txt || true npm -v >> /tmp/artifacts/npm-version.txt node -v >> /tmp/artifacts/node-version.txt ls -latR >> /tmp/artifacts/dir.txt - store_artifacts: path: /tmp/artifacts/ generate_e2e_code_cov_report: - description: "Generate e2e code coverage artifacts and publish to codecov.io. Needed to that we can ignore the exit code status of the npm run test" - parameters: + description: "Generate e2e code coverage artifacts and publish to codecov.io. Needed to that we can ignore the exit code status of the npm run test" + parameters: suite: type: string - steps: - - run: npm run cov:e2e:report || true - - run: npm run cov:e2e:<>:publish + steps: + - run: npm run cov:e2e:report || true + - run: npm run cov:e2e:<>:publish orbs: - node: circleci/node@4.9.0 + node: circleci/node@5.1.0 browser-tools: circleci/browser-tools@1.3.0 jobs: npm-audit: @@ -102,7 +105,11 @@ jobs: node-version: <> - browser-tools/install-chrome: replace-existing: false - - run: npm run test + - run: + command: | + mkdir -p dist/reports/tests/ + TESTFILES=$(circleci tests glob "src/**/*Spec.js") + echo "$TESTFILES" | circleci tests run --command="xargs npm run test" --verbose - run: npm run cov:unit:publish - save_cache_cmd: node-version: <> @@ -110,26 +117,36 @@ jobs: path: dist/reports/tests/ - store_artifacts: path: coverage - - generate_and_store_version_and_filesystem_artifacts + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts e2e-test: parameters: - node-version: - type: string suite: #stable or full type: string executor: pw-focal-development - parallelism: 4 + parallelism: 7 steps: - build_and_install: - node-version: <> + node-version: lts/hydrogen - when: #Only install chrome-beta when running the 'full' suite to save $$$ condition: - equal: [ "full", <> ] + equal: ["full", <>] steps: - run: npx playwright install chrome-beta - - run: SHARD="$((${CIRCLE_NODE_INDEX}+1))"; npm run test:e2e:<> -- --shard=${SHARD}/${CIRCLE_NODE_TOTAL} - - generate_e2e_code_cov_report: - suite: <> + - run: + command: | + mkdir test-results + TESTFILES=$(circleci tests glob "e2e/**/*.spec.js") + echo "$TESTFILES" | circleci tests run --command="xargs npm run test:e2e:<>" --verbose --split-by=timings + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: <> - store_test_results: path: test-results/results.xml - store_artifacts: @@ -138,78 +155,161 @@ jobs: path: coverage - store_artifacts: path: html-test-results - - generate_and_store_version_and_filesystem_artifacts + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + e2e-mobile: + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:e2e:mobile + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: full + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: coverage + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + e2e-couchdb: + executor: ubuntu + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npx playwright@1.39.0 install #Necessary for bare ubuntu machine + - run: | + export $(cat src/plugins/persistence/couch/.env.ci | xargs) + docker-compose -f src/plugins/persistence/couch/couchdb-compose.yaml up --detach + sleep 3 + bash src/plugins/persistence/couch/setup-couchdb.sh + - run: sh src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.sh #Replace LocalStorage Plugin with CouchDB + - run: npm run test:e2e:couchdb + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: full #add to full suite + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: coverage + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + mem-test: + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:perf:memory + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts perf-test: - parameters: - node-version: - type: string executor: pw-focal-development steps: - build_and_install: - node-version: <> - - run: npm run test:perf + node-version: lts/hydrogen + - run: npm run test:perf:localhost + - run: npm run test:perf:contract - store_test_results: path: test-results/results.xml - store_artifacts: path: test-results - store_artifacts: path: html-test-results - - generate_and_store_version_and_filesystem_artifacts - visual-test: + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + visual-a11y-tests: parameters: - node-version: - type: string + suite: + type: string # ci or full executor: pw-focal-development steps: - build_and_install: - node-version: <> - - run: npm run test:e2e:visual + node-version: lts/hydrogen + - run: npm run test:e2e:visual:<> - store_test_results: path: test-results/results.xml - store_artifacts: path: test-results - store_artifacts: path: html-test-results - - generate_and_store_version_and_filesystem_artifacts + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + workflows: overall-circleci-commit-status: #These jobs run on every commit jobs: - lint: - name: node14-lint - node-version: lts/fermium + name: node20-lint + node-version: lts/iron - unit-test: name: node18-chrome - node-version: "18" + node-version: lts/hydrogen - e2e-test: name: e2e-stable - node-version: lts/gallium suite: stable - - perf-test: - node-version: lts/gallium - - visual-test: - node-version: lts/gallium - + - e2e-mobile + - visual-a11y-tests: + name: visual-a11y-test-ci + suite: ci + the-nightly: #These jobs do not run on PRs, but against master at night jobs: - unit-test: - name: node14-chrome-nightly - node-version: lts/fermium - - unit-test: - name: node16-chrome-nightly - node-version: lts/gallium + name: node20-chrome-nightly + node-version: lts/iron - unit-test: name: node18-chrome - node-version: "18" + node-version: lts/hydrogen - npm-audit: - node-version: lts/gallium + node-version: lts/hydrogen - e2e-test: name: e2e-full-nightly - node-version: lts/gallium suite: full - - perf-test: - node-version: lts/gallium - - visual-test: - node-version: lts/gallium + - e2e-mobile + - perf-test + - mem-test + - visual-a11y-tests: + name: visual-a11y-test-nightly + suite: full + - e2e-couchdb triggers: - schedule: cron: "0 0 * * *" diff --git a/.cspell.json b/.cspell.json new file mode 100644 index 0000000000..9afde5db7c --- /dev/null +++ b/.cspell.json @@ -0,0 +1,513 @@ +{ + "version": "0.2", + "language": "en,en-us", + "words": [ + "gress", + "doctoc", + "minmax", + "openmct", + "datasources", + "recieved", + "evalute", + "Sinewave", + "deregistration", + "unregisters", + "configutation", + "configuation", + "codecov", + "carryforward", + "Chacon", + "Straub", + "OWASP", + "Testathon", + "exploratorily", + "Testathons", + "testathon", + "npmjs", + "publishj", + "treeitem", + "timespan", + "Timespan", + "spinbutton", + "popout", + "textbox", + "tablist", + "Telem", + "codecoverage", + "browserless", + "networkidle", + "nums", + "mgmt", + "faultname", + "gantt", + "sharded", + "perfromance", + "MMOC", + "codegen", + "Unfortuantely", + "viewports", + "updatesnapshots", + "excercised", + "Circel", + "browsercontexts", + "miminum", + "testcase", + "testsuite", + "domcontentloaded", + "Tracefile", + "lcov", + "linecov", + "Browserless", + "webserver", + "yamcs", + "quickstart", + "subobject", + "autosize", + "Horz", + "vehicula", + "Praesent", + "pharetra", + "Duis", + "eget", + "arcu", + "elementum", + "mauris", + "Donec", + "nunc", + "quis", + "Proin", + "elit", + "Nunc", + "Aenean", + "mollis", + "hendrerit", + "Vestibulum", + "placerat", + "velit", + "augue", + "Quisque", + "mattis", + "lectus", + "rutrum", + "Fusce", + "tincidunt", + "nibh", + "blandit", + "urna", + "Nullam", + "congue", + "enim", + "Morbi", + "bibendum", + "Vivamus", + "imperdiet", + "Pellentesque", + "cursus", + "Aliquam", + "orci", + "Suspendisse", + "amet", + "justo", + "Etiam", + "vestibulum", + "ullamcorper", + "Cras", + "aliquet", + "Mauris", + "Nulla", + "scelerisque", + "viverra", + "metus", + "condimentum", + "varius", + "nulla", + "sapien", + "Curabitur", + "tristique", + "Nonsectetur", + "convallis", + "accumsan", + "lacus", + "posuere", + "turpis", + "egestas", + "feugiat", + "tortor", + "faucibus", + "euismod", + "pratices", + "pathing", + "pases", + "testcases", + "Noneditable", + "listitem", + "Gantt", + "timelist", + "timestrip", + "networkevents", + "fetchpriority", + "persistable", + "Persistable", + "persistability", + "Persistability", + "testdata", + "Testdata", + "metdata", + "timeconductor", + "contenteditable", + "autoscale", + "Autoscale", + "prepan", + "sinewave", + "cyanish", + "driv", + "searchbox", + "datetime", + "timeframe", + "recents", + "recentobjects", + "gsearch", + "Disp", + "Cloc", + "noselect", + "requestfailed", + "viewlarge", + "Imageurl", + "thumbstrip", + "checkmark", + "Unshelve", + "autosized", + "chacskaylo", + "numberfield", + "OPENMCT", + "Autoflow", + "Timelist", + "faultmanagement", + "GEOSPATIAL", + "geospatial", + "plotspatial", + "annnotation", + "keystrings", + "undelete", + "sometag", + "containee", + "composability", + "mutables", + "Mutables", + "composee", + "handleoutsideclick", + "Datetime", + "Perc", + "autodismiss", + "filetree", + "deeptailor", + "keystring", + "reindex", + "unlisten", + "symbolsfont", + "ellipsize", + "dismissable", + "TIMESYSTEM", + "Metadatas", + "stalenes", + "receieves", + "unsub", + "callbacktwo", + "unsubscribetwo", + "telem", + "Telemetery", + "unemitted", + "granually", + "timesystem", + "metadatas", + "iteratees", + "metadatum", + "printj", + "sprintf", + "unlisteners", + "amts", + "reregistered", + "hudsonfoo", + "onclone", + "autoflow", + "xdescribe", + "mockmct", + "Autoflowed", + "plotly", + "relayout", + "Plotly", + "Yaxis", + "showlegend", + "textposition", + "xaxis", + "automargin", + "fixedrange", + "yaxis", + "Axistype", + "showline", + "bglayer", + "autorange", + "hoverinfo", + "dotful", + "Dotful", + "cartesianlayer", + "scatterlayer", + "textfont", + "ampm", + "cdef", + "horz", + "STYLEABLE", + "styleable", + "afff", + "shdw", + "braintree", + "vals", + "Subobject", + "Shdw", + "Movebar", + "inspectable", + "Stringformatter", + "sclk", + "Objectpath", + "Keystring", + "duplicatable", + "composees", + "Composees", + "Composee", + "callthrough", + "objectpath", + "createable", + "noneditable", + "Classname", + "classname", + "selectedfaults", + "accum", + "newpersisted", + "Metadatum", + "MCWS", + "YAMCS", + "frameid", + "containerid", + "mmgis", + "PERC", + "curval", + "viewbox", + "mutablegauge", + "Flatbush", + "flatbush", + "Indicies", + "Marqueed", + "NSEW", + "nsew", + "vrover", + "gimbled", + "Pannable", + "unsynced", + "Unsynced", + "pannable", + "autoscroll", + "TIMESTRIP", + "TWENTYFOUR", + "FULLSIZE", + "intialize", + "Timestrip", + "spyon", + "Unlistener", + "multipane", + "DATESTRING", + "akhenry", + "Niklas", + "Hertzen", + "Kash", + "Nouroozi", + "Bostock", + "BOSTOCK", + "Arnout", + "Kazemier", + "Karolis", + "Narkevicius", + "Ashkenas", + "Madhavan", + "Iskren", + "Ivov", + "Chernev", + "Borshchov", + "painterro", + "sheetjs", + "Yuxi", + "ACITON", + "localstorage", + "Linkto", + "Painterro", + "Editability", + "filteredsnapshots", + "Fromimage", + "muliple", + "notebookstorage", + "Andpage", + "pixelize", + "Quickstart", + "indexhtml", + "youradminpassword", + "chttpd", + "sourcefiles", + "USERPASS", + "XPUT", + "adipiscing", + "eiusmod", + "tempor", + "incididunt", + "labore", + "dolore", + "aliqua", + "perspiciatis", + "iteree", + "submodels", + "symlog", + "Plottable", + "antisymlog", + "docstrings", + "webglcontextlost", + "gridlines", + "Xaxis", + "Crosshairs", + "telemetrylimit", + "xscale", + "yscale", + "untracks", + "swatched", + "NULLVALUE", + "unobserver", + "unsubscriber", + "drap", + "Averager", + "averager", + "movecolumnfromindex", + "callout", + "Konqueror", + "unmark", + "hitarea", + "Hitarea", + "Unmark", + "controlbar", + "reactified", + "perc", + "DHMS", + "timespans", + "timeframes", + "Timesystems", + "Hilite", + "datetimes", + "momentified", + "ucontents", + "TIMELIST", + "Timeframe", + "Guirk", + "resizeable", + "iframing", + "Btns", + "Ctrls", + "Chakra", + "Petch", + "propor", + "phoneandtablet", + "desktopandtablet", + "Imgs", + "UNICODES", + "datatable", + "csvg", + "cpath", + "cellipse", + "xlink", + "cstyle", + "bfill", + "ctitle", + "eicon", + "interactability", + "AFFORDANCES", + "affordance", + "scrollcontainer", + "Icomoon", + "icomoon", + "configurability", + "btns", + "AUTOFLOW", + "DATETIME", + "infobubble", + "thumbsbubble", + "codehilite", + "vscroll", + "bgsize", + "togglebutton", + "Hacskaylo", + "noie", + "fullscreen", + "horiz", + "menubutton", + "SNAPSHOTTING", + "snapshotting", + "PAINTERRO", + "ptro", + "PLOTLY", + "gridlayer", + "xtick", + "ytick", + "subobjects", + "Ucontents", + "Userand", + "Userbefore", + "brdr", + "pushs", + "ALPH", + "Recents", + "Qbert", + "Infobubble", + "haslink", + "VPID", + "vpid", + "updatedtest", + "KHTML", + "Chromezilla", + "Safarifox", + "deregistering", + "hundredtized", + "dhms", + "unthrottled", + "Codecov", + "dont", + "mediump", + "sinonjs", + "generatedata", + "grandsearch", + "websockets", + "swgs", + "memlab", + "devmode", + "blockquote", + "blockquotes", + "Blockquote", + "Blockquotes", + "oger", + "lcovonly", + "gcov", + "WCAG", + "stackedplot", + "Andale", + "unnormalized", + "checksnapshots", + "specced", + "composables", + "countup" + ], + "dictionaries": ["npm", "softwareTerms", "node", "html", "css", "bash", "en_US", "en-gb", "misc"], + "ignorePaths": [ + "package.json", + "dist/**", + "package-lock.json", + "node_modules", + "coverage", + "*.log", + "html-test-results", + "test-results" + ] +} diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000000..e29c587925 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,181 @@ +const LEGACY_FILES = ['example/**']; +module.exports = { + env: { + browser: true, + es6: true, + jasmine: true, + amd: true + }, + globals: { + _: 'readonly' + }, + plugins: ['prettier', 'unicorn', 'simple-import-sort'], + extends: [ + 'eslint:recommended', + 'plugin:compat/recommended', + 'plugin:vue/vue3-recommended', + 'plugin:you-dont-need-lodash-underscore/compatible', + 'plugin:prettier/recommended', + 'plugin:no-unsanitized/DOM' + ], + parser: 'vue-eslint-parser', + parserOptions: { + parser: '@babel/eslint-parser', + requireConfigFile: false, + allowImportExportEverywhere: true, + ecmaVersion: 2015, + ecmaFeatures: { + impliedStrict: true + } + }, + rules: { + 'simple-import-sort/imports': 'warn', + 'simple-import-sort/exports': 'warn', + 'vue/no-deprecated-dollar-listeners-api': 'warn', + 'vue/no-deprecated-events-api': 'warn', + 'vue/no-v-for-template-key': 'off', + 'vue/no-v-for-template-key-on-child': 'error', + 'prettier/prettier': 'error', + 'you-dont-need-lodash-underscore/omit': 'off', + 'you-dont-need-lodash-underscore/throttle': 'off', + 'you-dont-need-lodash-underscore/flatten': 'off', + 'you-dont-need-lodash-underscore/get': 'off', + 'no-bitwise': 'error', + curly: 'error', + eqeqeq: 'error', + 'guard-for-in': 'error', + 'no-extend-native': 'error', + 'no-inner-declarations': 'off', + 'no-use-before-define': ['error', 'nofunc'], + 'no-caller': 'error', + 'no-irregular-whitespace': 'error', + 'no-new': 'error', + 'no-shadow': 'error', + 'no-undef': 'error', + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'none' + } + ], + 'no-console': 'off', + 'new-cap': [ + 'error', + { + capIsNew: false, + properties: false + } + ], + 'dot-notation': 'error', + + // https://eslint.org/docs/rules/no-case-declarations + 'no-case-declarations': 'error', + // https://eslint.org/docs/rules/max-classes-per-file + 'max-classes-per-file': ['error', 1], + // https://eslint.org/docs/rules/no-eq-null + 'no-eq-null': 'error', + // https://eslint.org/docs/rules/no-eval + 'no-eval': 'error', + // https://eslint.org/docs/rules/no-implicit-globals + 'no-implicit-globals': 'error', + // https://eslint.org/docs/rules/no-implied-eval + 'no-implied-eval': 'error', + // https://eslint.org/docs/rules/no-lone-blocks + 'no-lone-blocks': 'error', + // https://eslint.org/docs/rules/no-loop-func + 'no-loop-func': 'error', + // https://eslint.org/docs/rules/no-new-func + 'no-new-func': 'error', + // https://eslint.org/docs/rules/no-new-wrappers + 'no-new-wrappers': 'error', + // https://eslint.org/docs/rules/no-octal-escape + 'no-octal-escape': 'error', + // https://eslint.org/docs/rules/no-proto + 'no-proto': 'error', + // https://eslint.org/docs/rules/no-return-await + 'no-return-await': 'error', + // https://eslint.org/docs/rules/no-script-url + 'no-script-url': 'error', + // https://eslint.org/docs/rules/no-self-compare + 'no-self-compare': 'error', + // https://eslint.org/docs/rules/no-sequences + 'no-sequences': 'error', + // https://eslint.org/docs/rules/no-unmodified-loop-condition + 'no-unmodified-loop-condition': 'error', + // https://eslint.org/docs/rules/no-useless-call + 'no-useless-call': 'error', + // https://eslint.org/docs/rules/no-nested-ternary + 'no-nested-ternary': 'error', + // https://eslint.org/docs/rules/no-useless-computed-key + 'no-useless-computed-key': 'error', + // https://eslint.org/docs/rules/no-var + 'no-var': 'error', + // https://eslint.org/docs/rules/one-var + 'one-var': ['error', 'never'], + // https://eslint.org/docs/rules/default-case-last + 'default-case-last': 'error', + // https://eslint.org/docs/rules/default-param-last + 'default-param-last': 'error', + // https://eslint.org/docs/rules/grouped-accessor-pairs + 'grouped-accessor-pairs': 'error', + // https://eslint.org/docs/rules/no-constructor-return + 'no-constructor-return': 'error', + // https://eslint.org/docs/rules/array-callback-return + 'array-callback-return': 'error', + // https://eslint.org/docs/rules/no-invalid-this + 'no-invalid-this': 'error', // Believe this one actually surfaces some bugs + // https://eslint.org/docs/rules/func-style + 'func-style': ['error', 'declaration'], + // https://eslint.org/docs/rules/no-unused-expressions + 'no-unused-expressions': 'error', + // https://eslint.org/docs/rules/no-useless-concat + 'no-useless-concat': 'error', + // https://eslint.org/docs/rules/radix + radix: 'error', + // https://eslint.org/docs/rules/require-await + 'require-await': 'error', + // https://eslint.org/docs/rules/no-alert + 'no-alert': 'error', + // https://eslint.org/docs/rules/no-useless-constructor + 'no-useless-constructor': 'error', + // https://eslint.org/docs/rules/no-duplicate-imports + 'no-duplicate-imports': 'error', + + // https://eslint.org/docs/rules/no-implicit-coercion + 'no-implicit-coercion': 'error', + //https://eslint.org/docs/rules/no-unneeded-ternary + 'no-unneeded-ternary': 'error', + 'unicorn/filename-case': [ + 'error', + { + cases: { + pascalCase: true + }, + ignore: ['^.*\\.js$'] + } + ], + 'vue/first-attribute-linebreak': 'error', + 'vue/multiline-html-element-content-newline': 'off', + 'vue/singleline-html-element-content-newline': 'off', + 'vue/no-mutating-props': 'off' // TODO: Remove this rule and fix resulting errors + }, + overrides: [ + { + files: LEGACY_FILES, + rules: { + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'none', + varsIgnorePattern: 'controller' + } + ], + 'no-nested-ternary': 'off', + 'no-var': 'off', + 'one-var': 'off' + } + } + ] +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 26e8074908..0000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,271 +0,0 @@ -const LEGACY_FILES = ["example/**"]; -module.exports = { - "env": { - "browser": true, - "es6": true, - "jasmine": true, - "amd": true - }, - "globals": { - "_": "readonly" - }, - "extends": [ - "eslint:recommended", - "plugin:compat/recommended", - "plugin:vue/recommended", - "plugin:you-dont-need-lodash-underscore/compatible" - ], - "parser": "vue-eslint-parser", - "parserOptions": { - "parser": "@babel/eslint-parser", - "requireConfigFile": false, - "allowImportExportEverywhere": true, - "ecmaVersion": 2015, - "ecmaFeatures": { - "impliedStrict": true - } - }, - "rules": { - "you-dont-need-lodash-underscore/omit": "off", - "you-dont-need-lodash-underscore/throttle": "off", - "you-dont-need-lodash-underscore/flatten": "off", - "you-dont-need-lodash-underscore/get": "off", - "no-bitwise": "error", - "curly": "error", - "eqeqeq": "error", - "guard-for-in": "error", - "no-extend-native": "error", - "no-inner-declarations": "off", - "no-use-before-define": ["error", "nofunc"], - "no-caller": "error", - "no-irregular-whitespace": "error", - "no-new": "error", - "no-shadow": "error", - "no-undef": "error", - "no-unused-vars": [ - "error", - { - "vars": "all", - "args": "none" - } - ], - "no-console": "off", - "no-trailing-spaces": "error", - "space-before-function-paren": [ - "error", - { - "anonymous": "always", - "asyncArrow": "always", - "named": "never" - } - ], - "array-bracket-spacing": "error", - "space-in-parens": "error", - "space-before-blocks": "error", - "comma-dangle": "error", - "eol-last": "error", - "new-cap": [ - "error", - { - "capIsNew": false, - "properties": false - } - ], - "dot-notation": "error", - "indent": ["error", 4], - - // https://eslint.org/docs/rules/no-case-declarations - "no-case-declarations": "error", - // https://eslint.org/docs/rules/max-classes-per-file - "max-classes-per-file": ["error", 1], - // https://eslint.org/docs/rules/no-eq-null - "no-eq-null": "error", - // https://eslint.org/docs/rules/no-eval - "no-eval": "error", - // https://eslint.org/docs/rules/no-floating-decimal - "no-floating-decimal": "error", - // https://eslint.org/docs/rules/no-implicit-globals - "no-implicit-globals": "error", - // https://eslint.org/docs/rules/no-implied-eval - "no-implied-eval": "error", - // https://eslint.org/docs/rules/no-lone-blocks - "no-lone-blocks": "error", - // https://eslint.org/docs/rules/no-loop-func - "no-loop-func": "error", - // https://eslint.org/docs/rules/no-new-func - "no-new-func": "error", - // https://eslint.org/docs/rules/no-new-wrappers - "no-new-wrappers": "error", - // https://eslint.org/docs/rules/no-octal-escape - "no-octal-escape": "error", - // https://eslint.org/docs/rules/no-proto - "no-proto": "error", - // https://eslint.org/docs/rules/no-return-await - "no-return-await": "error", - // https://eslint.org/docs/rules/no-script-url - "no-script-url": "error", - // https://eslint.org/docs/rules/no-self-compare - "no-self-compare": "error", - // https://eslint.org/docs/rules/no-sequences - "no-sequences": "error", - // https://eslint.org/docs/rules/no-unmodified-loop-condition - "no-unmodified-loop-condition": "error", - // https://eslint.org/docs/rules/no-useless-call - "no-useless-call": "error", - // https://eslint.org/docs/rules/wrap-iife - "wrap-iife": "error", - // https://eslint.org/docs/rules/no-nested-ternary - "no-nested-ternary": "error", - // https://eslint.org/docs/rules/switch-colon-spacing - "switch-colon-spacing": "error", - // https://eslint.org/docs/rules/no-useless-computed-key - "no-useless-computed-key": "error", - // https://eslint.org/docs/rules/rest-spread-spacing - "rest-spread-spacing": ["error"], - // https://eslint.org/docs/rules/no-var - "no-var": "error", - // https://eslint.org/docs/rules/one-var - "one-var": ["error", "never"], - // https://eslint.org/docs/rules/default-case-last - "default-case-last": "error", - // https://eslint.org/docs/rules/default-param-last - "default-param-last": "error", - // https://eslint.org/docs/rules/grouped-accessor-pairs - "grouped-accessor-pairs": "error", - // https://eslint.org/docs/rules/no-constructor-return - "no-constructor-return": "error", - // https://eslint.org/docs/rules/array-callback-return - "array-callback-return": "error", - // https://eslint.org/docs/rules/no-invalid-this - "no-invalid-this": "error", // Believe this one actually surfaces some bugs - // https://eslint.org/docs/rules/func-style - "func-style": ["error", "declaration"], - // https://eslint.org/docs/rules/no-unused-expressions - "no-unused-expressions": "error", - // https://eslint.org/docs/rules/no-useless-concat - "no-useless-concat": "error", - // https://eslint.org/docs/rules/radix - "radix": "error", - // https://eslint.org/docs/rules/require-await - "require-await": "error", - // https://eslint.org/docs/rules/no-alert - "no-alert": "error", - // https://eslint.org/docs/rules/no-useless-constructor - "no-useless-constructor": "error", - // https://eslint.org/docs/rules/no-duplicate-imports - "no-duplicate-imports": "error", - - // https://eslint.org/docs/rules/no-implicit-coercion - "no-implicit-coercion": "error", - //https://eslint.org/docs/rules/no-unneeded-ternary - "no-unneeded-ternary": "error", - // https://eslint.org/docs/rules/semi - "semi": ["error", "always"], - // https://eslint.org/docs/rules/no-multi-spaces - "no-multi-spaces": "error", - // https://eslint.org/docs/rules/key-spacing - "key-spacing": ["error", { - "afterColon": true - }], - // https://eslint.org/docs/rules/keyword-spacing - "keyword-spacing": ["error", { - "before": true, - "after": true - }], - // https://eslint.org/docs/rules/comma-spacing - // Also requires one line code fix - "comma-spacing": ["error", { - "after": true - }], - //https://eslint.org/docs/rules/no-whitespace-before-property - "no-whitespace-before-property": "error", - // https://eslint.org/docs/rules/object-curly-newline - "object-curly-newline": ["error", { - "consistent": true, - "multiline": true - }], - // https://eslint.org/docs/rules/object-property-newline - "object-property-newline": "error", - // https://eslint.org/docs/rules/brace-style - "brace-style": "error", - // https://eslint.org/docs/rules/no-multiple-empty-lines - "no-multiple-empty-lines": ["error", {"max": 1}], - // https://eslint.org/docs/rules/operator-linebreak - "operator-linebreak": ["error", "before", {"overrides": {"=": "after"}}], - // https://eslint.org/docs/rules/padding-line-between-statements - "padding-line-between-statements": ["error", { - "blankLine": "always", - "prev": "multiline-block-like", - "next": "*" - }, { - "blankLine": "always", - "prev": "*", - "next": "return" - }], - // https://eslint.org/docs/rules/space-infix-ops - "space-infix-ops": "error", - // https://eslint.org/docs/rules/space-unary-ops - "space-unary-ops": ["error", { - "words": true, - "nonwords": false - }], - // https://eslint.org/docs/rules/arrow-spacing - "arrow-spacing": "error", - // https://eslint.org/docs/rules/semi-spacing - "semi-spacing": ["error", { - "before": false, - "after": true - }], - - "vue/html-indent": [ - "error", - 4, - { - "attribute": 1, - "baseIndent": 0, - "closeBracket": 0, - "alignAttributesVertically": true, - "ignores": [] - } - ], - "vue/html-self-closing": ["error", - { - "html": { - "void": "never", - "normal": "never", - "component": "always" - }, - "svg": "always", - "math": "always" - } - ], - "vue/max-attributes-per-line": ["error", { - "singleline": 1, - "multiline": 1, - }], - "vue/first-attribute-linebreak": "error", - "vue/multiline-html-element-content-newline": "off", - "vue/singleline-html-element-content-newline": "off", - "vue/multi-word-component-names": "off", // TODO enable, align with conventions - "vue/no-mutating-props": "off" - - }, - "overrides": [ - { - "files": LEGACY_FILES, - "rules": { - "no-unused-vars": [ - "warn", - { - "vars": "all", - "args": "none", - "varsIgnorePattern": "controller" - } - ], - "no-nested-ternary": "off", - "no-var": "off", - "one-var": "off" - } - } - ] -}; diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000000..839df6c0f9 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,16 @@ +# git-blame ignored revisions +# To configure, run: +# git config blame.ignoreRevsFile .git-blame-ignore-revs +# Requires Git > 2.23 +# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt + +# vue-eslint update 2019 +14a0f84c1bcd56886d7c9e4e6afa8f7d292734e5 +# eslint changes 2022 +d80b6923541704ab925abf0047cbbc58735c27e2 +# Copyright year update 2022 +4a9744e916d24122a81092f6b7950054048ba860 +# Copyright year update 2023 +8040b275fcf2ba71b42cd72d4daa64bb25c19c2d +# Apply `prettier` formatting +caa7bc6faebc204f67aedae3e35fb0d0d3ce27a7 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a5525f4ce9..563e893376 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,22 +8,22 @@ Closes -**Table of Contents** +**Table of Contents** -- [Building Applications With Open MCT](#building-applications-with-open-mct) +- [Developing Applications With Open MCT](#developing-applications-with-open-mct) - [Scope and purpose of this document](#scope-and-purpose-of-this-document) - [Building From Source](#building-from-source) - [Starting an Open MCT application](#starting-an-open-mct-application) + - [Types](#types) + - [Using Types](#using-types) + - [Limitations](#limitations) - [Plugins](#plugins) - [Defining and Installing a New Plugin](#defining-and-installing-a-new-plugin) - [Domain Objects and Identifiers](#domain-objects-and-identifiers) @@ -23,7 +26,7 @@ - [Value Hints](#value-hints) - [The Time Conductor and Telemetry](#the-time-conductor-and-telemetry) - [Telemetry Providers](#telemetry-providers) - - [Telemetry Requests and Responses.](#telemetry-requests-and-responses) + - [Telemetry Requests and Responses](#telemetry-requests-and-responses) - [Request Strategies **draft**](#request-strategies-draft) - [`latest` request strategy](#latest-request-strategy) - [`minmax` request strategy](#minmax-request-strategy) @@ -41,8 +44,10 @@ - [Clocks](#clocks) - [Defining and registering clocks](#defining-and-registering-clocks) - [Getting and setting active clock](#getting-and-setting-active-clock) - - [Stopping an active clock](#stopping-an-active-clock) + - [⚠️ \[DEPRECATED\] Stopping an active clock](#️-deprecated-stopping-an-active-clock) - [Clock Offsets](#clock-offsets) + - [Time Modes](#time-modes) + - [Time Mode Helper Methods](#time-mode-helper-methods) - [Time Events](#time-events) - [List of Time Events](#list-of-time-events) - [The Time Conductor](#the-time-conductor) @@ -57,23 +62,22 @@ -# Building Applications With Open MCT +# Developing Applications With Open MCT ## Scope and purpose of this document -This document is intended to serve as a reference for developing an application -based on Open MCT. It will provide details of the API functions necessary to -extend the Open MCT platform meet common use cases such as integrating with a telemetry source. +This document is intended to serve as a reference for developing an application +based on Open MCT. It will provide details of the API functions necessary to +extend the Open MCT platform meet common use cases such as integrating with a telemetry source. -The best place to start is with the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). -These will walk you through the process of getting up and running with Open +The best place to start is with the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). +These will walk you through the process of getting up and running with Open MCT, as well as addressing some common developer use cases. -## Building From Source +## Building From Source -The latest version of Open MCT is available from [our GitHub repository](https://github.com/nasa/openmct). -If you have `git`, and `node` installed, you can build Open MCT with the -commands +The latest version of Open MCT is available from [our GitHub repository](https://github.com/nasa/openmct). +If you have `git`, and `node` installed, you can build Open MCT with the commands ```bash git clone https://github.com/nasa/openmct.git @@ -81,28 +85,31 @@ cd openmct npm install ``` -These commands will fetch the Open MCT source from our GitHub repository, and -build a minified version that can be included in your application. The output -of the build process is placed in a `dist` folder under the openmct source -directory, which can be copied out to another location as needed. The contents -of this folder will include a minified javascript file named `openmct.js` as -well as assets such as html, css, and images necessary for the UI. +These commands will fetch the Open MCT source from our GitHub repository, and +build a minified version that can be included in your application. The output +of the build process is placed in a `dist` folder under the openmct source +directory, which can be copied out to another location as needed. The contents +of this folder will include a minified javascript file named `openmct.js` as +well as assets such as html, css, and images necessary for the UI. ## Starting an Open MCT application -To start a minimally functional Open MCT application, it is necessary to -include the Open MCT distributable, enable some basic plugins, and bootstrap -the application. The tutorials walk through the process of getting Open MCT up -and running from scratch, but provided below is a minimal HTML template that -includes Open MCT, installs some basic plugins, and bootstraps the application. -It assumes that Open MCT is installed under an `openmct` subdirectory, as -described in [Building From Source](#building-from-source). +> [!WARNING] +> Open MCT provides a development server via `webpack-dev-server` (`npm start`). **This should be used for development purposes only and should never be deployed to a production environment**. -This approach includes openmct using a simple script tag, resulting in a global -variable named `openmct`. This `openmct` object is used subsequently to make -API calls. +To start a minimally functional Open MCT application, it is necessary to +include the Open MCT distributable, enable some basic plugins, and bootstrap +the application. The tutorials walk through the process of getting Open MCT up +and running from scratch, but provided below is a minimal HTML template that +includes Open MCT, installs some basic plugins, and bootstraps the application. +It assumes that Open MCT is installed under an `openmct` subdirectory, as +described in [Building From Source](#building-from-source). -Open MCT is packaged as a UMD (Universal Module Definition) module, so common +This approach includes openmct using a simple script tag, resulting in a global +variable named `openmct`. This `openmct` object is used subsequently to make +API calls. + +Open MCT is packaged as a UMD (Universal Module Definition) module, so common script loaders are also supported. ```html @@ -123,17 +130,59 @@ script loaders are also supported. ``` -The Open MCT library included above requires certain assets such as html -templates, images, and css. If you installed Open MCT from GitHub as described +The Open MCT library included above requires certain assets such as html +templates, images, and css. If you installed Open MCT from GitHub as described in the section on [Building from Source](#building-from-source) then these -assets will have been downloaded along with the Open MCT javascript library. +assets will have been downloaded along with the Open MCT javascript library. -There are some plugins bundled with the application that provide UI, -persistence, and other default configuration which are necessary to be able to -do anything with the application initially. Any of these plugins can, in -principle, be replaced with a custom plugin. The included plugins are +There are some plugins bundled with the application that provide UI, +persistence, and other default configuration which are necessary to be able to +do anything with the application initially. Any of these plugins can, in +principle, be replaced with a custom plugin. The included plugins are documented in the [Included Plugins](#included-plugins) section. +## Types + +The Open MCT library includes its own TypeScript declaration files which can be +used to provide code hints and typechecking in your own Open MCT application. + +Open MCT's type declarations are generated via `tsc` from JSDoc-style comment +blocks. For more information on this, [check out TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html). + +### Using Types + +In order to use Open MCT's provided types in your own application, create a +`jsconfig.js` at the root of your project with this minimal configuration: + +```json +{ + "compilerOptions": { + "baseUrl": "./", + "target": "es6", + "checkJs": true, + "moduleResolution": "node", + "paths": { + "openmct": ["node_modules/openmct/dist/openmct.d.ts"] + } + } +} +``` + +Then, simply import and use `openmct` in your application: + +```js +import openmct from "openmct"; +``` + +### Limitations + +The effort to add types for Open MCT's public API is ongoing, and the provided +type declarations may be incomplete. + +If you would like to contribute types to Open MCT, please check out +[TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html) on generating type declarations from JSDoc-style comment blocks. +Then read through our [contributing guide](https://github.com/nasa/openmct/blob/f7cf3f72c2efd46da7ce5719c5e52c8806d166f0/CONTRIBUTING.md) and open a PR! + ## Plugins ### Defining and Installing a New Plugin @@ -146,10 +195,10 @@ openmct.install(function install(openmctAPI) { ``` New plugins are installed in Open MCT by calling `openmct.install`, and -providing a plugin installation function. This function will be invoked on -application startup with one parameter - the openmct API object. A common -approach used in the Open MCT codebase is to define a plugin as a function that -returns this installation function. This allows configuration to be specified +providing a plugin installation function. This function will be invoked on +application startup with one parameter - the openmct API object. A common +approach used in the Open MCT codebase is to define a plugin as a function that +returns this installation function. This allows configuration to be specified when the plugin is included. eg. @@ -162,16 +211,16 @@ This approach can be seen in all of the [plugins provided with Open MCT](https:/ ## Domain Objects and Identifiers -_Domain Objects_ are the basic entities that represent domain knowledge in Open -MCT. The temperature sensor on a solar panel, an overlay plot comparing the -results of all temperature sensors, the command dictionary for a spacecraft, -the individual commands in that dictionary, the "My Items" folder: All of these +_Domain Objects_ are the basic entities that represent domain knowledge in Open +MCT. The temperature sensor on a solar panel, an overlay plot comparing the +results of all temperature sensors, the command dictionary for a spacecraft, +the individual commands in that dictionary, the "My Items" folder: All of these things are domain objects. A _Domain Object_ is simply a javascript object with some standard attributes. -An example of a _Domain Object_ is the "My Items" object which is a folder in -which a user can persist any objects that they create. The My Items object -looks like this: +An example of a _Domain Object_ is the "My Items" object which is a folder in +which a user can persist any objects that they create. The My Items object +looks like this: ```javascript { @@ -190,23 +239,24 @@ looks like this: The main attributes to note are the `identifier`, and `type` attributes. -* `identifier`: A composite key that provides a universally unique identifier +- `identifier`: A composite key that provides a universally unique identifier for this object. The `namespace` and `key` are used to identify the object. - The `key` must be unique within the namespace. -* `type`: All objects in Open MCT have a type. Types allow you to form an - ontology of knowledge and provide an abstraction for grouping, visualizing, - and interpreting data. Details on how to define a new object type are - provided below. + The `key` must be unique within the namespace. +- `type`: All objects in Open MCT have a type. Types allow you to form an + ontology of knowledge and provide an abstraction for grouping, visualizing, + and interpreting data. Details on how to define a new object type are + provided below. -Open MCT uses a number of builtin types. Typically you are going to want to +Open MCT uses a number of builtin types. Typically you are going to want to define your own when extending Open MCT. ### Domain Object Types -Custom types may be registered via the `addType` function on the Open MCT Type +Custom types may be registered via the `addType` function on the Open MCT Type registry. eg. + ```javascript openmct.types.addType('example.my-type', { name: "My Type", @@ -216,37 +266,39 @@ openmct.types.addType('example.my-type', { ``` The `addType` function accepts two arguments: -* A `string` key identifying the type. This key is used when specifying a type + +- A `string` key identifying the type. This key is used when specifying a type for an object. We recommend prefixing your types with a namespace to avoid conflicts with other plugins. -* An object type specification. An object type definition supports the following -attributes - * `name`: a `string` naming this object type - * `description`: a `string` specifying a longer-form description of this type - * `initialize`: a `function` which initializes the model for new domain objects - of this type. This can be used for setting default values on an object when +- An object type specification. An object type definition supports the following +attributes + - `name`: a `string` naming this object type + - `description`: a `string` specifying a longer-form description of this type + - `initialize`: a `function` which initializes the model for new domain objects + of this type. This can be used for setting default values on an object when it is instantiated. - * `creatable`: A `boolean` indicating whether users should be allowed to create - this type (default: `false`). This will determine whether the type appears + - `creatable`: A `boolean` indicating whether users should be allowed to create + this type (default: `false`). This will determine whether the type appears in the `Create` menu. - * `cssClass`: A `string` specifying a CSS class to apply to each representation - of this object. This is used for specifying an icon to appear next to each + - `cssClass`: A `string` specifying a CSS class to apply to each representation + of this object. This is used for specifying an icon to appear next to each object of this type. -The [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial) provide a -step-by-step examples of writing code for Open MCT that includes a [section on +The [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial) provide a +step-by-step examples of writing code for Open MCT that includes a [section on defining a new object type](https://github.com/nasa/openmct-tutorial#step-3---providing-objects). ## Root Objects -In many cases, you'd like a certain object (or a certain hierarchy of objects) -to be accessible from the top level of the application (the tree on the left-hand -side of Open MCT.) For example, it is typical to expose a telemetry dictionary +In many cases, you'd like a certain object (or a certain hierarchy of objects) +to be accessible from the top level of the application (the tree on the left-hand +side of Open MCT.) For example, it is typical to expose a telemetry dictionary as a hierarchy of telemetry-providing domain objects in this fashion. To do so, use the `addRoot` method of the object API. eg. + ```javascript openmct.objects.addRoot({ namespace: "example.namespace", @@ -255,12 +307,13 @@ openmct.objects.addRoot({ openmct.priority.HIGH); ``` -The `addRoot` function takes a two arguments, the first can be an [object identifier](#domain-objects-and-identifiers) for a root level object, or an array of identifiers for root +The `addRoot` function takes a two arguments, the first can be an [object identifier](#domain-objects-and-identifiers) for a root level object, or an array of identifiers for root level objects, or a function that returns a promise for an identifier or an array of root level objects, the second is a [priority](#priority-api) or numeric value. When using the `getAll` method of the object API, they will be returned in order of priority. eg. + ```javascript openmct.objects.addRoot(identifier, openmct.priority.LOW); // low = -1000, will appear last in composition or tree openmct.objects.addRoot(otherIdentifier, openmct.priority.HIGH); // high = 1000, will appear first in composition or tree @@ -270,11 +323,11 @@ Root objects are loaded just like any other objects, i.e. via an object provider ## Object Providers -An Object Provider is used to build _Domain Objects_, typically retrieved from -some source such as a persistence store or telemetry dictionary. In order to -integrate telemetry from a new source an object provider will need to be created -that can build objects representing telemetry points exposed by the telemetry -source. The API call to define a new object provider is fairly straightforward. +An Object Provider is used to build _Domain Objects_, typically retrieved from +some source such as a persistence store or telemetry dictionary. In order to +integrate telemetry from a new source an object provider will need to be created +that can build objects representing telemetry points exposed by the telemetry +source. The API call to define a new object provider is fairly straightforward. Here's a very simple example: ```javascript @@ -288,14 +341,15 @@ openmct.objects.addProvider('example.namespace', { } }); ``` + The `addProvider` function takes two arguments: -* `namespace`: A `string` representing the namespace that this object provider +- `namespace`: A `string` representing the namespace that this object provider will provide objects for. -* `provider`: An `object` with a single function, `get`. This function accepts an -[Identifier](#domain-objects-and-identifiers) for the object to be provided. -It is expected that the `get` function will return a -[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) +- `provider`: An `object` with a single function, `get`. This function accepts an +[Identifier](#domain-objects-and-identifiers) for the object to be provided. +It is expected that the `get` function will return a +[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with the object being requested. In future, object providers will support other methods to enable other operations with persistence stores, such as creating, updating, and deleting objects. @@ -310,8 +364,8 @@ may be cases where you want to provide the composition of a certain object ### Adding Composition Providers -You may want to populate a hierarchy under a custom root-level object based on -the contents of a telemetry dictionary. To do this, you can add a new +You may want to populate a hierarchy under a custom root-level object based on +the contents of a telemetry dictionary. To do this, you can add a new Composition Provider: ```javascript @@ -324,19 +378,20 @@ openmct.composition.addProvider({ } }); ``` -The `addProvider` function accepts a Composition Provider object as its sole + +The `addProvider` function accepts a Composition Provider object as its sole argument. A Composition Provider is a javascript object exposing two functions: -* `appliesTo`: A `function` that accepts a `domainObject` argument, and returns -a `boolean` value indicating whether this composition provider applies to the +- `appliesTo`: A `function` that accepts a `domainObject` argument, and returns +a `boolean` value indicating whether this composition provider applies to the given object. -* `load`: A `function` that accepts a `domainObject` as an argument, and returns +- `load`: A `function` that accepts a `domainObject` as an argument, and returns a `Promise` that resolves with an array of [Identifier](#domain-objects-and-identifiers). These identifiers will be used to fetch Domain Objects from an [Object Provider](#object-provider) ### Default Composition Provider -The default composition provider applies to any domain object with a -`composition` property. The value of `composition` should be an array of +The default composition provider applies to any domain object with a +`composition` property. The value of `composition` should be an array of identifiers, e.g.: ```javascript @@ -370,7 +425,7 @@ Open MCT are stable and documentation is included below. There are two main tasks for integrating telemetry sources-- describing telemetry objects with relevant metadata, and then providing telemetry data for those objects. You'll use an [Object Provider](#object-providers) to provide objects with the necessary [Telemetry Metadata](#telemetry-metadata), and then register a [Telemetry Provider](#telemetry-providers) to retrieve telemetry data for those objects. Alternatively, you can register a telemetry metadata provider to provide the necessary telemetry metadata. -For a step-by-step guide to building a telemetry adapter, please see the +For a step-by-step guide to building a telemetry adapter, please see the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). #### Telemetry Metadata @@ -430,24 +485,22 @@ attribute | type | flags | notes `max` | number | optional | the maximum possible value of this measurement. Will be used by plots, gauges, etc to automatically set a max value. `enumerations` | array | optional | for objects where `format` is `"enum"`, this array tracks all possible enumerations of the value. Each entry in this array is an object, with a `value` property that is the numerical value of the enumeration, and a `string` property that is the text value of the enumeration. ex: `{"value": 0, "string": "OFF"}`. If you use an enumerations array, `min` and `max` will be set automatically for you. - ###### Value Hints Each telemetry value description has an object defining hints. Keys in this object represent the hint itself, and the value represents the weight of that hint. A lower weight means the hint has a higher priority. For example, multiple values could be hinted for use as the y-axis of a plot (raw, engineering), but the highest priority would be the default choice. Likewise, a table will use hints to determine the default order of columns. Known hints: -* `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first. -* `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values. -* `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available. -* `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file. +- `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first. +- `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values. +- `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available. +- `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file. -##### The Time Conductor and Telemetry +##### The Time Conductor and Telemetry Open MCT provides a number of ways to pivot through data and link data via time. The Time Conductor helps synchronize multiple views around the same time. -In order for the time conductor to work, there will always be an active "time system". All telemetry metadata *must* have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings. - +In order for the time conductor to work, there will always be an active "time system". All telemetry metadata _must_ have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings. #### Telemetry Providers @@ -455,14 +508,14 @@ Telemetry providers are responsible for providing historical and real-time telem A telemetry provider is a javascript object with up to four methods: -* `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options). -* `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function. -* `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object. -* `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests. -* `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for. -* `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition. -* `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for. -* `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object. +- `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options). +- `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function. +- `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object. +- `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests. +- `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for. +- `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition. +- `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for. +- `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object. Telemetry providers are registered by calling `openmct.telemetry.addProvider(provider)`, e.g. @@ -475,7 +528,7 @@ openmct.telemetry.addProvider({ Note: it is not required to implement all of the methods on every provider. Depending on the complexity of your implementation, it may be helpful to instantiate and register your realtime, historical, and metadata providers separately. -#### Telemetry Requests and Responses. +#### Telemetry Requests and Responses Telemetry requests support time bounded queries. A call to a _Telemetry Provider_'s `request` function will include an `options` argument. These are simply javascript objects with attributes for the request parameters. An example of a telemetry request object with a start and end time is included below: @@ -508,6 +561,7 @@ the number of results it desires. The `size` parameter is a hint; views must not assume the response will have the exact number of results requested. example: + ```javascript { start: 1487981997240, @@ -523,6 +577,7 @@ This strategy says "I want the latest data point in this time range". A provide ##### `minmax` request strategy example: + ```javascript { start: 1487981997240, @@ -537,36 +592,109 @@ MinMax queries are issued by plots, and may be issued by other types as well. T #### Telemetry Formats -Telemetry format objects define how to interpret and display telemetry data. -They have a simple structure: +Telemetry format objects define how to interpret and display telemetry data. +They have a simple structure, provided here as a TypeScript interface: -* `key`: A `string` that uniquely identifies this formatter. -* `format`: A `function` that takes a raw telemetry value, and returns a - human-readable `string` representation of that value. It has one required - argument, and three optional arguments that provide context and can be used - for returning scaled representations of a value. An example of this is - representing time values in a scale such as the time conductor scale. There - are multiple ways of representing a point in time, and by providing a minimum - scale value, maximum scale value, and a count, it's possible to provide more - useful representations of time given the provided limitations. - * `value`: The raw telemetry value in its native type. - * `minValue`: An __optional__ argument specifying the minimum displayed - value. - * `maxValue`: An __optional__ argument specifying the maximum displayed - value. - * `count`: An __optional__ argument specifying the number of displayed - values. -* `parse`: A `function` that takes a `string` representation of a telemetry - value, and returns the value in its native type. **Note** parse might receive an already-parsed value. This function should be idempotent. -* `validate`: A `function` that takes a `string` representation of a telemetry - value, and returns a `boolean` value indicating whether the provided string - can be parsed. +```ts +interface Formatter { + key: string; // A string that uniquely identifies this formatter. + + format: ( + value: any, // The raw telemetry value in its native type. + minValue?: number, // An optional argument specifying the minimum displayed value. + maxValue?: number, // An optional argument specifying the maximum displayed value. + count?: number // An optional argument specifying the number of displayed values. + ) => string; // Returns a human-readable string representation of the provided value. + + parse: ( + value: string | any // A string representation of a telemetry value or an already-parsed value. + ) => any; // Returns the value in its native type. This function should be idempotent. + + validate: (value: string) => boolean; // Takes a string representation of a telemetry value and returns a boolean indicating whether the provided string can be parsed. +} +``` + +##### Built-in Formats + +Open MCT on its own defines a handful of built-in formats: + +###### **Number Format (default):** + +Applied to data with `format: 'number'` +```js +valueMetadata = { + format: 'number' + // ... +}; +``` + +```ts +interface NumberFormatter extends Formatter { + parse: (x: any) => number; + format: (x: number) => string; + validate: (value: any) => boolean; +} +``` +###### **String Format**: + +Applied to data with `format: 'string'` +```js +valueMetadata = { + format: 'string' + // ... +}; +``` +```ts +interface StringFormatter extends Formatter { + parse: (value: any) => string; + format: (value: string) => string; + validate: (value: any) => boolean; +} +``` + +###### **Enum Format**: +Applied to data with `format: 'enum'` +```js +valueMetadata = { + format: 'enum', + enumerations: [ + { + value: 1, + string: 'APPLE' + }, + { + value: 2, + string: 'PEAR', + }, + { + value: 3, + string: 'ORANGE' + }] + // ... +}; +``` + +Creates a two-way mapping between enum string and value to be used in the `parse` and `format` methods. +Ex: +- `formatter.parse('APPLE') === 1;` +- `formatter.format(1) === 'APPLE';` + +```ts +interface EnumFormatter extends Formatter { + parse: (value: string) => string; + format: (value: number) => string; + validate: (value: any) => boolean; +} +``` ##### Registering Formats +Formats implement the following interface (provided here as TypeScript for simplicity): + + Formats are registered with the Telemetry API using the `addFormat` function. eg. -``` javascript +```javascript openmct.telemetry.addFormat({ key: 'number-to-string', format: function (number) { @@ -584,9 +712,9 @@ openmct.telemetry.addFormat({ #### Telemetry Data A single telemetry point is considered a Datum, and is represented by a standard -javascript object. Realtime subscriptions (obtained via __subscribe__) will +javascript object. Realtime subscriptions (obtained via **subscribe**) will invoke the supplied callback once for each telemetry datum recieved. Telemetry -requests (obtained via __request__) will return a promise for an array of +requests (obtained via **request**) will return a promise for an array of telemetry datums. ##### Telemetry Datums @@ -607,14 +735,14 @@ section. #### Limit Evaluators **draft** -Limit evaluators allow a telemetry integrator to define which limits exist for a +Limit evaluators allow a telemetry integrator to define which limits exist for a telemetry endpoint and how limits should be applied to telemetry from a given domain object. A limit evaluator can implement the `evalute` method which is used to define how limits -should be applied to telemetry and the `getLimits` method which is used to specify +should be applied to telemetry and the `getLimits` method which is used to specify what the limit values are for different limit levels. -Limit levels can be mapped to one of 5 colors for visualization: +Limit levels can be mapped to one of 5 colors for visualization: `purple`, `red`, `orange`, `yellow` and `cyan`. For an example of a limit evaluator, take a look at `examples/generator/SinewaveLimitProvider.js`. @@ -623,30 +751,30 @@ For an example of a limit evaluator, take a look at `examples/generator/Sinewave The APIs for requesting telemetry from Open MCT -- e.g. for use in custom views -- are currently in draft state and are being revised. If you'd like to experiment with them before they are finalized, please contact the team via the contact-us link on our website. - ## Time API Open MCT provides API for managing the temporal state of the application. -Central to this is the concept of "time bounds". Views in Open MCT will -typically show telemetry data for some prescribed date range, and the Time API +Central to this is the concept of "time bounds". Views in Open MCT will +typically show telemetry data for some prescribed date range, and the Time API provides a way to centrally manage these bounds. -The Time API exposes a number of methods for querying and setting the temporal +The Time API exposes a number of methods for querying and setting the temporal state of the application, and emits events to inform listeners when the state changes. -Because the data displayed tends to be time domain data, Open MCT must always +Because the data displayed tends to be time domain data, Open MCT must always have at least one time system installed and activated. When you download Open -MCT, it will be pre-configured to use the UTC time system, which is installed and activated, along with other default plugins, in `index.html`. Installing and activating a time system is simple, and is covered -[in the next section](#defining-and-registering-time-systems). +MCT, it will be pre-configured to use the UTC time system, which is installed and activated, +along with other default plugins, in `index.html`. Installing and activating a time system +is simple, and is covered [in the next section](#defining-and-registering-time-systems). ### Time Systems and Bounds #### Defining and Registering Time Systems -The time bounds of an Open MCT application are defined as numbers, and a Time -System gives meaning and context to these numbers so that they can be correctly -interpreted. Time Systems are JavaScript objects that provide some information -about the current time reference frame. An example of defining and registering +The time bounds of an Open MCT application are defined as numbers, and a Time +System gives meaning and context to these numbers so that they can be correctly +interpreted. Time Systems are JavaScript objects that provide some information +about the current time reference frame. An example of defining and registering a new time system is given below: ``` javascript @@ -660,91 +788,109 @@ openmct.time.addTimeSystem({ }); ``` -The example above defines a new utc based time system. In fact, this time system -is configured and activated by default from `index.html` in the default -installation of Open MCT if you download the source from GitHub. Some details of +The example above defines a new utc based time system. In fact, this time system +is configured and activated by default from `index.html` in the default +installation of Open MCT if you download the source from GitHub. Some details of each of the required properties is provided below. -* `key`: A `string` that uniquely identifies this time system. -* `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor) +- `key`: A `string` that uniquely identifies this time system. +- `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor) plugin is enabled, this name will identify the time system in a dropdown menu. -* `cssClass`: A class name `string` that will be applied to the time system when -it appears in the UI. This will be used to represent the time system with an icon. -There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), -or a custom class can be used here. -* `timeFormat`: A `string` corresponding to the key of a registered -[telemetry time format](#telemetry-formats). The format will be used for -displaying discrete timestamps from telemetry streams when this time system is -activated. If the [UTCTimeSystem](#included-plugins) is enabled, then the `utc` +- `cssClass`: A class name `string` that will be applied to the time system when +it appears in the UI. This will be used to represent the time system with an icon. +There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), +or a custom class can be used here. +- `timeFormat`: A `string` corresponding to the key of a registered +[telemetry time format](#telemetry-formats). The format will be used for +displaying discrete timestamps from telemetry streams when this time system is +activated. If the [UTCTimeSystem](#included-plugins) is enabled, then the `utc` format can be used if this is a utc-based time system -* `durationFormat`: A `string` corresponding to the key of a registered -[telemetry time format](#telemetry-formats). The format will be used for -displaying time ranges, for example `00:15:00` might be used to represent a time +- `durationFormat`: A `string` corresponding to the key of a registered +[telemetry time format](#telemetry-formats). The format will be used for +displaying time ranges, for example `00:15:00` might be used to represent a time period of fifteen minutes. These are used by the Time Conductor plugin to specify -relative time offsets. If the [UTCTimeSystem](#included-plugins) is enabled, +relative time offsets. If the [UTCTimeSystem](#included-plugins) is enabled, then the `duration` format can be used if this is a utc-based time system -* `isUTCBased`: A `boolean` that defines whether this time system represents -numbers in UTC terrestrial time. +- `isUTCBased`: A `boolean` that defines whether this time system represents +numbers in UTC terrestrial time. #### Getting and Setting the Active Time System -Once registered, a time system can be activated by calling `timeSystem` with -the timeSystem `key` or an instance of the time system. If you are not using a -[clock](#clocks), you must also specify valid [bounds](#time-bounds) for the -timeSystem. +Once registered, a time system can be activated by calling `setTimeSystem` with +the timeSystem `key` or an instance of the time system. You can also specify +valid [bounds](#time-bounds) for the timeSystem. ```javascript -openmct.time.timeSystem('utc', bounds); +openmct.time.setTimeSystem('utc', bounds); ``` -A time system can be immediately activated after registration: +The current time system can be retrieved as well by calling `getTimeSystem`. + +```javascript +openmct.time.getTimeSystem(); +``` + +A time system can be immediately activated after registration: ```javascript openmct.time.addTimeSystem(utcTimeSystem); -openmct.time.timeSystem(utcTimeSystem, bounds); +openmct.time.setTimeSystem(utcTimeSystem, bounds); ``` -Setting the active time system will trigger a [`'timeSystem'`](#time-events) -event. If you supplied bounds, a [`'bounds'`](#time-events) event will be triggered afterwards with your newly supplied bounds. +Setting the active time system will trigger a [`'timeSystemChanged'`](#time-events) +event. If you supplied bounds, a [`'boundsChanged'`](#time-events) event will be triggered afterwards with your newly supplied bounds. + +> ⚠️ **Deprecated** +> - The method `timeSystem()` is deprecated. Please use `getTimeSystem()` and `setTimeSystem()` as a replacement. + + #### Time Bounds -The TimeAPI provides a getter/setter for querying and setting time bounds. Time +The TimeAPI provides a getter and setter for querying and setting time bounds. Time bounds are simply an object with a `start` and an end `end` attribute. -* `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). +- `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). This will be used as the beginning of the time period displayed by time-responsive telemetry views. -* `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). +- `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). This will be used as the end of the time period displayed by time-responsive telemetry views. -If invoked with bounds, it will set the new time bounds system-wide. If invoked -without any parameters, it will return the current application-wide time bounds. +New bounds can be set system wide by calling `setBounds` with [bounds](#time-bounds). ``` javascript const ONE_HOUR = 60 * 60 * 1000; let now = Date.now(); -openmct.time.bounds({start: now - ONE_HOUR, now); +openmct.time.setBounds({start: now - ONE_HOUR, now); ``` -To respond to bounds change events, listen for the [`'bounds'`](#time-events) +Calling `getBounds` will return the current application-wide time bounds. + +``` javascript +openmct.time.getBounds(); +``` + +To respond to bounds change events, listen for the [`'boundsChanged'`](#time-events) event. +> ⚠️ **Deprecated** +> - The method `bounds()` is deprecated and will be removed in a future release. Please use `getBounds()` and `setBounds()` as a replacement. + ### Clocks -The Time API can be set to follow a clock source which will cause the bounds -to be updated automatically whenever the clock source "ticks". A clock is simply -an object that supports registration of listeners and periodically invokes its -listeners with a number. Open MCT supports registration of new clock sources that -tick on almost anything. A tick occurs when the clock invokes callback functions -registered by its listeners with a new time value. +The Time API requires a clock source which will cause the bounds to be updated +automatically whenever the clock source "ticks". A clock is simply an object that +supports registration of listeners and periodically invokes its listeners with a +number. Open MCT supports registration of new clock sources that tick on almost +anything. A tick occurs when the clock invokes callback functions registered by its +listeners with a new time value. -An example of a clock source is the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) -which emits the current time in UTC every 100ms. Clocks can tick on anything. For -example, a clock could be defined to provide the timestamp of any new data -received via a telemetry subscription. This would have the effect of advancing -the bounds of views automatically whenever data is received. A clock could also +An example of a clock source is the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) +which emits the current time in UTC every 100ms. Clocks can tick on anything. For +example, a clock could be defined to provide the timestamp of any new data +received via a telemetry subscription. This would have the effect of advancing +the bounds of views automatically whenever data is received. A clock could also be defined to tick on some remote timing source. The values provided by clocks are simple `number`s, which are interpreted in the @@ -754,32 +900,32 @@ context of the active [Time System](#defining-and-registering-time-systems). A clock is an object that defines certain required metadata and functions: -* `key`: A `string` uniquely identifying this clock. This can be used later to +- `key`: A `string` uniquely identifying this clock. This can be used later to reference the clock in places such as the [Time Conductor configuration](#time-conductor-configuration) -* `cssClass`: A `string` identifying a CSS class to apply to this clock when it's -displayed in the UI. This will be used to represent the time system with an icon. -There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), -or a custom class can be used here. -* `name`: A `string` providing a human-readable identifier for the clock source. -This will be displayed in the clock selector menu in the Time Conductor UI -component, if active. -* `description`: An __optional__ `string` providing a longer description of the -clock. The description will be visible in the clock selection menu in the Time +- `cssClass`: A `string` identifying a CSS class to apply to this clock when it's +displayed in the UI. This will be used to represent the time system with an icon. +There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), +or a custom class can be used here. +- `name`: A `string` providing a human-readable identifier for the clock source. +This will be displayed in the clock selector menu in the Time Conductor UI +component, if active. +- `description`: An **optional** `string` providing a longer description of the +clock. The description will be visible in the clock selection menu in the Time Conductor plugin. -* `on`: A `function` supporting registration of a new callback that will be +- `on`: A `function` supporting registration of a new callback that will be invoked when the clock next ticks. It will be invoked with two arguments: - * `eventName`: A `string` specifying the event to listen on. For now, clocks + - `eventName`: A `string` specifying the event to listen on. For now, clocks support one event - `tick`. - * `callback`: A `function` that will be invoked when this clock ticks. The + - `callback`: A `function` that will be invoked when this clock ticks. The function must be invoked with one parameter - a `number` representing a valid time in the current time system. -* `off`: A `function` that allows deregistration of a tick listener. It accepts +- `off`: A `function` that allows deregistration of a tick listener. It accepts the same arguments as `on`. -* `currentValue`: A `function` that returns a `number` representing a point in -time in the active time system. It should be the last value provided by a tick, +- `currentValue`: A `function` that returns a `number` representing a point in +time in the active time system. It should be the last value provided by a tick, or some default value if no ticking has yet occurred. -A new clock can be registered using the `addClock` function exposed by the Time +A new clock can be registered using the `addClock` function exposed by the Time API: ```javascript @@ -806,63 +952,128 @@ An example clock implementation is provided in the form of the [LocalClock](http #### Getting and setting active clock -Once registered a clock can be activated by calling the `clock` function on the -Time API passing in the key or instance of a registered clock. Only one clock -may be active at once, so activating a clock will deactivate any currently -active clock. [`clockOffsets`](#clock-offsets) must be specified when changing a clock. - -Setting the clock triggers a [`'clock'`](#time-events) event, followed by a [`'clockOffsets'`](#time-events) event, and then a [`'bounds'`](#time-events) event as the offsets are applied to the clock's currentValue(). +Once registered a clock can be activated by calling the `setClock` function on the +Time API passing in the key or instance of a registered clock. Only one clock +may be active at once, so activating a clock will deactivate any currently +active clock and start the new clock. [`clockOffsets`](#clock-offsets) must be specified when changing a clock. +Setting the clock triggers a [`'clockChanged'`](#time-events) event, followed by a [`'clockOffsetsChanged'`](#time-events) event, and then a [`'boundsChanged'`](#time-events) event as the offsets are applied to the clock's currentValue(). ``` -openmct.time.clock(someClock, clockOffsets); +openmct.time.setClock(someClock, clockOffsets); ``` Upon being activated, the time API will listen for tick events on the clock by calling `clock.on`. -The currently active clock (if any) can be retrieved by calling the same -function without any arguments. +The currently active clock can be retrieved by calling `getClock`. -#### Stopping an active clock +``` +openmct.time.getClock(); +``` -The `stopClock` method can be used to stop an active clock, and to clear it. It +> ⚠️ **Deprecated** +> - The method `clock()` is deprecated and will be removed in a future release. Please use `getClock()` and `setClock()` as a replacement. + +#### ⚠️ [DEPRECATED] Stopping an active clock + +_As of July 2023, this method will be deprecated. Open MCT will always have a ticking clock._ + +The `stopClock` method can be used to stop an active clock, and to clear it. It will stop the clock from ticking, and set the active clock to `undefined`. ``` javascript openmct.time.stopClock(); ``` +> ⚠️ **Deprecated** +> - The method `stopClock()` is deprecated and will be removed in a future release. + #### Clock Offsets -When a clock is active, the time bounds of the application will be updated -automatically each time the clock "ticks". The bounds are calculated based on -the current value provided by the active clock (via its `tick` event, or its -`currentValue()` method). +When in Real-time [mode](#time-modes), the time bounds of the application will be updated automatically each time the +clock "ticks". The bounds are calculated based on the current value provided by +the active clock (via its `tick` event, or its `currentValue()` method). Unlike bounds, which represent absolute time values, clock offsets represent relative time spans. Offsets are defined as an object with two properties: -* `start`: A `number` that must be < 0 and which is used to calculate the start -bounds on each clock tick. The start offset will be calculated relative to the +- `start`: A `number` that must be < 0 and which is used to calculate the start +bounds on each clock tick. The start offset will be calculated relative to the value provided by a clock's tick callback, or its `currentValue()` function. -* `end`: A `number` that must be >= 0 and which is used to calculate the end +- `end`: A `number` that must be >= 0 and which is used to calculate the end bounds on each clock tick. -The `clockOffsets` function can be used to get or set clock offsets. For example, -to show the last fifteen minutes in a ms-based time system: +The `setClockOffsets` function can be used to get or set clock offsets. For example, +to show the last fifteen minutes in a ms-based time system: ```javascript var FIFTEEN_MINUTES = 15 * 60 * 1000; -openmct.time.clockOffsets({ +openmct.time.setClockOffsets({ start: -FIFTEEN_MINUTES, end: 0 }) ``` -__Note:__ Setting the clock offsets will trigger an immediate bounds change, as -new bounds will be calculated based on the `currentValue()` of the active clock. -Clock offsets are only relevant when a clock source is active. +The `getClockOffsets` method will return the currently set clock offsets. + +```javascript +openmct.time.getClockOffsets() +``` + +**Note:** Setting the clock offsets will trigger an immediate bounds change, as +new bounds will be calculated based on the `currentValue()` of the active clock. +Clock offsets are only relevant when in Real-time [mode](#time-modes). + +> ⚠️ **Deprecated** +> - The method `clockOffsets()` is deprecated and will be removed in a future release. Please use `getClockOffsets()` and `setClockOffsets()` as a replacement. + +### Time Modes + +There are two time modes in Open MCT, "Fixed" and "Real-time". In Real-time mode the +time bounds of the application will be updated automatically each time the clock "ticks". +The bounds are calculated based on the current value provided by the active clock. In +Fixed mode, the time bounds are set for a specified time range. When Open MCT is first +initialized, it will be in Real-time mode. + +The `setMode` method can be used to set the current time mode. It accepts a mode argument, +`'realtime'` or `'fixed'` and it also accepts an optional [offsets](#clock-offsets)/[bounds](#time-bounds) argument dependent +on the current mode. + +``` javascript +openmct.time.setMode('fixed'); +openmct.time.setMode('fixed', bounds); // with optional bounds +``` + +or + +``` javascript +openmct.time.setMode('realtime'); +openmct.time.setMode('realtime', offsets); // with optional offsets +``` + +The `getMode` method will return the current time mode, either `'realtime'` or `'fixed'`. + +``` javascript +openmct.time.getMode(); +``` + +#### Time Mode Helper Methods + +There are two methods available to determine the current time mode in Open MCT programmatically, +`isRealTime` and `isFixed`. Each one will return a boolean value based on the current mode. + +``` javascript +if (openmct.time.isRealTime()) { + // do real-time stuff +} +``` + +``` javascript +if (openmct.time.isFixed()) { + // do fixed-time stuff +} +``` ### Time Events @@ -871,7 +1082,7 @@ The Time API is a standard event emitter; you can register callbacks for events For example: ``` javascript -openmct.time.on('bounds', function callback (newBounds, tick) { +openmct.time.on('boundsChanged', function callback (newBounds, tick) { // Do something with new bounds }); ``` @@ -880,89 +1091,97 @@ openmct.time.on('bounds', function callback (newBounds, tick) { The events emitted by the Time API are: -* `bounds`: emitted whenever the bounds change. The callback will be invoked +- `boundsChanged`: emitted whenever the bounds change. The callback will be invoked with two arguments: - * `bounds`: A [bounds](#getting-and-setting-bounds) bounds object + - `bounds`: A [bounds](#getting-and-setting-bounds) bounds object representing a new time period bound by the specified start and send times. - * `tick`: A `boolean` indicating whether or not this bounds change is due to - a "tick" from a [clock source](#clocks). This information can be useful - when determining a strategy for fetching telemetry data in response to a - bounds change event. For example, if the bounds change was automatic, and - is due to a tick then it's unlikely that you would need to perform a - historical data query. It should be sufficient to just show any new - telemetry received via subscription since the last tick, and optionally to - discard any older data that now falls outside of the currently set bounds. - If `tick` is false,then the bounds change was not due to an automatic tick, - and a query for historical data may be necessary, depending on your data + - `tick`: A `boolean` indicating whether or not this bounds change is due to + a "tick" from a [clock source](#clocks). This information can be useful + when determining a strategy for fetching telemetry data in response to a + bounds change event. For example, if the bounds change was automatic, and + is due to a tick then it's unlikely that you would need to perform a + historical data query. It should be sufficient to just show any new + telemetry received via subscription since the last tick, and optionally to + discard any older data that now falls outside of the currently set bounds. + If `tick` is false,then the bounds change was not due to an automatic tick, + and a query for historical data may be necessary, depending on your data caching strategy, and how significantly the start bound has changed. -* `timeSystem`: emitted whenever the active time system changes. The callback will be invoked with a single argument: - * `timeSystem`: The newly active [time system](#defining-and-registering-time-systems). -* `clock`: emitted whenever the clock changes. The callback will be invoked +- `timeSystemChanged`: emitted whenever the active time system changes. The callback will be invoked with a single argument: + - `timeSystem`: The newly active [time system](#defining-and-registering-time-systems). +- `clockChanged`: emitted whenever the clock changes. The callback will be invoked with a single argument: - * `clock`: The newly active [clock](#clocks), or `undefined` if an active + - `clock`: The newly active [clock](#clocks), or `undefined` if an active clock has been deactivated. -* `clockOffsets`: emitted whenever the active clock offsets change. The +- `clockOffsetsChanged`: emitted whenever the active clock offsets change. The callback will be invoked with a single argument: - * `clockOffsets`: The new [clock offsets](#clock-offsets). + - `clockOffsets`: The new [clock offsets](#clock-offsets). +- `modeChanged`: emitted whenever the time [mode](#time-modes) changed. The callback will + be invoked with one argument: + - `mode`: A string representation of the current time mode, either `'realtime'` or `'fixed'`. +> ⚠️ **Deprecated Events** (These will be removed in a future release): +> - `bounds` → `boundsChanged` +> - `timeSystem` → `timeSystemChanged` +> - `clock` → `clockChanged` +> - `clockOffsets` → `clockOffsetsChanged` ### The Time Conductor -The Time Conductor provides a user interface for managing time bounds in Open +The Time Conductor provides a user interface for managing time bounds in Open MCT. It allows a user to select from configured time systems and clocks, and to set bounds and clock offsets. -If activated, the time conductor must be provided with configuration options, +If activated, the time conductor must be provided with configuration options, detailed below. #### Time Conductor Configuration -The time conductor is configured by specifying the options that will be -available to the user from the menus in the time conductor. These will determine -the clocks available from the conductor, the time systems available for each -clock, and some default bounds and clock offsets for each combination of clock -and time system. By default, the conductor always supports a `fixed` mode where +The time conductor is configured by specifying the options that will be +available to the user from the menus in the time conductor. These will determine +the clocks available from the conductor, the time systems available for each +clock, and some default bounds and clock offsets for each combination of clock +and time system. By default, the conductor always supports a `fixed` mode where no clock is active. To specify configuration for fixed mode, simply leave out a `clock` attribute in the configuration entry object. -Configuration is provided as an `array` of menu options. Each entry of the +Configuration is provided as an `array` of menu options. Each entry of the array is an object with some properties specifying configuration. The configuration -options specified are slightly different depending on whether or not it is for +options specified are slightly different depending on whether or not it is for an active clock mode. -__Configuration for Fixed Time Mode (no active clock)__ +**Configuration for Fixed Time Mode (no active clock)** -* `timeSystem`: A `string`, the key for the time system that this configuration +- `timeSystem`: A `string`, the key for the time system that this configuration relates to. -* `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied -when the user selects the time system specified in the previous `timeSystem` +- `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied +when the user selects the time system specified in the previous `timeSystem` property. -* `zoomOutLimit`: An __optional__ `number` specifying the longest period of time -that can be represented by the conductor when zooming. If a `zoomOutLimit` is -provided, then a `zoomInLimit` must also be provided. If provided, the zoom +- `zoomOutLimit`: An **optional** `number` specifying the longest period of time +that can be represented by the conductor when zooming. If a `zoomOutLimit` is +provided, then a `zoomInLimit` must also be provided. If provided, the zoom slider will automatically become available in the Time Conductor UI. -* `zoomInLimit`: An __optional__ `number` specifying the shortest period of time -that can be represented by the conductor when zooming. If a `zoomInLimit` is -provided, then a `zoomOutLimit` must also be provided. If provided, the zoom +- `zoomInLimit`: An **optional** `number` specifying the shortest period of time +that can be represented by the conductor when zooming. If a `zoomInLimit` is +provided, then a `zoomOutLimit` must also be provided. If provided, the zoom slider will automatically become available in the Time Conductor UI. -__Configuration for Active Clock__ +**Configuration for Active Clock** -* `clock`: A `string`, the `key` of the clock that this configuration applies to. -* `timeSystem`: A `string`, the key for the time system that this configuration -relates to. Separate configuration must be provided for each time system that you +- `clock`: A `string`, the `key` of the clock that this configuration applies to. +- `timeSystem`: A `string`, the key for the time system that this configuration +relates to. Separate configuration must be provided for each time system that you wish to be available to users when they select the specified clock. -* `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be -automatically applied when the combination of clock and time system specified in +- `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be +automatically applied when the combination of clock and time system specified in this configuration is selected from the UI. #### Example conductor configuration -An example time conductor configuration is provided below. It sets up some -default options for the [UTCTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/UTCTimeSystem.js) -and [LocalTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/localTimeSystem/LocalTimeSystem.js), -in both fixed mode, and for the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) -source. In this configutation, the local clock supports both the UTCTimeSystem -and LocalTimeSystem. Configuration for fixed bounds mode is specified by omitting +An example time conductor configuration is provided below. It sets up some +default options for the [UTCTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/UTCTimeSystem.js) +and [LocalTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/localTimeSystem/LocalTimeSystem.js), +in both fixed mode, and for the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) +source. In this configutation, the local clock supports both the UTCTimeSystem +and LocalTimeSystem. Configuration for fixed bounds mode is specified by omitting a clock key. ``` javascript @@ -998,26 +1217,27 @@ openmct.install(openmct.plugins.Conductor({ ## Indicators -Indicators are small widgets that reside at the bottom of the screen and are visible from +Indicators are small widgets that reside at the bottom of the screen and are visible from every screen in Open MCT. They can be used to convey system state using an icon and text. -Typically an indicator will display an icon (customizable with a CSS class) that will +Typically an indicator will display an icon (customizable with a CSS class) that will reveal additional information when the mouse cursor is hovered over it. ### The URL Status Indicator -A common use case for indicators is to convey the state of some external system such as a -persistence backend or HTTP server. So long as this system is accessible via HTTP request, -Open MCT provides a general purpose indicator to show whether the server is available and +A common use case for indicators is to convey the state of some external system such as a +persistence backend or HTTP server. So long as this system is accessible via HTTP request, +Open MCT provides a general purpose indicator to show whether the server is available and returning a 2xx status code. The URL Status Indicator is made available as a default plugin. See -the [documentation](./src/plugins/URLIndicatorPlugin) for details on how to install and configure the +the [documentation](./src/plugins/URLIndicatorPlugin) for details on how to install and configure the URL Status Indicator. ### Creating a Simple Indicator -A simple indicator with an icon and some text can be created and added with minimal code. An indicator +A simple indicator with an icon and some text can be created and added with minimal code. An indicator of this type exposes functions for customizing the text, icon, and style of the indicator. eg. + ``` javascript var myIndicator = openmct.indicators.simpleIndicator(); myIndicator.text("Hello World!"); @@ -1026,24 +1246,24 @@ openmct.indicators.add(myIndicator); This will create a new indicator and add it to the bottom of the screen in Open MCT. By default, the indicator will appear as an information icon. Hovering over the icon will -reveal the text set via the call to `.text()`. The Indicator object returned by the API +reveal the text set via the call to `.text()`. The Indicator object returned by the API call exposes a number of functions for customizing the content and appearance of the indicator: -* `.text([text])`: Gets or sets the text shown when the user hovers over the indicator. -Accepts an __optional__ `string` argument that, if provided, will be used to set the text. -Hovering over the indicator will expand it to its full size, revealing this text alongside +- `.text([text])`: Gets or sets the text shown when the user hovers over the indicator. +Accepts an **optional** `string` argument that, if provided, will be used to set the text. +Hovering over the indicator will expand it to its full size, revealing this text alongside the icon. Returns the currently set text as a `string`. -* `.description([description])`: Gets or sets the indicator's description. Accepts an -__optional__ `string` argument that, if provided, will be used to set the text. The description -allows for more detail to be provided in a tooltip when the user hovers over the indicator. +- `.description([description])`: Gets or sets the indicator's description. Accepts an +**optional** `string` argument that, if provided, will be used to set the text. The description +allows for more detail to be provided in a tooltip when the user hovers over the indicator. Returns the currently set text as a `string`. -* `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an __optional__ -`string` parameter to be used to set the class applied to the indicator. Any of -[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs) -may be used here, or a custom CSS class can be provided. Returns the currently defined CSS +- `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an **optional** +`string` parameter to be used to set the class applied to the indicator. Any of +[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs) +may be used here, or a custom CSS class can be provided. Returns the currently defined CSS class as a `string`. -* `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional __ -`string` parameter to be used to set a status class applied to the indicator. May be used to apply +- `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional__ +`string` parameter to be used to set a status class applied to the indicator. May be used to apply different colors to indicate status. ### Custom Indicators @@ -1069,6 +1289,7 @@ Open MCT provides some built-in priority values that can be used in the applicat ### Priority Types Currently, the Open MCT Priority API provides (type: numeric value): + - HIGH: 1000 - Default: 0 - LOW: -1000 @@ -1083,3 +1304,61 @@ View provider Example: } } ``` + +## Visibility-Based Rendering in View Providers + +To enhance performance and resource efficiency in OpenMCT, a visibility-based rendering feature has been added. This feature is designed to defer the execution of rendering logic for views that are not currently visible. It ensures that views are only updated when they are in the viewport, similar to how modern browsers handle rendering of inactive tabs but optimized for the OpenMCT tabbed display. It also works when views are scrolled outside the viewport (e.g., in a Display Layout). + +### Overview + +The show function is responsible for the rendering of a view. An [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) is used internally to determine whether the view is visible. This observer drives the visibility-based rendering feature, accessed via the `renderWhenVisible` function provided in the `viewOptions` parameter. + +### Implementing Visibility-Based Rendering + +The `renderWhenVisible` function is passed to the show function as part of the `viewOptions` object. This function can be used for all rendering logic that would otherwise be executed within a `requestAnimationFrame` call. When called, `renderWhenVisible` will either execute the provided function immediately (via `requestAnimationFrame`) if the view is currently visible, or defer its execution until the view becomes visible. + +Additionally, `renderWhenVisible` returns a boolean value indicating whether the provided function was executed immediately (`true`) or deferred (`false`). + +Monitoring of visibility begins after the first call to `renderWhenVisible` is made. + +Here’s the signature for the show function: + +`show(element, isEditing, viewOptions)` + + * `element` (HTMLElement) - The DOM element where the view should be rendered. + * `isEditing` (boolean) - Indicates whether the view is in editing mode. + * `viewOptions` (Object) - An object with configuration options for the view, including: + * `renderWhenVisible` (Function) - This function wraps the `requestAnimationFrame` and only triggers the provided render logic when the view is visible in the viewport. + +### Example + +An OpenMCT view provider might implement the show function as follows: + +```js +// Define your view provider +const myViewProvider = { + // ... other properties and methods ... + show: function (element, isEditing, viewOptions) { + // Callback for rendering view content + const renderCallback = () => { + // Your view rendering logic goes here + }; + + // Use the renderWhenVisible function to ensure rendering only happens when view is visible + const wasRenderedImmediately = viewOptions.renderWhenVisible(renderCallback); + + // Optionally handle the immediate rendering return value + if (wasRenderedImmediately) { + console.debug('🪞 Rendering triggered immediately as the view is visible.'); + } else { + console.debug('🛑 Rendering has been deferred until the view becomes visible.'); + } + } +}; +``` + + +Note that `renderWhenVisible` defers rendering while the view is not visible and caters to the latest execution call. This provides responsiveness for dynamic content while ensuring performance optimizations. + +Ensure your view logic is prepared to handle potentially multiple deferrals if using this API, as only the last call to renderWhenVisible will be queued for execution upon the view becoming visible. + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8d7e0a4353..674059c34d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ accept changes from external contributors. The short version: -1. Write your contribution or describe your idea in the form of an [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions) +1. Write your contribution or describe your idea in the form of a [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [start a GitHub discussion](https://github.com/nasa/openmct/discussions). 2. Make sure your contribution meets code, test, and commit message standards as described below. 3. Submit a pull request from a topic branch back to `master`. Include a check @@ -18,13 +18,13 @@ The short version: for review.) 4. Respond to any discussion. When the reviewer decides it's ready, they will merge back `master` and fill out their own check list. -5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information. +5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information. ## Contribution Process Open MCT uses git for software version control, and for branching and merging. The central repository is at -https://github.com/nasa/openmct.git. +. ### Roles @@ -116,6 +116,7 @@ the pull request containing the reviewer checklist (from below) and complete the merge back to the master branch. Additionally: + * Every pull request must link to the issue that it addresses. Eg. “Addresses #1234” or “Closes #1234”. This is the responsibility of the pull request’s __author__. If no issue exists, [create one](https://github.com/nasa/openmct/issues/new/choose). * Every __author__ must include testing instructions. These instructions should identify the areas of code affected, and some minimal test steps. If addressing a bug, reproduction steps should be included, if they were not included in the original issue. If reproduction steps were included on the original issue, and are sufficient, refer to them. * A pull request that closes an issue should say so in the description. Including the text “Closes #1234” will cause the linked issue to be automatically closed when the pull request is merged. This is the responsibility of the pull request’s __author__. @@ -132,25 +133,26 @@ changes. ### Code Standards -JavaScript sources in Open MCT must satisfy the ESLint rules defined in -this repository. This is verified by the command line build. +JavaScript sources in Open MCT must satisfy the [ESLint](https://eslint.org/) rules defined in +this repository. [Prettier](https://prettier.io/) is used in conjunction with ESLint to enforce code style +via automated formatting. These are verified by the command line build. #### Code Guidelines The following guidelines are provided for anyone contributing source code to the Open MCT project: -1. Write clean code. Here’s a good summary - https://github.com/ryanmcdermott/clean-code-javascript. +1. Write clean code. Here’s a good summary - . 1. Include JSDoc for any exposed API (e.g. public methods, classes). 1. Include non-JSDoc comments as-needed for explaining private variables, - methods, or algorithms when they are non-obvious. Otherwise code + methods, or algorithms when they are non-obvious. Otherwise code should be self-documenting. 1. Classes and Vue components should use camel case, first letter capitalized (e.g. SomeClassName). 1. Methods, variables, fields, events, and function names should use camelCase, first letter lower-case (e.g. someVariableName). 1. Source files that export functions should use camelCase, first letter lower-case (eg. testTools.js) -1. Constants (variables or fields which are meant to be declared and - initialized statically, and never changed) should use only capital +1. Constants (variables or fields which are meant to be declared and + initialized statically, and never changed) should use only capital letters, with underscores between words (e.g. SOME_CONSTANT). They should always be declared as `const`s 1. File names should be the name of the exported class, plus a .js extension (e.g. SomeClassName.js). @@ -159,21 +161,25 @@ The following guidelines are provided for anyone contributing source code to the (e.g. as arguments to a forEach call). Anonymous functions should always be arrow functions. 1. Named functions are preferred over functions assigned to variables. eg. + ```JavaScript function renameObject(object, newName) { Object.name = newName; } ``` + is preferable to + ```JavaScript const rename = (object, newName) => { Object.name = newName; } ``` + 1. Avoid deep nesting (especially of functions), except where necessary (e.g. due to closure scope). 1. End with a single new-line character. -1. Always use ES6 `Class`es and inheritance rather than the pre-ES6 prototypal +1. Always use ES6 `Class`es and inheritance rather than the pre-ES6 prototypal pattern. 1. Within a given function's scope, do not mix declarations and imperative code, and present these in the following order: @@ -182,19 +188,24 @@ The following guidelines are provided for anyone contributing source code to the * Finally, the returned value. A single return statement at the end of the function should be used, except where an early return would improve code clarity. 1. Avoid the use of "magic" values. eg. + ```JavaScript const UNAUTHORIZED = 401; if (responseCode === UNAUTHORIZED) ``` + is preferable to + ```JavaScript if (responseCode === 401) ``` + 1. Use the ternary operator only for simple cases such as variable assignment. Nested ternaries should be avoided in all cases. -1. Test specs should reside alongside the source code they test, not in a separate directory. +1. Unit Test specs should reside alongside the source code they test, not in a separate directory. 1. Organize code by feature, not by type. eg. - ``` + + ```txt - telemetryTable - row TableRow.js @@ -206,8 +217,10 @@ The following guidelines are provided for anyone contributing source code to the plugin.js pluginSpec.js ``` + is preferable to - ``` + + ```txt - telemetryTable - components TableRow.vue @@ -219,47 +232,10 @@ The following guidelines are provided for anyone contributing source code to the plugin.js pluginSpec.js ``` + Deviations from Open MCT code style guidelines require two-party agreement, typically from the author of the change and its reviewer. -### Test Standards - -Automated testing shall occur whenever changes are merged into the main -development branch and must be confirmed alongside any pull request. - -Automated tests are tests which exercise plugins, API, and utility classes. -Tests are subject to code review along with the actual implementation, to -ensure that tests are applicable and useful. - -Examples of useful tests: -* Tests which replicate bugs (or their root causes) to verify their - resolution. -* Tests which reflect details from software specifications. -* Tests which exercise edge or corner cases among inputs. -* Tests which verify expected interactions with other components in the - system. - -#### Guidelines -* 100% statement coverage is achievable and desirable. -* Do blackbox testing. Test external behaviors, not internal details. Write tests that describe what your plugin is supposed to do. How it does this doesn't matter, so don't test it. -* Unit test specs for plugins should be defined at the plugin level. Start with one test spec per plugin named pluginSpec.js, and as this test spec grows too big, break it up into multiple test specs that logically group related tests. -* Unit tests for API or for utility functions and classes may be defined at a per-source file level. -* Wherever possible only use and mock public API, builtin functions, and UI in your test specs. Do not directly invoke any private functions. ie. only call or mock functions and objects exposed by openmct.* (eg. openmct.telemetry, openmct.objectView, etc.), and builtin browser functions (fetch, requestAnimationFrame, setTimeout, etc.). -* Where builtin functions have been mocked, be sure to clear them between tests. -* Test at an appropriate level of isolation. Eg. - * If you’re testing a view, you do not need to test the whole application UI, you can just fetch the view provider using the public API and render the view into an element that you have created. - * You do not need to test that the view switcher works, there should be separate tests for that. - * You do not need to test that telemetry providers work, you can mock openmct.telemetry.request() to feed test data to the view. - * Use your best judgement when deciding on appropriate scope. -* Automated tests for plugins should start by actually installing the plugin being tested, and then test that installing the plugin adds the desired features and behavior to Open MCT, observing the above rules. -* All variables used in a test spec, including any instances of the Open MCT API should be declared inside of an appropriate block scope (not at the root level of the source file), and should be initialized in the relevant beforeEach block. `beforeEach` is preferable to `beforeAll` to avoid leaking of state between tests. -* A `afterEach` or `afterAll` should be used to do any clean up necessary to prevent leakage of state between test specs. This can happen when functions on `window` are wrapped, or when the URL is changed. [A convenience function](https://github.com/nasa/openmct/blob/master/src/utils/testing.js#L59) is provided for resetting the URL and clearing builtin spies between tests. -* If writing unit tests for legacy Angular code be sure to follow [best practices in order to avoid memory leaks](https://www.thecodecampus.de/blog/avoid-memory-leaks-angularjs-unit-tests/). - -#### Examples -* [Example of an automated test spec for an object view plugin](https://github.com/nasa/openmct/blob/master/src/plugins/telemetryTable/pluginSpec.js) -* [Example of an automated test spec for API](https://github.com/nasa/openmct/blob/master/src/api/time/TimeAPISpec.js) - ### Commit Message Standards Commit messages should: @@ -295,13 +271,13 @@ these standards. ## Issue Reporting -Issues are tracked at https://github.com/nasa/openmct/issues. +Issues are tracked at . Issue severity is categorized as follows (in ascending order): * _Trivial_: Minimal impact on the usefulness and functionality of the software; a "nice-to-have." Visual impact without functional impact, * _Medium_: Some impairment of use, but simple workarounds exist -* _Critical_: Significant loss of functionality or impairment of use. Display of telemetry data is not affected though. +* _Critical_: Significant loss of functionality or impairment of use. Display of telemetry data is not affected though. Complex workarounds exist. * _Blocker_: Major functionality is impaired or lost, threatening mission success. Display of telemetry data is impaired or blocked by the bug, which could lead to loss of situational awareness. ## Check Lists @@ -310,22 +286,4 @@ The following check lists should be completed and attached to pull requests when they are filed (author checklist) and when they are merged (reviewer checklist). -### Author Checklist - [Within PR Template](.github/PULL_REQUEST_TEMPLATE.md) - -### Reviewer Checklist - -* [ ] Changes appear to address issue? -* [ ] Changes appear not to be breaking changes? -* [ ] Appropriate unit tests included? -* [ ] Code style and in-line documentation are appropriate? -* [ ] Commit messages meet standards? -* [ ] Has associated issue been labelled `unverified`? (only applicable if this PR closes the issue) -* [ ] Has associated issue been labelled `bug`? (only applicable if this PR is for a bug fix) -* [ ] List of Acceptance Tests Performed. - -Write out a small list of tests performed with just enough detail for another developer on the team -to execute. - -i.e. ```When Clicking on Add button, new `object` appears in dropdown.``` diff --git a/LICENSE.md b/LICENSE.md index 2e87024fd1..6f5fecba6c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # Open MCT License -Open MCT, Copyright (c) 2014-2022, United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All rights reserved. +Open MCT, Copyright (c) 2014-2024, United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All rights reserved. Open MCT is 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. diff --git a/Procfile b/Procfile deleted file mode 100644 index 1e13b4ae05..0000000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: node app.js --port $PORT diff --git a/README.md b/README.md index dc685fac11..78335fbb99 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,49 @@ -# Open MCT [![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/nasa/openmct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/nasa/openmct/context:javascript) [![codecov](https://codecov.io/gh/nasa/openmct/branch/master/graph/badge.svg?token=7DQIipp3ej)](https://codecov.io/gh/nasa/openmct) [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/b2e34b17/openmct) [![npm version](https://img.shields.io/npm/v/openmct.svg)](https://www.npmjs.com/package/openmct) +# Open MCT [![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![codecov](https://codecov.io/gh/nasa/openmct/branch/master/graph/badge.svg?token=7DQIipp3ej)](https://codecov.io/gh/nasa/openmct) [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/b2e34b17/openmct) [![npm version](https://img.shields.io/npm/v/openmct.svg)](https://www.npmjs.com/package/openmct) ![CodeQL](https://github.com/nasa/openmct/workflows/CodeQL/badge.svg) Open MCT (Open Mission Control Technologies) is a next-generation mission control framework for visualization of data on desktop and mobile devices. It is developed at NASA's Ames Research Center, and is being used by NASA for data analysis of spacecraft missions, as well as planning and operation of experimental rover systems. As a generalizable and open source framework, Open MCT could be used as the basis for building applications for planning, operation, and analysis of any systems producing telemetry data. -Please visit our [Official Site](https://nasa.github.io/openmct/) and [Getting Started Guide](https://nasa.github.io/openmct/getting-started/) +> [!NOTE] +> Please visit our [Official Site](https://nasa.github.io/openmct/) and [Getting Started Guide](https://nasa.github.io/openmct/getting-started/) + Once you've created something amazing with Open MCT, showcase your work in our GitHub Discussions [Show and Tell](https://github.com/nasa/openmct/discussions/categories/show-and-tell) section. We love seeing unique and wonderful implementations of Open MCT! -## See Open MCT in Action +![Screen Shot 2022-11-23 at 9 51 36 AM](https://user-images.githubusercontent.com/4215777/203617422-4d912bfc-766f-4074-8324-409d9bbe7c05.png) -Try Open MCT now with our [live demo](https://openmct-demo.herokuapp.com/). -![Demo](https://nasa.github.io/openmct/static/res/images/Open-MCT.Browse.Layout.Mars-Weather-1.jpg) ## Building and Running Open MCT Locally Building and running Open MCT in your local dev environment is very easy. Be sure you have [Git](https://git-scm.com/downloads) and [Node.js](https://nodejs.org/) installed, then follow the directions below. Need additional information? Check out the [Getting Started](https://nasa.github.io/openmct/getting-started/) page on our website. (These instructions assume you are installing as a non-root user; developers have [reported issues](https://github.com/nasa/openmct/issues/1151) running these steps with root privileges.) -1. Clone the source code +1. Clone the source code: - `git clone https://github.com/nasa/openmct.git` +``` +git clone https://github.com/nasa/openmct.git +``` -2. Install development dependencies. Note: Check the package.json engine for our tested and supported node versions. +2. (Optional) Install the correct node version using [nvm](https://github.com/nvm-sh/nvm): - `npm install` +``` +nvm install +``` -3. Run a local development server +3. Install development dependencies (Note: Check the `package.json` engine for our tested and supported node versions): - `npm start` +``` +npm install +``` -Open MCT is now running, and can be accessed by pointing a web browser at [http://localhost:8080/](http://localhost:8080/) +4. Run a local development server: + +``` +npm start +``` + +> [!IMPORTANT] +> Open MCT is now running, and can be accessed by pointing a web browser at [http://localhost:8080/](http://localhost:8080/) + +Open MCT is built using [`npm`](http://npmjs.com/) and [`webpack`](https://webpack.js.org/). ## Documentation @@ -40,19 +55,23 @@ The clearest examples for developing Open MCT plugins are in the [tutorials](https://github.com/nasa/openmct-tutorial) provided in our documentation. -We want Open MCT to be as easy to use, install, run, and develop for as -possible, and your feedback will help us get there! Feedback can be provided via [GitHub issues](https://github.com/nasa/openmct/issues/new/choose), [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions), or by emailing us at [arc-dl-openmct@mail.nasa.gov](mailto:arc-dl-openmct@mail.nasa.gov). +> [!NOTE] +> We want Open MCT to be as easy to use, install, run, and develop for as +> possible, and your feedback will help us get there! +> Feedback can be provided via [GitHub issues](https://github.com/nasa/openmct/issues/new/choose), +> [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions), +> or by emailing us at [arc-dl-openmct@mail.nasa.gov](mailto:arc-dl-openmct@mail.nasa.gov). -## Building Applications With Open MCT +## Developing Applications With Open MCT -Open MCT is built using [`npm`](http://npmjs.com/) and [`webpack`](https://webpack.js.org/). - -See our documentation for a guide on [building Applications with Open MCT](https://github.com/nasa/openmct/blob/master/API.md#starting-an-open-mct-application). +For more on developing with Open MCT, see our documentation for a guide on [Developing Applications with Open MCT](./API.md#starting-an-open-mct-application). ## Compatibility This is a fast moving project and we do our best to test and support the widest possible range of browsers, operating systems, and nodejs APIs. We have a published list of support available in our package.json's `browserslist` key. +The project uses `nvm` to ensure the node and npm version used, is coherent in all projects. Install nvm (non-windows), [here](https://github.com/nvm-sh/nvm) or the windows equivalent [here](https://github.com/coreybutler/nvm-windows) + If you encounter an issue with a particular browser, OS, or nodejs API, please file a [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) ## Plugins @@ -64,7 +83,7 @@ that is intended to be added or removed as a single unit. As well as providing an extension mechanism, most of the core Open MCT codebase is also written as plugins. -For information on writing plugins, please see [our API documentation](https://github.com/nasa/openmct/blob/master/API.md#plugins). +For information on writing plugins, please see [our API documentation](./API.md#plugins). ## Tests @@ -97,10 +116,10 @@ To run the performance tests: `npm run test:perf` -The test suite is configured to all tests localed in `e2e/tests/` ending in `*.e2e.spec.js`. For more about the e2e test suite, please see the [README](./e2e/README.md) +The test suite is configured to all tests located in `e2e/tests/` ending in `*.e2e.spec.js`. For more about the e2e test suite, please see the [README](./e2e/README.md) ### Security Tests -Each commit is analyzed for known security vulnerabilities using [CodeQL](https://codeql.github.com/docs/codeql-language-guides/codeql-library-for-javascript/) and our overall security report is available on [LGTM](https://lgtm.com/projects/g/nasa/openmct/) +Each commit is analyzed for known security vulnerabilities using [CodeQL](https://codeql.github.com/docs/codeql-language-guides/codeql-library-for-javascript/). The list of CWE coverage items is available in the [CodeQL docs](https://codeql.github.com/codeql-query-help/javascript-cwe/). The CodeQL workflow is specified in the [CodeQL analysis file](./.github/workflows/codeql-analysis.yml) and the custom [CodeQL config](./.github/codeql/codeql-config.yml). ### Test Reporting and Code Coverage @@ -108,6 +127,8 @@ Each test suite generates a report in CircleCI. For a complete overview of testi Our code coverage is generated during the runtime of our unit, e2e, and visual tests. The combination of those reports is published to [codecov.io](https://app.codecov.io/gh/nasa/openmct/) +For more on the specifics of our code coverage setup, [see](TESTING.md#code-coverage) + # Glossary Certain terms are used throughout Open MCT with consistent meanings @@ -163,3 +184,17 @@ You might still be using legacy API if your source code ### What should I do if I am using legacy API? Please refer to [the modern Open MCT API](https://nasa.github.io/openmct/documentation/). Post any questions to the [Discussions section](https://github.com/nasa/openmct/discussions) of the Open MCT GitHub repository. + +## Related Repos + +> [!NOTE] +> Although Open MCT functions as a standalone project, it is primarily an extensible framework intended to be used as a dependency with users' own plugins and packaging. Furthermore, Open MCT is intended to be used with an HTTP server such as Apache or Nginx. A great example of hosting Open MCT with Apache is `openmct-quickstart` and can be found in the table below. + +| Repository | Description | +| --- | --- | +| [openmct-tutorial](https://github.com/nasa/openmct-tutorial) | A great place for beginners to learn how to use and extend Open MCT. | +| [openmct-quickstart](https://github.com/scottbell/openmct-quickstart) | A working example of Open MCT integrated with Apache HTTP server, YAMCS telemetry, and Couch DB for persistence. +| [Open MCT YAMCS Plugin](https://github.com/akhenry/openmct-yamcs) | Plugin for integrating YAMCS telemetry and command server with Open MCT. | +| [openmct-performance](https://github.com/unlikelyzero/openmct-performance) | Resources for performance testing Open MCT. | +| [openmct-as-a-dependency](https://github.com/unlikelyzero/openmct-as-a-dependency) | An advanced guide for users on how to build, develop, and test Open MCT when it's used as a dependency. | + diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000000..68e4e3ad1f --- /dev/null +++ b/TESTING.md @@ -0,0 +1,120 @@ +# Testing +Open MCT Testing is iterating and improving at a rapid pace. This document serves to capture and index existing testing documentation and house documentation which no other obvious location as our testing evolves. + +## General Testing Process +Documentation located [here](./docs/src/process/testing/plan.md) + +## Unit Testing +Unit testing is essential part of our test strategy and complements our e2e testing strategy. + +#### Unit Test Guidelines +* Unit Test specs should reside alongside the source code they test, not in a separate directory. +* Unit test specs for plugins should be defined at the plugin level. Start with one test spec per plugin named pluginSpec.js, and as this test spec grows too big, break it up into multiple test specs that logically group related tests. +* Unit tests for API or for utility functions and classes may be defined at a per-source file level. +* Wherever possible only use and mock public API, builtin functions, and UI in your test specs. Do not directly invoke any private functions. ie. only call or mock functions and objects exposed by openmct.* (eg. openmct.telemetry, openmct.objectView, etc.), and builtin browser functions (fetch, requestAnimationFrame, setTimeout, etc.). +* Where builtin functions have been mocked, be sure to clear them between tests. +* Test at an appropriate level of isolation. Eg. + * If you’re testing a view, you do not need to test the whole application UI, you can just fetch the view provider using the public API and render the view into an element that you have created. + * You do not need to test that the view switcher works, there should be separate tests for that. + * You do not need to test that telemetry providers work, you can mock openmct.telemetry.request() to feed test data to the view. + * Use your best judgement when deciding on appropriate scope. +* Automated tests for plugins should start by actually installing the plugin being tested, and then test that installing the plugin adds the desired features and behavior to Open MCT, observing the above rules. +* All variables used in a test spec, including any instances of the Open MCT API should be declared inside of an appropriate block scope (not at the root level of the source file), and should be initialized in the relevant beforeEach block. `beforeEach` is preferable to `beforeAll` to avoid leaking of state between tests. +* A `afterEach` or `afterAll` should be used to do any clean up necessary to prevent leakage of state between test specs. This can happen when functions on `window` are wrapped, or when the URL is changed. [A convenience function](https://github.com/nasa/openmct/blob/master/src/utils/testing.js#L59) is provided for resetting the URL and clearing builtin spies between tests. + +#### Unit Test Examples +* [Example of an automated test spec for an object view plugin](https://github.com/nasa/openmct/blob/master/src/plugins/telemetryTable/pluginSpec.js) +* [Example of an automated test spec for API](https://github.com/nasa/openmct/blob/master/src/api/time/TimeAPISpec.js) + +#### Unit Testing Execution + +The unit tests can be executed in one of two ways: +`npm run test` which runs the entire suite against headless chrome +`npm run test:debug` for debugging the tests in realtime in an active chrome session. + +## e2e, performance, and visual testing +Documentation located [here](./e2e/README.md) + +## Code Coverage + +It's up to the individual developer as to whether they want to add line coverage in the form of a unit test or e2e test. + +Line Code Coverage is generated by our unit tests and e2e tests, then combined by ([Codecov.io Flags](https://docs.codecov.com/docs/flags)), and finally reported in GitHub PRs by Codecov.io's PR Bot. This workflow gives a comprehensive (if flawed) view of line coverage. + +### Karma-istanbul + +Line coverage is generated by our `karma-coverage-istanbul-reporter` package as defined in our `karma.conf.js` file: + +```js + coverageIstanbulReporter: { + fixWebpackSourcePaths: true, + skipFilesWithNoCoverage: true, + dir: 'coverage/unit', //Sets coverage file to be consumed by codecov.io + reports: ['lcovonly'] + }, +``` + +Once the file is generated, it can be published to codecov with + +```json + "cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit", +``` + +### e2e +The e2e line coverage is a bit more complex than the karma implementation. This is the general sequence of events: + +1. Each e2e suite will start webpack with the ```npm run start:coverage``` command with config `webpack.coverage.js` and the `babel-plugin-istanbul` plugin to generate code coverage during e2e test execution using our custom [baseFixture](./baseFixtures.js). +1. During testcase execution, each e2e shard will generate its piece of the larger coverage suite. **This coverage file is not merged**. The raw coverage file is stored in a `.nyc_report` directory. +1. [nyc](https://github.com/istanbuljs/nyc) converts this directory into a `lcov` file with the following command `npm run cov:e2e:report` +1. Most of the tests are run in the '@stable' configuration and focus on chrome/ubuntu at a single resolution. This coverage is published to codecov with `npm run cov:e2e:stable:publish`. +1. The rest of our coverage only appears when run against `@unstable` tests, persistent datastore (couchdb), non-ubuntu machines, and non-chrome browsers with the `npm run cov:e2e:full:publish` flag. Since this happens about once a day, we have leveraged codecov.io's carryforward flag to report on lines covered outside of each commit on an individual PR. + + +### Limitations in our code coverage reporting +Our code coverage implementation has some known limitations: +- [Variability](https://github.com/nasa/openmct/issues/5811) +- [Accuracy](https://github.com/nasa/openmct/issues/7015) +- [Vue instrumentation gaps](https://github.com/nasa/openmct/issues/4973) + +## Troubleshooting CI +The following is an evolving guide to troubleshoot CI and PR issues. + +### Github Checks failing +There are a few reasons that your GitHub PR could be failing beyond simple failed tests. +* Required Checks. We're leveraging required checks in GitHub so that we can quickly and precisely control what becomes and informational failure vs a hard requirement. The only way to determine the difference between a required vs information check is check for the `(Required)` emblem next to the step details in GitHub Checks. +* Not all required checks are run per commit. You may need to manually trigger addition GitHub checks with a `pr: