From 4cb26694ffc5ef5833e49c5c7c1b0d6b74826dd3 Mon Sep 17 00:00:00 2001 From: Parth Shah Date: Wed, 21 Feb 2024 23:24:19 -0800 Subject: [PATCH] resources: Updated tabs to show workloads in a suite. --- __mocks__/resources-test.json | 16 ++++----- __tests__/components/resourceMetadata.test.js | 2 +- __tests__/pages/api/findresources.test.js | 14 ++++---- __tests__/pages/api/getTabs.test.js | 2 +- __tests__/pages/api/getresource.test.js | 10 +++--- __tests__/pages/api/resources.json | 4 +-- .../pages/resources/[id]/[[...page]].test.js | 2 +- components/resourceMetadata.js | 6 ++-- components/resourceTab.js | 35 ++++++++++--------- components/tabs/rawTab.js | 2 +- gem5.config.json | 9 +++++ pages/api/json/getResourceByID.js | 2 +- pages/api/mongodb/getResourceByID.js | 2 +- 13 files changed, 59 insertions(+), 47 deletions(-) diff --git a/__mocks__/resources-test.json b/__mocks__/resources-test.json index d5c99ce..96bccd8 100644 --- a/__mocks__/resources-test.json +++ b/__mocks__/resources-test.json @@ -98,7 +98,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -126,7 +126,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -154,7 +154,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -182,7 +182,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -210,7 +210,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -238,7 +238,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -266,7 +266,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -294,7 +294,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] diff --git a/__tests__/components/resourceMetadata.test.js b/__tests__/components/resourceMetadata.test.js index 2ec68e1..1ed791a 100644 --- a/__tests__/components/resourceMetadata.test.js +++ b/__tests__/components/resourceMetadata.test.js @@ -50,7 +50,7 @@ describe('MetaData component', () => { "resource_version": "1.0.0", "database": "db1", "license": "MIT", - "workloads": [ + "workloads_mapping": [ "workload1", "workload2" ], diff --git a/__tests__/pages/api/findresources.test.js b/__tests__/pages/api/findresources.test.js index da841e4..ccd0edc 100644 --- a/__tests__/pages/api/findresources.test.js +++ b/__tests__/pages/api/findresources.test.js @@ -77,7 +77,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 2, score: 21, ver_latest: '23.0', @@ -208,7 +208,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 1, score: 90, ver_latest: '23.0', @@ -268,7 +268,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 2, score: 21, ver_latest: '23.0', @@ -325,7 +325,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 2, score: 21, ver_latest: '23.0', @@ -359,7 +359,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 2, score: 21, ver_latest: '23.0', @@ -418,7 +418,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 1, score: 14, ver_latest: '23.0', @@ -454,7 +454,7 @@ describe('findResources', () => { gem5_versions: ["23.0"], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], + workloads_mapping: ["x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint"], totalMatches: 1, score: 7, ver_latest: '23.0', diff --git a/__tests__/pages/api/getTabs.test.js b/__tests__/pages/api/getTabs.test.js index e513f05..7723b41 100644 --- a/__tests__/pages/api/getTabs.test.js +++ b/__tests__/pages/api/getTabs.test.js @@ -82,7 +82,7 @@ describe("getTabs", () => { ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] diff --git a/__tests__/pages/api/getresource.test.js b/__tests__/pages/api/getresource.test.js index 889b06f..d447e9a 100644 --- a/__tests__/pages/api/getresource.test.js +++ b/__tests__/pages/api/getresource.test.js @@ -29,7 +29,7 @@ global.fetch = jest.fn((url) => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' }], }), @@ -102,7 +102,7 @@ describe('getResource', () => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' }) }); @@ -130,7 +130,7 @@ describe('getResource', () => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' }) }); @@ -173,7 +173,7 @@ describe('getResource', () => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' }) }); @@ -216,7 +216,7 @@ describe('getResource', () => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' }) }); diff --git a/__tests__/pages/api/resources.json b/__tests__/pages/api/resources.json index ec707dd..1f4a5fe 100644 --- a/__tests__/pages/api/resources.json +++ b/__tests__/pages/api/resources.json @@ -45,7 +45,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] @@ -73,7 +73,7 @@ ], "workload_name": "x86-print-this-15000-with-simpoints", "example_usage": "get_resource(resource_name=\"x86-print-this-1500-simpoints\")", - "workloads": [ + "workloads_mapping": [ "x86-print-this-15000-with-simpoints", "x86-print-this-15000-with-simpoints-and-checkpoint" ] diff --git a/__tests__/pages/resources/[id]/[[...page]].test.js b/__tests__/pages/resources/[id]/[[...page]].test.js index 766306c..acf6637 100644 --- a/__tests__/pages/resources/[id]/[[...page]].test.js +++ b/__tests__/pages/resources/[id]/[[...page]].test.js @@ -155,7 +155,7 @@ describe("Resource-specific component", () => { gem5_versions: ['23.0'], workload_name: 'x86-print-this-15000-with-simpoints', example_usage: 'get_resource(resource_name="x86-print-this-1500-simpoints")', - workloads: [], + workloads_mapping: [], database: 'db1' })) })) diff --git a/components/resourceMetadata.js b/components/resourceMetadata.js index b339fbf..0374d8b 100644 --- a/components/resourceMetadata.js +++ b/components/resourceMetadata.js @@ -137,12 +137,12 @@ export default function MetaData({ resource, className, metaFields, showMetadata : null } { - (resource.workloads && resource.workloads.length > 0) ? + (resource.workloads_mapping && resource.workloads_mapping.length > 0) ?

Depend on this resource

{ - resource.workloads.map((workload, index) => { + resource.workloads_mapping.map((workload, index) => { return ( {workload} - {index != resource.workloads.length - 1 ? ', ' : ''} + {index != resource.workloads_mapping.length - 1 ? ', ' : ''} ) }) diff --git a/components/resourceTab.js b/components/resourceTab.js index eefc90a..6d47926 100644 --- a/components/resourceTab.js +++ b/components/resourceTab.js @@ -16,6 +16,7 @@ import rehypeHighlight from "rehype-highlight"; import rehypeSlug from "rehype-slug"; import rehypeRaw from "rehype-raw"; import remarkFrontmatter from "remark-frontmatter"; +import CopyIcon from "./copyIcon"; export function createTab(tab) { if (!"content" in tab) return null; @@ -30,13 +31,15 @@ export function createTab(tab) { content = String(tab.content); break; case "array": - content = tab.content.map((item, index) => { - return ( -
- {item} -
- ); - }); + content = ( + +
+            
+              {JSON.stringify(tab.content, null, 4)}
+            
+          
+
+ ); break; case "object": content = Object.keys(tab.content).map((key, index) => { @@ -131,15 +134,15 @@ export default function ResourceTab({ resource, requiredTabs, additionalInfoTabs > - {resource.description ?? 'This is a description of the resource.'} + className="markdown-body mt-3" + rehypePlugins={[ + [rehypeHighlight, { ignoreMissing: true }], + rehypeRaw, + rehypeSlug, + ]} + remarkPlugins={[remarkGfm, remarkToc, remarkFrontmatter]} + > + {resource.description ?? 'This is a description of the resource.'} diff --git a/components/tabs/rawTab.js b/components/tabs/rawTab.js index 2533564..e10df91 100644 --- a/components/tabs/rawTab.js +++ b/components/tabs/rawTab.js @@ -26,7 +26,7 @@ export default function RawTab({ resource }) { resource = JSON.parse(JSON.stringify(resource)); delete resource.database delete resource._id - delete resource.workloads + delete resource.workloads_mapping textToHtml(JSON.stringify(resource, null, 4)); }, [resource]); return ( diff --git a/gem5.config.json b/gem5.config.json index 12cf086..ba06b1d 100644 --- a/gem5.config.json +++ b/gem5.config.json @@ -110,6 +110,15 @@ } }, "metadata": {} + }, + "suite": { + "tab": { + "workloads": { + "displayName": "Workloads" + } + }, + "additionalInfo": {}, + "metadata": {} } } } diff --git a/pages/api/json/getResourceByID.js b/pages/api/json/getResourceByID.js index fa82bff..7720654 100644 --- a/pages/api/json/getResourceByID.js +++ b/pages/api/json/getResourceByID.js @@ -49,7 +49,7 @@ export default async function getResourceByIDJSON(id, database, version) { if (!resource) { return { error: 'Resource not found' } } - resource.workloads = workloads; + resource.workloads_mapping = workloads; resource.database = database; return resource; } diff --git a/pages/api/mongodb/getResourceByID.js b/pages/api/mongodb/getResourceByID.js index a07907b..0fb515e 100644 --- a/pages/api/mongodb/getResourceByID.js +++ b/pages/api/mongodb/getResourceByID.js @@ -86,7 +86,7 @@ async function getResourceByID(token, url, dataSource, database, collection, id, }) }).catch(err => console.log(err)); let workloads = await dependendWorkloads.json(); - resource.workloads = Object.values(workloads['documents']).map(workload => workload['_id']); + resource.workloads_mapping = Object.values(workloads['documents']).map(workload => workload['_id']); return resource; }