Skip to content
Merged
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
30 changes: 19 additions & 11 deletions devtools/dashboard_utilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,28 @@ export function createMocksList(files) {
const jsonFiles = files.filter((file) => file.name.substr(-5) === '.json');

const mocksList = jsonFiles.map((file) => {
const contents = JSON.parse(file.contents);
try {
const contents = JSON.parse(file.contents);

// get plot type keywords from mocks
const types = contents.data
.map((trace) => trace.type || 'scatter')
.reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []);
// get plot type keywords from mocks
const types = contents.data
.map((trace) => trace.type || 'scatter')
.reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []);

const filename = file.name.split(path.sep).pop();
const filename = file.name.split(path.sep).pop();

return {
name: filename.slice(0, -5),
file: filename,
keywords: types.join(', ')
};
return {
name: filename.slice(0, -5),
file: filename,
keywords: types.join(', ')
};
} catch (error) {
if (error instanceof SyntaxError) {
console.log(`Couldn't parse ${file.name} as JSON. Excluding from mocks list.`);
} else {
throw error;
}
}
});

return mocksList;
Expand Down