Skip to content

Commit

Permalink
chore: upgrade eventemitter to v5.0.2 (#7709)
Browse files Browse the repository at this point in the history
* chore: upgrade eventemitter to v5.0.2
* fix: pass context to eventHelpers
* fix: no need to destroy router as it is destroyed during openmct teardown
* fix: register `CreateAction` and retrieve it from the registry
* test: fix tests
* refactor: import action key consts
* fix: update usage. don't use getters
Co-authored-by: David Tsay <3614296+davetsay@users.noreply.github.com>

---------

Co-authored-by: David Tsay <3614296+davetsay@users.noreply.github.com>
  • Loading branch information
ozyx and davetsay committed May 14, 2024
1 parent 810d580 commit 017380b
Show file tree
Hide file tree
Showing 56 changed files with 630 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .webpack/webpack.coverage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ information to pull requests.

import config from './webpack.dev.mjs';

config.devtool = 'source-map';
config.devtool = 'inline-source-map';
config.devServer.hot = false;

config.module.rules.push({
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"eslint-plugin-unicorn": "49.0.0",
"eslint-plugin-vue": "9.22.0",
"eslint-plugin-you-dont-need-lodash-underscore": "6.13.0",
"eventemitter3": "1.2.0",
"eventemitter3": "5.0.1",

This comment has been minimized.

Copy link
@ozyx

ozyx May 14, 2024

Author Member

whoops. the title of this change should be 5.0.1

"file-saver": "2.0.5",
"flatbush": "4.2.0",
"git-rev-sync": "3.0.2",
Expand Down
2 changes: 0 additions & 2 deletions src/MCT.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import Browse from './ui/router/Browse.js';
export class MCT extends EventEmitter {
constructor() {
super();
EventEmitter.call(this);

this.buildInfo = {
version: __OPENMCT_VERSION__,
Expand Down Expand Up @@ -371,6 +370,5 @@ export class MCT extends EventEmitter {
destroy() {
window.removeEventListener('beforeunload', this.destroy);
this.emit('destroy');
this.router.destroy();
}
}
19 changes: 12 additions & 7 deletions src/plugins/LADTable/components/LadRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@
</template>

<script>
const CONTEXT_MENU_ACTIONS = ['viewDatumAction', 'viewHistoricalData', 'remove'];
const BLANK_VALUE = '---';
import { objectPathToUrl } from '/src/tools/url.js';
import PreviewAction from '@/ui/preview/PreviewAction.js';
import { REMOVE_ACTION_KEY } from '@/plugins/remove/RemoveAction.js';
import { VIEW_DATUM_ACTION_KEY } from '@/plugins/viewDatumAction/ViewDatumAction.js';
import { PREVIEW_ACTION_KEY } from '@/ui/preview/PreviewAction.js';
import { VIEW_HISTORICAL_DATA_ACTION_KEY } from '@/ui/preview/ViewHistoricalDataAction.js';
import tooltipHelpers from '../../../api/tooltips/tooltipMixins.js';
const BLANK_VALUE = '---';
const CONTEXT_MENU_ACTIONS = [
VIEW_DATUM_ACTION_KEY,
VIEW_HISTORICAL_DATA_ACTION_KEY,
REMOVE_ACTION_KEY
];
export default {
mixins: [tooltipHelpers],
inject: ['openmct', 'currentView', 'renderWhenVisible'],
Expand Down Expand Up @@ -236,14 +243,12 @@ export default {
this.setUnit();
}
this.previewAction = new PreviewAction(this.openmct);
this.previewAction.on('isVisible', this.togglePreviewState);
this.previewAction = this.openmct.actions.getAction(PREVIEW_ACTION_KEY);
},
unmounted() {
this.openmct.time.off('timeSystem', this.updateTimeSystem);
this.telemetryCollection.off('add', this.setLatestValues);
this.telemetryCollection.off('clear', this.resetValues);
this.previewAction.off('isVisible', this.togglePreviewState);
this.telemetryCollection.destroy();
},
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/clearData/ClearDataAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ function inSelectionPath(openmct, domainObject) {
});
}

export default class ClearDataAction {
const CLEAR_DATA_ACTION_KEY = 'clear-data-action';
class ClearDataAction {
constructor(openmct, appliesToObjects) {
this.name = 'Clear Data for Object';
this.key = 'clear-data-action';
this.key = CLEAR_DATA_ACTION_KEY;
this.description = 'Clears current data for object, unsubscribes and resubscribes to data';
this.cssClass = 'icon-clear-data';

this._openmct = openmct;
this._appliesToObjects = appliesToObjects;
}

invoke(objectPath) {
let domainObject = null;
if (objectPath) {
Expand Down Expand Up @@ -76,3 +78,7 @@ export default class ClearDataAction {
}
}
}

export { CLEAR_DATA_ACTION_KEY };

export default ClearDataAction;
4 changes: 2 additions & 2 deletions src/plugins/condition/components/inspector/StylesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ import {
getConditionSetIdentifierForItem,
getConsolidatedStyleValues
} from '@/plugins/condition/utils/styleUtils';
import PreviewAction from '@/ui/preview/PreviewAction.js';
import { PREVIEW_ACTION_KEY } from '@/ui/preview/PreviewAction.js';
import FontStyleEditor from '../../../inspectorViews/styles/FontStyleEditor.vue';
import StyleEditor from './StyleEditor.vue';
Expand Down Expand Up @@ -237,7 +237,7 @@ export default {
this.stylesManager.off('styleSelected', this.applyStyleToSelection);
},
mounted() {
this.previewAction = new PreviewAction(this.openmct);
this.previewAction = this.openmct.actions.getAction(PREVIEW_ACTION_KEY);
this.isMultipleSelection = this.selection.length > 1;
this.getObjectsAndItemsFromSelection();
this.useConditionSetOutputAsLabel = this.getConfigurationForLabel();
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/displayLayout/actions/CopyToClipboardAction.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import clipboard from '@/utils/clipboard';

export default class CopyToClipboardAction {
const COPY_TO_CLIPBOARD_ACTION_KEY = 'copyToClipboard';

class CopyToClipboardAction {
constructor(openmct) {
this.openmct = openmct;

this.cssClass = 'icon-duplicate';
this.description = 'Copy value to clipboard';
this.group = 'action';
this.key = 'copyToClipboard';
this.key = COPY_TO_CLIPBOARD_ACTION_KEY;
this.name = 'Copy to Clipboard';
this.priority = 1;
}
Expand Down Expand Up @@ -36,3 +38,7 @@ export default class CopyToClipboardAction {
return row.formattedValueForCopy && typeof row.formattedValueForCopy === 'function';
}
}

export { COPY_TO_CLIPBOARD_ACTION_KEY };

export default CopyToClipboardAction;
11 changes: 9 additions & 2 deletions src/plugins/displayLayout/components/TelemetryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,26 @@
</template>

<script>
import { COPY_TO_CLIPBOARD_ACTION_KEY } from '@/plugins/displayLayout/actions/CopyToClipboardAction.js';
import { COPY_TO_NOTEBOOK_ACTION_KEY } from '@/plugins/notebook/actions/CopyToNotebookAction.js';
import {
getDefaultNotebook,
getNotebookSectionAndPage
} from '@/plugins/notebook/utils/notebook-storage.js';
import stalenessMixin from '@/ui/mixins/staleness-mixin';
import { VIEW_HISTORICAL_DATA_ACTION_KEY } from '@/ui/preview/ViewHistoricalDataAction.js';
import tooltipHelpers from '../../../api/tooltips/tooltipMixins.js';
import conditionalStylesMixin from '../mixins/objectStyles-mixin.js';
import LayoutFrame from './LayoutFrame.vue';
const DEFAULT_TELEMETRY_DIMENSIONS = [10, 5];
const DEFAULT_POSITION = [1, 1];
const CONTEXT_MENU_ACTIONS = ['copyToClipboard', 'copyToNotebook', 'viewHistoricalData'];
const CONTEXT_MENU_ACTIONS = [
COPY_TO_CLIPBOARD_ACTION_KEY,
COPY_TO_NOTEBOOK_ACTION_KEY,
VIEW_HISTORICAL_DATA_ACTION_KEY
];
export default {
makeDefinition(openmct, gridSize, domainObject, position) {
Expand Down Expand Up @@ -381,7 +388,7 @@ export default {
return CONTEXT_MENU_ACTIONS.map((actionKey) => {
const action = this.openmct.actions.getAction(actionKey);
if (action.key === 'copyToNotebook') {
if (action.key === COPY_TO_NOTEBOOK_ACTION_KEY) {
action.name = defaultNotebookName;
}
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/duplicate/DuplicateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
*****************************************************************************/
import DuplicateTask from './DuplicateTask.js';

export default class DuplicateAction {
const DUPLICATE_ACTION_KEY = 'duplicate';

class DuplicateAction {
constructor(openmct) {
this.name = 'Duplicate';
this.key = 'duplicate';
this.key = DUPLICATE_ACTION_KEY;
this.description = 'Duplicate this object.';
this.cssClass = 'icon-duplicate';
this.group = 'action';
Expand Down Expand Up @@ -169,3 +171,7 @@ export default class DuplicateAction {
this.transaction = null;
}
}

export { DUPLICATE_ACTION_KEY };

export default DuplicateAction;
9 changes: 7 additions & 2 deletions src/plugins/exportAsJSONAction/ExportAsJSONAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import { v4 as uuid } from 'uuid';

import JSONExporter from '/src/exporters/JSONExporter.js';
const EXPORT_AS_JSON_ACTION_KEY = 'export.JSON';

export default class ExportAsJSONAction {
class ExportAsJSONAction {
#openmct;

/**
Expand All @@ -39,7 +40,7 @@ export default class ExportAsJSONAction {
this.saveAs = this.saveAs.bind(this);

this.name = 'Export as JSON';
this.key = 'export.JSON';
this.key = EXPORT_AS_JSON_ACTION_KEY;
this.description = '';
this.cssClass = 'icon-export';
this.group = 'export';
Expand Down Expand Up @@ -410,3 +411,7 @@ export default class ExportAsJSONAction {
return JSON.parse(JSON.stringify(object));
}
}

export { EXPORT_AS_JSON_ACTION_KEY };

export default ExportAsJSONAction;
25 changes: 16 additions & 9 deletions src/plugins/formActions/CreateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ import { v4 as uuid } from 'uuid';
import CreateWizard from './CreateWizard.js';
import PropertiesAction from './PropertiesAction.js';

export default class CreateAction extends PropertiesAction {
const CREATE_ACTION_KEY = 'create';

class CreateAction extends PropertiesAction {
#transaction;

constructor(openmct, type, parentDomainObject) {
constructor(openmct) {
super(openmct);

this.type = type;
this.parentDomainObject = parentDomainObject;
this.#transaction = null;
this.key = CREATE_ACTION_KEY;
// Hide the create action from context menus by default
this.isHidden = true;
}

invoke() {
this._showCreateForm(this.type);
get invoke() {
return (type, parentDomainObject) => this._showCreateForm(type, parentDomainObject);
}

/**
Expand Down Expand Up @@ -142,15 +145,15 @@ export default class CreateAction extends PropertiesAction {
/**
* @private
*/
_showCreateForm(type) {
_showCreateForm(type, parentDomainObject) {
const typeDefinition = this.openmct.types.get(type);
const definition = typeDefinition.definition;
const domainObject = {
name: `Unnamed ${definition.name}`,
type,
identifier: {
key: uuid(),
namespace: this.parentDomainObject.identifier.namespace
namespace: parentDomainObject.identifier.namespace
}
};

Expand All @@ -160,7 +163,7 @@ export default class CreateAction extends PropertiesAction {
definition.initialize(this.domainObject);
}

const createWizard = new CreateWizard(this.openmct, this.domainObject, this.parentDomainObject);
const createWizard = new CreateWizard(this.openmct, this.domainObject, parentDomainObject);
const formStructure = createWizard.getFormStructure(true);
formStructure.title = 'Create a New ' + definition.name;

Expand Down Expand Up @@ -191,3 +194,7 @@ export default class CreateAction extends PropertiesAction {
this.#transaction = null;
}
}

export { CREATE_ACTION_KEY };

export default CreateAction;
6 changes: 3 additions & 3 deletions src/plugins/formActions/CreateActionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { debounce } from 'lodash';
import { createOpenMct, resetApplicationState } from 'utils/testing';

import CreateAction from './CreateAction.js';
import { CREATE_ACTION_KEY } from './CreateAction.js';

let parentObject;
let parentObjectPath;
Expand Down Expand Up @@ -115,8 +115,8 @@ describe('The create action plugin', () => {
const deBouncedCallback = debounce(callback, 300);
unObserve = openmct.objects.observe(parentObject, '*', deBouncedCallback);

const createAction = new CreateAction(openmct, type, parentObject);
createAction.invoke();
const createAction = openmct.actions.getAction(CREATE_ACTION_KEY);
createAction.invoke(type, parentObject);
});
});
});
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/formActions/EditPropertiesAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import _ from 'lodash';

import CreateWizard from './CreateWizard.js';
import PropertiesAction from './PropertiesAction.js';
const EDIT_PROPERTIES_ACTION_KEY = 'properties';

export default class EditPropertiesAction extends PropertiesAction {
class EditPropertiesAction extends PropertiesAction {
constructor(openmct) {
super(openmct);

this.name = 'Edit Properties...';
this.key = 'properties';
this.key = EDIT_PROPERTIES_ACTION_KEY;
this.description = 'Edit properties of this object.';
this.cssClass = 'major icon-pencil';
this.hideInDefaultMenu = true;
Expand Down Expand Up @@ -100,3 +101,7 @@ export default class EditPropertiesAction extends PropertiesAction {
.catch(this._onCancel.bind(this));
}
}

export { EDIT_PROPERTIES_ACTION_KEY };

export default EditPropertiesAction;
2 changes: 2 additions & 0 deletions src/plugins/formActions/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

import CreateAction from './CreateAction.js';
import EditPropertiesAction from './EditPropertiesAction.js';

export default function () {
return function (openmct) {
openmct.actions.register(new EditPropertiesAction(openmct));
openmct.actions.register(new CreateAction(openmct));
};
}

0 comments on commit 017380b

Please sign in to comment.