Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce bundle size #7246

Merged
merged 14 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const config = {
csv: 'comma-separated-values',
EventEmitter: 'eventemitter3',
bourbon: 'bourbon.scss',
'plotly-basic': 'plotly.js-basic-dist',
'plotly-gl2d': 'plotly.js-gl2d-dist',
printj: path.join(projectRootDir, 'node_modules/printj/dist/printj.min.js'),
'plotly-basic': 'plotly.js-basic-dist-min',
'plotly-gl2d': 'plotly.js-gl2d-dist-min',
printj: 'printj/printj.mjs',
ozyx marked this conversation as resolved.
Show resolved Hide resolved
styles: path.join(projectRootDir, 'src/styles'),
MCT: path.join(projectRootDir, 'src/MCT'),
testUtils: path.join(projectRootDir, 'src/utils/testUtils.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/

/* global __dirname */
/*
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks.
*/

const fs = require('fs').promises;
const path = require('path');
const { test, expect } = require('../../../../pluginFixtures');
const { createDomainObjectWithDefaults } = require('../../../../appActions');

Expand Down Expand Up @@ -176,7 +177,9 @@ test.describe('Snapshot image tests', () => {
});

test('Can drop an image onto a notebook and create a new entry', async ({ page }) => {
const imageData = await fs.readFile('src/images/favicons/favicon-96x96.png');
const imageData = await fs.readFile(
path.resolve(__dirname, '../../../../../src/images/favicons/favicon-96x96.png')
);
const imageArray = new Uint8Array(imageData);
const fileData = Array.from(imageArray);

Expand All @@ -201,14 +204,17 @@ test.describe('Snapshot image tests', () => {
// drop another image onto the entry
await page.dispatchEvent('.c-snapshots', 'drop', { dataTransfer: dropTransfer });

const secondThumbnail = page.getByRole('img', { name: 'favicon-96x96.png thumbnail' }).nth(1);
await secondThumbnail.waitFor({ state: 'attached' });
// expect two embedded images now
expect(await page.getByRole('img', { name: 'favicon-96x96.png thumbnail' }).count()).toBe(2);

await page.locator('.c-snapshot.c-ne__embed').first().getByTitle('More options').click();

await page.getByRole('menuitem', { name: /Remove This Embed/ }).click();

await page.getByRole('button', { name: 'Ok', exact: true }).click();
// Ensure that the thumbnail is removed before we assert
await secondThumbnail.waitFor({ state: 'detached' });

// expect one embedded image now as we deleted the other
expect(await page.getByRole('img', { name: 'favicon-96x96.png thumbnail' }).count()).toBe(1);
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"@percy/cli": "1.27.4",
"@percy/playwright": "1.0.4",
"@playwright/test": "1.39.0",
"@types/d3-axis": "3.0.6",
"@types/d3-scale": "4.0.8",
"@types/d3-selection": "3.0.10",
"@types/eventemitter3": "1.2.0",
"@types/jasmine": "5.1.2",
"@types/lodash": "4.14.192",
Expand Down Expand Up @@ -62,8 +65,8 @@
"npm-run-all2": "6.1.1",
"nyc": "15.1.0",
"painterro": "1.2.87",
"plotly.js-basic-dist": "2.20.0",
"plotly.js-gl2d-dist": "2.20.0",
"plotly.js-basic-dist-min": "2.20.0",
"plotly.js-gl2d-dist-min": "2.20.0",
"prettier": "2.8.7",
"printj": "1.3.1",
"resolve-url-loader": "5.0.0",
Expand All @@ -72,6 +75,7 @@
"sass-loader": "13.3.2",
"sinon": "17.0.0",
"style-loader": "3.3.3",
"terser-webpack-plugin": "5.3.9",
"tiny-emitter": "2.1.0",
"typescript": "5.2.2",
"uuid": "9.0.1",
Expand Down
80 changes: 37 additions & 43 deletions src/api/telemetry/TelemetryValueFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,25 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

define(['lodash', 'printj'], function (_, printj) {
// TODO: needs reference to formatService;
function TelemetryValueFormatter(valueMetadata, formatMap) {
const numberFormatter = {
parse: function (x) {
return Number(x);
},
format: function (x) {
return x;
},
validate: function (x) {
return true;
}
};
import _ from 'lodash';
import { sprintf } from 'printj';

// TODO: needs reference to formatService;
export default class TelemetryValueFormatter {
constructor(valueMetadata, formatMap) {
this.valueMetadata = valueMetadata;
this.formatMap = formatMap;
this.valueMetadataFormat = this.getNonArrayValue(valueMetadata.format);

function getNonArrayValue(value) {
//metadata format could have array formats ex. string[]/number[]
const arrayRegex = /\[\]$/g;
if (value && value.match(arrayRegex)) {
return value.replace(arrayRegex, '');
}

return value;
}

let valueMetadataFormat = getNonArrayValue(valueMetadata.format);

//Is there an existing formatter for the format specified? If not, default to number format
this.formatter = formatMap.get(valueMetadataFormat) || numberFormatter;
const numberFormatter = {
parse: (x) => Number(x),
format: (x) => x,
validate: (x) => true

Check warning on line 36 in src/api/telemetry/TelemetryValueFormatter.js

View check run for this annotation

Codecov / codecov/patch

src/api/telemetry/TelemetryValueFormatter.js#L36

Added line #L36 was not covered by tests
};

if (valueMetadataFormat === 'enum') {
// Is there an existing formatter for the format specified? If not, default to number format
this.formatter = formatMap.get(this.valueMetadataFormat) || numberFormatter;
if (this.valueMetadataFormat === 'enum') {
this.formatter = {};
this.enumerations = valueMetadata.enumerations.reduce(
function (vm, e) {
Expand All @@ -66,34 +52,34 @@
byString: {}
}
);
this.formatter.format = function (value) {
this.formatter.format = (value) => {

Check warning on line 55 in src/api/telemetry/TelemetryValueFormatter.js

View check run for this annotation

Codecov / codecov/patch

src/api/telemetry/TelemetryValueFormatter.js#L55

Added line #L55 was not covered by tests
if (Object.prototype.hasOwnProperty.call(this.enumerations.byValue, value)) {
return this.enumerations.byValue[value];
}

return value;
}.bind(this);
this.formatter.parse = function (string) {
};
this.formatter.parse = (string) => {

Check warning on line 62 in src/api/telemetry/TelemetryValueFormatter.js

View check run for this annotation

Codecov / codecov/patch

src/api/telemetry/TelemetryValueFormatter.js#L62

Added line #L62 was not covered by tests
if (typeof string === 'string') {
if (Object.prototype.hasOwnProperty.call(this.enumerations.byString, string)) {
return this.enumerations.byString[string];
}
}

return Number(string);
}.bind(this);
};
}

// Check for formatString support once instead of per format call.
if (valueMetadata.formatString) {
const baseFormat = this.formatter.format;
const formatString = getNonArrayValue(valueMetadata.formatString);
const formatString = this.getNonArrayValue(valueMetadata.formatString);
this.formatter.format = function (value) {
return printj.sprintf(formatString, baseFormat.call(this, value));
return sprintf(formatString, baseFormat.call(this, value));
};
}

if (valueMetadataFormat === 'string') {
if (this.valueMetadataFormat === 'string') {
this.formatter.parse = function (value) {
if (value === undefined) {
return '';
Expand All @@ -116,7 +102,17 @@
}
}

TelemetryValueFormatter.prototype.parse = function (datum) {
getNonArrayValue(value) {
//metadata format could have array formats ex. string[]/number[]
const arrayRegex = /\[\]$/g;
if (value && value.match(arrayRegex)) {
return value.replace(arrayRegex, '');
}

return value;
}

parse(datum) {
const isDatumArray = Array.isArray(datum);
if (_.isObject(datum)) {
const objectDatum = isDatumArray ? datum : datum[this.valueMetadata.source];
Expand All @@ -130,9 +126,9 @@
}

return this.formatter.parse(datum);
};
}

TelemetryValueFormatter.prototype.format = function (datum) {
format(datum) {
const isDatumArray = Array.isArray(datum);
if (_.isObject(datum)) {
const objectDatum = isDatumArray ? datum : datum[this.valueMetadata.source];
Expand All @@ -146,7 +142,5 @@
}

return this.formatter.format(datum);
};

return TelemetryValueFormatter;
});
}
}
4 changes: 2 additions & 2 deletions src/plugins/displayLayout/CustomStringFormatter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import printj from 'printj';
import { sprintf } from 'printj';

export default class CustomStringFormatter {
constructor(openmct, valueMetadata, itemFormat) {
Expand All @@ -14,7 +14,7 @@
}

if (!this.itemFormat.startsWith('&')) {
return printj.sprintf(this.itemFormat, datum[this.valueMetadata.key]);
return sprintf(this.itemFormat, datum[this.valueMetadata.key]);

Check warning on line 17 in src/plugins/displayLayout/CustomStringFormatter.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/displayLayout/CustomStringFormatter.js#L17

Added line #L17 was not covered by tests
}

try {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/timeConductor/ConductorAxis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</template>

<script>
import * as d3Axis from 'd3-axis';
import { axisTop } from 'd3-axis';
import { scaleLinear, scaleUtc } from 'd3-scale';
import * as d3Selection from 'd3-selection';
import { select } from 'd3-selection';

import { TIME_CONTEXT_EVENTS } from '../../api/time/constants';
import utcMultiTimeFormat from './utcMultiTimeFormat.js';
Expand Down Expand Up @@ -78,9 +78,9 @@ export default {
}
},
mounted() {
let vis = d3Selection.select(this.$refs.axisHolder).append('svg:svg');
let vis = select(this.$refs.axisHolder).append('svg:svg');

this.xAxis = d3Axis.axisTop();
this.xAxis = axisTop();
this.dragging = false;

// draw x axis with labels. CSS is used to position them.
Expand Down
8 changes: 4 additions & 4 deletions src/ui/components/TimeSystemAxis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</template>

<script>
import * as d3Axis from 'd3-axis';
import { axisTop } from 'd3-axis';
import { scaleLinear, scaleUtc } from 'd3-scale';
import * as d3Selection from 'd3-selection';
import { select } from 'd3-selection';

import utcMultiTimeFormat from '@/plugins/timeConductor/utcMultiTimeFormat';

Expand Down Expand Up @@ -89,7 +89,7 @@ export default {
this.useSVG = true;
}

this.container = d3Selection.select(this.$refs.axisHolder);
this.container = select(this.$refs.axisHolder);
this.svgElement = this.container.append('svg:svg');
// draw x axis with labels. CSS is used to position them.
this.axisElement = this.svgElement
Expand Down Expand Up @@ -165,7 +165,7 @@ export default {
this.xScale.range([PADDING, this.offsetWidth - PADDING * 2]);
},
setAxis() {
this.xAxis = d3Axis.axisTop(this.xScale);
this.xAxis = axisTop(this.xScale);
this.xAxis.tickFormat(utcMultiTimeFormat);

if (this.width > 1800) {
Expand Down
Loading