Commit 48b89f69 authored by Markus Scheidgen's avatar Markus Scheidgen Committed by Mohammad Nakhaee
Browse files

Resolve warning to preserve the value over time inside react hook

parents a4d14b8b 931f2593
Pipeline #134166 passed with stages
in 62 minutes and 11 seconds
......@@ -31,6 +31,7 @@ import {useErrors} from '../errors'
import AutoComplete from '@material-ui/lab/Autocomplete'
import DeleteIcon from '@material-ui/icons/Delete'
import { useUploadContext } from './UploadContext'
import {debounce} from 'lodash'
export const editMembersDialogContext = React.createContext()
......@@ -199,7 +200,7 @@ function AddMember({...props}) {
const [isValid, setIsValid] = useState(false)
const [query, setQuery] = useState('')
const fetchUsers = useCallback((event, value) => {
const fetchUsers = useCallback((value) => {
let newQuery = value.toLowerCase()
if (!(newQuery.startsWith(query) && suggestions.length === 0) || query === '') {
api.getUsers(newQuery)
......@@ -226,14 +227,13 @@ function AddMember({...props}) {
setQuery(newQuery)
}, [api, raiseError, query, suggestions])
let timeout = null
const debouncedFetchUsers = useMemo(() => {
return debounce(fetchUsers, 700)
}, [fetchUsers])
const handleInputChange = useCallback((event, value) => {
clearTimeout(timeout)
timeout = setTimeout(() => {
fetchUsers(event, value)
}, 700)
}, [])
debouncedFetchUsers(value)
}, [debouncedFetchUsers])
const handleChange = useCallback((event, value) => {
if (value && value?.user_id) {
......
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# 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.
#
from fastapi import FastAPI, status, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import traceback
from h5grove import fastapi_utils as h5grove_router
from nomad import config, utils
logger = utils.get_logger(__name__)
h5grove_router.settings.base_dir = config.fs.staging
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(Exception)
async def unicorn_exception_handler(request: Request, e: Exception):
logger.error('unexpected exception in API', url=request.url, exc_info=e)
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
'detail': {
'reason': 'Unexpected exception while handling your request',
'exception': str(e),
'exception_class': e.__class__.__name__,
'exception_traceback': traceback.format_exc()
}
}
)
app.include_router(h5grove_router.router)
......@@ -29,6 +29,7 @@ from nomad import config, infrastructure
from .dcat.main import app as dcat_app
from .optimade import optimade_app
from .v1.main import app as v1_app
from .h5grove_app import app as h5grove_app
class OasisAuthenticationMiddleware(BaseHTTPMiddleware):
......@@ -61,6 +62,7 @@ app_base = config.services.api_base_path
app.mount(f'{app_base}/api/v1', v1_app)
app.mount(f'{app_base}/dcat', dcat_app)
app.mount(f'{app_base}/optimade', optimade_app)
app.mount(f'{app_base}/h5grove', h5grove_app)
dist_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../dist'))
docs_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../docs/build'))
......
......@@ -22,7 +22,7 @@ python-keycloak==0.26.1
elasticsearch-dsl==7.4.0
pydantic==1.8.2
jmespath==0.10.0
h5grove==0.0.14
h5grove==1.0.0
httpx==0.22.0
memoization==0.4.0
......
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# 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 pytest
import os
import h5py
from fastapi.testclient import TestClient
from nomad.app import h5grove_app
from nomad import config
@pytest.fixture
def h5grove_api(raw_files):
h5grove_app.h5grove_router.settings.base_dir = config.fs.staging
return TestClient(h5grove_app.app, base_url='http://testserver/')
def test_h5grove(client, h5grove_api):
file_name = "test.h5"
file_path = f"{config.fs.staging}{os.sep}{file_name}"
h5file = h5py.File(file_path, "w")
h5file.create_dataset("entry", data="test")
h5file.close()
assert h5grove_api.get(f"/data/?file={file_name}&path=/entry").content == b'"test"'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment