Skip to content

Commit

Permalink
[ENH] Removed NB_IS_FEDERATION_API environment variable (#245)
Browse files Browse the repository at this point in the history
* Removed code related to `NB_IS_FEDERATION` env var

* Update workflow config files

* Updated README.md

* Fixed formatting
  • Loading branch information
rmanaem authored Aug 9, 2024
1 parent 93d0176 commit 34e083b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/component-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- name: Create .env file
run: |
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/\nNB_IS_FEDERATION_API=true" > .env
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/" > .env
- name: build
run: npm install && npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
cache: 'npm'
- name: Create .env file
run: |
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/\nNB_IS_FEDERATION_API=true" > .env
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/" > .env
- name: Install dependencies
run: npm ci
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: Create .env file
run: |
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/\nNB_IS_FEDERATION_API=true\nNB_ENABLE_AUTH=true\nNB_QUERY_CLIENT_ID=mockclientid" > .env
echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/\nNB_ENABLE_AUTH=true\nNB_QUERY_CLIENT_ID=mockclientid" > .env
- name: build
run: npm install && npm run build
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ but before proceeding with either you need to set the environment variables.
| Environment variable | Type | Required | Default value if not set | Example |
| ------------------------ | ------- | ---------------------------------------- | ------------------------ | --------------------------------------------------------- |
| `NB_API_QUERY_URL` | string | Yes | - | `https://federate.neurobagel.org/` |
| `NB_IS_FEDERATION_API` | boolean | No | `true` | `true` |
| `NB_QUERY_APP_BASE_PATH` | string | No | `/` | `/query/` |
| `NB_ENABLE_AUTH` | boolean | No | `false` | `false` |
| `NB_QUERY_CLIENT_ID` | string | Yes (if `NB_ENABLE_AUTH` is set to true) | - | `46923719231972-dhsahgasl3123.apps.googleusercontent.com` |
Expand All @@ -59,10 +58,6 @@ but before proceeding with either you need to set the environment variables.

You'll need to set the `NB_API_QUERY_URL` environment variable required to run the query tool. `NB_API_QUERY_URL` is the [Neurobagel API](https://github.com/neurobagel/api) URL that the query tool uses to send requests to for results.

#### `NB_IS_FEDERATION_API`

If the API you'd like to send queries to is not a [federation api](https://neurobagel.org/federate/), you need to set the `NB_IS_FEDERATION_API` to `false` as it is `true` by default.

#### `NB_QUERY_APP_BASE_PATH`

If you are using a custom configuration where the query tool is accessible via a path other than the root (`/`), you need to set the `NB_QUERY_APP_BASE_PATH` to your custom path. This ensures that the query tool is correctly rendered and accessible at the specified URL
Expand All @@ -82,16 +77,15 @@ To set environment variables, create a `.env` file in the root directory and add

```bash
NB_API_QUERY_URL=http://localhost:8000/
NB_IS_FEDERATION_API=false # For node API
```

if you're using the remote (in this example federation) api, your `.env` file would look something like this:
if you're using the remote api, your `.env` file would look something like this:

```bash
NB_API_QUERY_URL=https://federate.neurobagel.org/
```

if you're using a federation api with authentication, your `.env` file would look something like this:
if you're using a remote api with authentication, your `.env` file would look something like this:

```bash
NB_API_QUERY_URL=https://federate.neurobagel.org/
Expand Down
64 changes: 26 additions & 38 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CloseIcon from '@mui/icons-material/Close';
import { SnackbarKey, SnackbarProvider, closeSnackbar, enqueueSnackbar } from 'notistack';
import { jwtDecode } from 'jwt-decode';
import { googleLogout } from '@react-oauth/google';
import { queryURL, attributesURL, isFederationAPI, nodesURL, enableAuth } from './utils/constants';
import { queryURL, attributesURL, nodesURL, enableAuth } from './utils/constants';
import {
RetrievedAttributeOption,
AttributeOption,
Expand Down Expand Up @@ -136,17 +136,15 @@ function App() {
}
}

if (isFederationAPI) {
getNodeOptions(nodesURL).then((nodeResponse) => {
if (nodeResponse === null) {
enqueueSnackbar('Failed to retrieve Node options', { variant: 'error', action });
} else if (nodeResponse.length === 0) {
enqueueSnackbar('No options found for Node', { variant: 'info', action });
} else {
setAvailableNodes([...nodeResponse, { NodeName: 'All', ApiURL: 'allNodes' }]);
}
});
}
getNodeOptions(nodesURL).then((nodeResponse) => {
if (nodeResponse === null) {
enqueueSnackbar('Failed to retrieve Node options', { variant: 'error', action });
} else if (nodeResponse.length === 0) {
enqueueSnackbar('No options found for Node', { variant: 'info', action });
} else {
setAvailableNodes([...nodeResponse, { NodeName: 'All', ApiURL: 'allNodes' }]);
}
});
}, []);

useEffect(() => {
Expand Down Expand Up @@ -309,34 +307,24 @@ function App() {
'Content-Type': 'application/json',
},
});
// TODO: remove this branch once there is no more non-federation option
if (isFederationAPI) {
setResult(response.data);
switch (response.data.nodes_response_status) {
case 'partial success': {
response.data.errors.forEach((error: NodeError) => {
enqueueSnackbar(`${error.node_name} failed to respond`, {
variant: 'warning',
action,
});
setResult(response.data);
switch (response.data.nodes_response_status) {
case 'partial success': {
response.data.errors.forEach((error: NodeError) => {
enqueueSnackbar(`${error.node_name} failed to respond`, {
variant: 'warning',
action,
});
break;
}
case 'fail': {
enqueueSnackbar('Error: All nodes failed to respond', { variant: 'error', action });
break;
}
default: {
break;
}
});
break;
}
case 'fail': {
enqueueSnackbar('Error: All nodes failed to respond', { variant: 'error', action });
break;
}
default: {
break;
}
} else {
const myResponse = {
responses: response.data,
nodes_response_status: 'success',
errors: [],
};
setResult(myResponse);
}
} catch (error) {
enqueueSnackbar('Failed to retrieve results', { variant: 'error', action });
Expand Down
52 changes: 22 additions & 30 deletions src/components/QueryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FormHelperText,
} from '@mui/material';
import SendIcon from '@mui/icons-material/Send';
import { isFederationAPI, sexes, modalities } from '../utils/constants';
import { sexes, modalities } from '../utils/constants';
import { NodeOption, AttributeOption, FieldInput } from '../utils/types';
import CategoricalField from './CategoricalField';
import ContinuousField from './ContinuousField';
Expand Down Expand Up @@ -78,35 +78,27 @@ function QueryForm({
minNumImagingSessionsHelperText !== '';

return (
<div
className={
isFederationAPI
? 'grid grid-cols-2 grid-rows-9 gap-2'
: 'grid grid-cols-2 grid-rows-10 gap-2'
}
>
{isFederationAPI && (
<div className="col-span-2">
<CategoricalField
label="Neurobagel graph"
options={availableNodes.map((n) => ({
label: n.NodeName,
id: n.ApiURL,
}))}
onFieldChange={(label, value) => updateCategoricalQueryParams(label, value)}
multiple
inputValue={selectedNode}
/>
</div>
)}
<div className={isFederationAPI ? 'row-start-2' : ''}>
<div className="grid grid-cols-2 grid-rows-10 gap-2">
<div className="col-span-2">
<CategoricalField
label="Neurobagel graph"
options={availableNodes.map((n) => ({
label: n.NodeName,
id: n.ApiURL,
}))}
onFieldChange={(label, value) => updateCategoricalQueryParams(label, value)}
multiple
inputValue={selectedNode}
/>
</div>
<div className="row-start-2">
<ContinuousField
helperText={minAgeExceedsMaxAge ? '' : minAgeHelperText}
label="Minimum age"
onFieldChange={updateContinuousQueryParams}
/>
</div>
<div className={isFederationAPI ? 'row-start-2' : ''}>
<div className="row-start-2">
<ContinuousField
helperText={minAgeExceedsMaxAge ? '' : maxAgeHelperText}
label="Maximum age"
Expand All @@ -131,7 +123,7 @@ function QueryForm({
inputValue={sex}
/>
</div>
<div className={isFederationAPI ? 'col-span-2 row-start-5' : 'col-span-2 row-start-4'}>
<div className="col-span-2 row-start-5">
<div className="grid grid-cols-12 items-center gap-4">
<div className="col-span-9">
<CategoricalField
Expand All @@ -155,29 +147,29 @@ function QueryForm({
</div>
</div>
</div>
<div className={isFederationAPI ? 'col-span-2 row-start-6' : 'col-span-2 row-start-5'}>
<div className="col-span-2 row-start-6">
<ContinuousField
helperText={minNumImagingSessionsHelperText}
label="Minimum number of imaging sessions"
onFieldChange={updateContinuousQueryParams}
/>
</div>
<div className={isFederationAPI ? 'col-span-2 row-start-7' : 'col-span-2 row-start-6'}>
<div className="col-span-2 row-start-7">
<ContinuousField
helperText={minNumPhenotypicSessionsHelperText}
label="Minimum number of phenotypic sessions"
onFieldChange={updateContinuousQueryParams}
/>
</div>
<div className={isFederationAPI ? 'col-span-2 row-start-8' : 'col-span-2 row-start-7'}>
<div className="col-span-2 row-start-8">
<CategoricalField
label="Assessment tool"
options={assessmentOptions.map((a) => ({ label: a.Label, id: a.TermURL }))}
onFieldChange={(label, value) => updateCategoricalQueryParams(label, value)}
inputValue={assessmentTool}
/>
</div>
<div className={isFederationAPI ? 'col-span-2 row-start-9' : 'col-span-2 row-start-8'}>
<div className="col-span-2 row-start-9">
<CategoricalField
label="Imaging modality"
options={Object.entries(modalities).map(([, value]) => ({
Expand All @@ -188,7 +180,7 @@ function QueryForm({
inputValue={imagingModality}
/>
</div>
<div className={isFederationAPI ? 'row-start-10' : 'row-start-9'}>
<div className="row-start-10">
<Button
data-cy="submit-query-button"
disabled={disableSubmit}
Expand Down
5 changes: 0 additions & 5 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ export const nodesURL: string = baseAPIURL.endsWith('/')
? `${baseAPIURL}nodes`
: `${baseAPIURL}/nodes`;

export const isFederationAPI: boolean =
import.meta.env.NB_IS_FEDERATION_API === undefined
? true
: import.meta.env.NB_IS_FEDERATION_API.toLowerCase() === 'true';

export const appBasePath: string = import.meta.env.NB_QUERY_APP_BASE_PATH ?? '/';

export const enableAuth: boolean =
Expand Down

0 comments on commit 34e083b

Please sign in to comment.