-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added recipes endpoint to sparsezoo table ui (#77)
* Added recipes endpoint to sparsezoo table ui * Removed commented code
- Loading branch information
Showing
21 changed files
with
651 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { API_ROOT, validateAPIResponseJSON } from "./utils"; | ||
|
||
/** | ||
* API action for searching for models in the model zoo | ||
* @param {object} requestBody the requestBody | ||
* @param {string} requestBody.domain the domain of the model search | ||
* @param {string} requestBody.subdomain the subdomain of the model search | ||
* @param {string} requestBody.token the token for the model search authentication | ||
* @param {string} requestBody.page the page of search results to return | ||
* @param {string} requestBody.page_legth the amount of search results to return | ||
* @param {{ | ||
* architecture: string, | ||
* sub_architecture: string, | ||
* repo: string, | ||
* framework: string, | ||
* dataset: string, | ||
* training_scheme: string, | ||
* sparse_name: string, | ||
* sparse_category: string, | ||
* sparse_target: string, | ||
* recipe_type: string | ||
* }} requestBody.queries the additional queries for the search result | ||
* @returns {Promise<Array>} | ||
*/ | ||
export function requestSearchRecipes({ | ||
domain, | ||
subdomain, | ||
token, | ||
page = 1, | ||
page_length = 20, | ||
queries = {}, | ||
}) { | ||
let url = `${API_ROOT}/recipes/search/${domain}/${subdomain}?page=${page}&page_length=${page_length}`; | ||
if (queries) { | ||
for (const [key, value] of Object.entries(queries)) { | ||
url = `${url}&${key}=${value}`; | ||
} | ||
} | ||
return validateAPIResponseJSON( | ||
fetch(url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"nm-token-header": token, | ||
}, | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
export { default } from "./recipe-table"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { makeStyles } from "@material-ui/core/styles"; | ||
|
||
export default function makeRecipeTableStyles() { | ||
return makeStyles( | ||
(theme) => ({ | ||
root: { | ||
padding: theme.spacing(0.5), | ||
}, | ||
toolbar: {}, | ||
}), | ||
{ name: "RecipeTable" } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { useEffect } from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import PropTypes from "prop-types"; | ||
|
||
import lodash from "lodash"; | ||
|
||
import Typography from "@material-ui/core/Typography"; | ||
|
||
import { | ||
selectAuthState, | ||
selectRecipesState, | ||
searchRecipesThunk, | ||
selectRecipesTable, | ||
} from "../../store"; | ||
import makeStyles from "./recipe-table-styles"; | ||
import ZooTable from "../zoo-table"; | ||
|
||
function RecipeTable({ domain, subdomain, includePagination, includeHeader, queries }) { | ||
const useStyles = makeStyles(); | ||
const classes = useStyles(); | ||
const dispatch = useDispatch(); | ||
|
||
const authState = useSelector(selectAuthState); | ||
const recipesState = useSelector(selectRecipesState); | ||
console.log(recipesState); | ||
const results = useSelector(selectRecipesTable); | ||
|
||
useEffect(() => { | ||
const status = lodash.get(recipesState.status, `${domain}.${subdomain}`, "idle"); | ||
if (authState.token !== null && status === "idle") { | ||
dispatch( | ||
searchRecipesThunk({ | ||
domain, | ||
subdomain, | ||
token: authState.token, | ||
queries, | ||
}) | ||
); | ||
} | ||
}, [authState.token, recipesState.status, dispatch, domain, subdomain, queries]); | ||
|
||
const rows = lodash | ||
.get(results, `${domain}.${subdomain}.data`, []) | ||
.map((data) => data.row); | ||
const status = lodash.get(results, `${domain}.${subdomain}.status`, "idle"); | ||
const loaded = status !== "idle" && status !== "loading"; | ||
return ( | ||
<div className={classes.root}> | ||
{loaded && includeHeader && ( | ||
<Typography variant="h6"> | ||
{lodash.get( | ||
results, | ||
`${domain}.${subdomain}.displayName`, | ||
`${domain} ${subdomain}` | ||
)} | ||
</Typography> | ||
)} | ||
<ZooTable | ||
ariaLabel={`${domain}.${subdomain}`} | ||
headers={lodash.get(results, `${domain}.${subdomain}.headers`, [])} | ||
rows={rows} | ||
status={status} | ||
error={authState.error || recipesState.error} | ||
aligns={lodash.get(results, `${domain}.${subdomain}.aligns`, "left")} | ||
copy={lodash.get(results, `${domain}.${subdomain}.copy`, false)} | ||
width={lodash.get(results, `${domain}.${subdomain}.width`)} | ||
includePagination={includePagination} | ||
loadingMessage="Loading recipes" | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
RecipeTable.propTypes = { | ||
domain: PropTypes.string.isRequired, | ||
subdomain: PropTypes.string.isRequired, | ||
queries: PropTypes.object, | ||
includePagination: PropTypes.bool, | ||
includeHeader: PropTypes.bool, | ||
}; | ||
|
||
RecipeTable.defaultProps = { | ||
includePagination: false, | ||
includeHeader: false, | ||
queries: {}, | ||
}; | ||
|
||
export default RecipeTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
export { default } from "./recipes-root"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
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 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { makeStyles } from "@material-ui/core/styles"; | ||
|
||
export default function makeRecipeTableRootStyles() { | ||
return makeStyles( | ||
(theme) => ({ | ||
root: {}, | ||
}), | ||
{ name: "RecipeTableRoot" } | ||
); | ||
} |
Oops, something went wrong.