Skip to content

Commit

Permalink
feat(lapis2-docs): configure LAPIS URL via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Sep 20, 2023
1 parent f98a835 commit 2ede4aa
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
5 changes: 3 additions & 2 deletions lapis2-docs/src/components/QueryGenerator/QueryGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type { Config } from '../../config';

type Props = {
config: Config;
lapisUrl: string;
};

export const QueryGenerator = ({ config }: Props) => {
export const QueryGenerator = ({ config, lapisUrl }: Props) => {
const [step, setStep] = useState(0);
const [queryType, setQueryType] = useState<QueryTypeSelectionState>({
selection: 'aggregatedAll',
Expand Down Expand Up @@ -52,7 +53,7 @@ export const QueryGenerator = ({ config }: Props) => {
{step === 0 && <QueryTypeSelection config={config} state={queryType} onStateChange={setQueryType} />}
{step === 1 && <FiltersSelection config={config} filters={filters} onFiltersChange={setFilters} />}
{step === 2 && <>TODO</>}
{step === 3 && <Result queryType={queryType} filters={filters} config={config} />}
{step === 3 && <Result queryType={queryType} filters={filters} config={config} lapisUrl={lapisUrl} />}
</div>

<div className='w-full flex justify-between mt-8'>
Expand Down
12 changes: 7 additions & 5 deletions lapis2-docs/src/components/QueryGenerator/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Props = {
queryType: QueryTypeSelectionState;
filters: Filters;
config: Config;
lapisUrl: string;
};

export const Result = (props: Props) => {
Expand Down Expand Up @@ -94,17 +95,18 @@ const PythonTab = (props: Props) => {
const propsWithJson: Props = {
...props,
};
const { endpoint, body, resultFields } = constructPostQuery(propsWithJson);
const code = generateNonFastaQuery('', endpoint, body, resultFields);
const { lapisUrl, endpoint, body, resultFields } = constructPostQuery(propsWithJson);
const code = generateNonFastaQuery(lapisUrl, endpoint, body, resultFields);
return <CodeBlock>{code}</CodeBlock>;
};

function constructPostQuery({ queryType, filters, config }: Props): {
function constructPostQuery({ queryType, filters, config, lapisUrl }: Props): {
lapisUrl: string;
endpoint: string;
body: object;
resultFields: ResultField[];
} {
let endpoint = '/sample/';
let endpoint = '/';
const body: any = {};
const resultFields: ResultField[] = [];

Expand Down Expand Up @@ -158,7 +160,7 @@ function constructPostQuery({ queryType, filters, config }: Props): {
body[name] = value;
}
}
return { endpoint, body, resultFields };
return { lapisUrl, endpoint, body, resultFields };
}

function mapMetadataTypeToResultFieldType(type: MetadataType): ResultFieldType {
Expand Down
12 changes: 5 additions & 7 deletions lapis2-docs/src/components/SwaggerUIContainer.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
---
interface Props {
url: string;
}
const { url } = Astro.props;
const test = 'df';
import { getLapisUrl } from '../lapisUrl';
const openApiUrl = getLapisUrl() + '/api-docs';
---

YAML definition: <a href={openApiUrl}>{openApiUrl}</a>

<head>
<!-- TODO Don't fetch from external source! -->
<link rel='stylesheet' href='https://unpkg.com/[email protected]/swagger-ui.css' />
</head>

<div class='not-content'>
<swagger-ui-container data-url={url}></swagger-ui-container>
<swagger-ui-container data-url={openApiUrl}></swagger-ui-container>
</div>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description: A step-by-step wizard to help you generate a request
---

import { getConfig } from '../../../config.ts';
import { getLapisUrl } from '../../../lapisUrl.js';

import { QueryGenerator } from '../../../components/QueryGenerator/QueryGenerator.tsx';

<QueryGenerator client:load config={getConfig()} />
<QueryGenerator client:load config={getConfig()} lapisUrl={getLapisUrl()} />
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ description: Open API / Swagger

import SwaggerUIContainer from '../../../components/SwaggerUIContainer.astro';

YAML definition: [https://lapis.cov-spectrum.org/openapi/v1.yml](https://lapis.cov-spectrum.org/openapi/v1.yml)

<SwaggerUIContainer url='https://lapis.cov-spectrum.org/openapi/v1.yml' />
<SwaggerUIContainer />
11 changes: 11 additions & 0 deletions lapis2-docs/src/lapisUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let lapisUrl: string | null = null;

export function getLapisUrl(): string {
if (lapisUrl === null) {
if (import.meta.env.LAPIS_URL === undefined) {
throw new Error('LAPIS_URL environment variable is not set');
}
lapisUrl = (import.meta.env.LAPIS_URL as string).replace(/\/$/, '');
}
return lapisUrl;
}
2 changes: 2 additions & 0 deletions lapis2-docs/test-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ services:
- "3000:3000"
volumes:
- ../siloLapisTests/testData/testDatabaseConfig.yaml:/config/database_config.yaml
environment:
LAPIS_URL: localhost:8080

0 comments on commit 2ede4aa

Please sign in to comment.