Skip to content

Commit

Permalink
Merge pull request #1 from gecage952/dev
Browse files Browse the repository at this point in the history
merge dev into branch
  • Loading branch information
gecage952 authored Nov 3, 2023
2 parents 6dfbc7a + abbb03c commit fba01ad
Show file tree
Hide file tree
Showing 488 changed files with 12,528 additions and 8,055 deletions.
1 change: 1 addition & 0 deletions .ci/ignore-spelling.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
hda
implementors
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ area/toolshed:
- lib/toolshed/**/*
- templates/webapps/tool_shed/**/*
area/UI-UX:
- all: ["client/src/**/*", "!client/src/schema/schema.ts"]
- all: ["client/src/**/*", "!client/src/api/schema/schema.ts"]
any: ["templates/**/*"]
area/util:
- lib/galaxy/util/**/*
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.11']
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_openapi_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Check for changes
run: |
if [[ `git status --porcelain` ]]; then
echo "Rebuilding client/src/schema/schema.ts resulted in changes, run 'make update-client-api-schema' and commit results"
echo "Rebuilding client/src/api/schema/schema.ts resulted in changes, run 'make update-client-api-schema' and commit results"
exit 1
fi
working-directory: 'galaxy root'
43 changes: 20 additions & 23 deletions .github/workflows/toolshed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,11 @@ jobs:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- test-install-client: 'galaxy_api'
python-version: '3.7'
shed-api: 'v1'
shed-browser: 'twill'
- test-install-client: 'standalone'
python-version: '3.8'
shed-api: 'v1'
shed-browser: 'twill'
- test-install-client: 'galaxy_api'
python-version: '3.9'
shed-api: 'v2'
shed-browser: 'playwright'
- test-install-client: 'standalone'
python-version: '3.10'
shed-api: 'v2'
shed-browser: 'playwright'
python-version: ['3.7', '3.11']
shed-api: ['v1', 'v2']
test-install-client: ['galaxy_api', 'standalone']
services:
postgres:
image: postgres:13
Expand All @@ -50,6 +37,11 @@ jobs:
- uses: actions/checkout@v3
with:
path: 'galaxy root'
- uses: actions/setup-node@v3
with:
node-version: '18.12.1'
cache: 'yarn'
cache-dependency-path: 'galaxy root/client/yarn.lock'
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -68,25 +60,30 @@ jobs:
with:
path: 'galaxy root/.venv'
key: gxy-venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('galaxy root/requirements.txt') }}-toolshed
key: gxy-venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('galaxy_root/requirements.txt') }}-toolshed
- name: Install dependencies
run: ./scripts/common_startup.sh --skip-client-build
working-directory: 'galaxy root'
- name: Build Frontend
run: '. .venv/bin/activate && cd lib/tool_shed/webapp/frontend && yarn && make client'
run: |
. .venv/bin/activate
cd lib/tool_shed/webapp/frontend
yarn
make client
working-directory: 'galaxy root'
- name: Install playwright
run: '. .venv/bin/activate && playwright install'
run: |
. .venv/bin/activate
playwright install
working-directory: 'galaxy root'
- name: Run tests
run: './run_tests.sh -toolshed'
run: ./run_tests.sh -toolshed
env:
TOOL_SHED_TEST_INSTALL_CLIENT: ${{ matrix.test-install-client }}
TOOL_SHED_API_VERSION: ${{ matrix.shed-api }}
TOOL_SHED_TEST_BROWSER: ${{ matrix.shed-browser }}
TOOL_SHED_TEST_BROWSER: ${{ matrix.shed-api == 'v1' && 'twill' || 'playwright' }}
working-directory: 'galaxy root'
- uses: actions/upload-artifact@v3
if: failure()
with:
name: Toolshed test results (${{ matrix.python-version }}, ${{ matrix.test-install-client }})
name: Toolshed test results (${{ matrix.python-version }}, ${{ matrix.shed-api }}, ${{ matrix.test-install-client }})
path: 'galaxy root/run_toolshed_tests.html'
5 changes: 3 additions & 2 deletions .k8s_ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ RUN set -xe; \

# Create Galaxy user, group, directory; chown
RUN set -xe; \
adduser --system --group $GALAXY_USER \
adduser --system --group --uid 101 $GALAXY_USER \
&& mkdir -p $SERVER_DIR \
&& chown $GALAXY_USER:$GALAXY_USER $ROOT_DIR -R

Expand All @@ -179,7 +179,8 @@ COPY --chown=$GALAXY_USER:$GALAXY_USER --from=client_build $SERVER_DIR/static ./
WORKDIR $SERVER_DIR

# The data in version.json will be displayed in Galaxy's /api/version endpoint
RUN printf "{\n \"git_commit\": \"$(cat GITREVISION)\",\n \"build_date\": \"$BUILD_DATE\",\n \"image_tag\": \"$IMAGE_TAG\"\n}\n" > version.json
RUN printf "{\n \"git_commit\": \"$(cat GITREVISION)\",\n \"build_date\": \"$BUILD_DATE\",\n \"image_tag\": \"$IMAGE_TAG\"\n}\n" > version.json \
&& chown $GALAXY_USER:$GALAXY_USER version.json

EXPOSE 8080
USER $GALAXY_USER
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ remove-api-schema:
rm _shed_schema.yaml

update-client-api-schema: client-node-deps build-api-schema
$(IN_VENV) cd client && node openapi_to_schema.mjs ../_schema.yaml > src/schema/schema.ts && npx prettier --write src/schema/schema.ts
$(IN_VENV) cd client && node openapi_to_schema.mjs ../_schema.yaml > src/api/schema/schema.ts && npx prettier --write src/api/schema/schema.ts
$(IN_VENV) cd client && node openapi_to_schema.mjs ../_shed_schema.yaml > ../lib/tool_shed/webapp/frontend/src/schema/schema.ts && npx prettier --write ../lib/tool_shed/webapp/frontend/src/schema/schema.ts
$(MAKE) remove-api-schema

Expand Down
15 changes: 12 additions & 3 deletions client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ const baseRules = {
"vuejs-accessibility/form-control-has-label": "warn",
"vuejs-accessibility/heading-has-content": "error",
"vuejs-accessibility/iframe-has-title": "error",
"vuejs-accessibility/label-has-for": "warn",
"vuejs-accessibility/label-has-for": [
"warn",
{
required: {
some: ["nesting", "id"],
},
},
],
"vuejs-accessibility/mouse-events-have-key-events": "warn",
"vuejs-accessibility/no-autofocus": "error",
"vuejs-accessibility/no-static-element-interactions": "warn",
Expand Down Expand Up @@ -117,21 +124,23 @@ module.exports = {
files: ["**/*.ts", "**/*.tsx"],
extends: [
...baseExtends,
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
// "plugin:@typescript-eslint/stylistic" // TODO: work towards this
],
rules: {
...baseRules,
"@typescript-eslint/no-throw-literal": "error",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-explicit-any": "warn", // TODO: re-enable this
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "_.+", varsIgnorePattern: "_.+" }],
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2020,
sourceType: "module",
extraFileExtensions: [".vue"],
project: "./tsconfig.json",
project: true,
},
plugins: [...basePlugins, "@typescript-eslint"],
},
Expand Down
86 changes: 86 additions & 0 deletions client/docs/querying-the-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Best practices when querying the API from UI components

If you need to query the API from a component, there are several ways to do so. This document will help you decide which one to use and provide some best practices when doing so to keep the code clean and maintainable.

## Choose the Right Approach

When querying APIs in Vue components, consider the following approaches and their best practices:

## 1. Prefer Composables over Stores over Direct API Calls

### Composables

- **What Are Composables?**: please read the official Vue documentation on composables [here](https://vuejs.org/guide/reusability/composables.html).

If there is already a composable that takes care of the logic you need for accessing a particular resource in the API please use it or consider writing a new one. They provide a type-safe interface and a higher level of abstraction than the related Store or the API itself. They might rely on one or more Stores for caching and reactivity.

### Stores

- **Stores Explained**: Please read the official Vue documentation on State Management [here](https://vuejs.org/guide/scaling-up/state-management.html).

If there is no Composable for the API endpoint you are using, try using a (Pinia) Store instead. Stores are type-safe and provide a reactive interface to the API. They can also be used to cache data, ensuring a single source of truth.

- **Use Pinia Stores**: If you need to create a new Store, make sure to create a Pinia Store, and not a Vuex Store as Pinia will be the replacement for Vuex. Also, use [Composition API syntax over the Options API](https://vuejs.org/guide/extras/composition-api-faq.html) for increased readability, code organization, type inference, etc.

### Direct API Calls

- If the type of data you are querying should not be cached, or you just need to update or create new data, you can use the API directly. Make sure to use the **Fetcher** (see below) instead of Axios, as it provides a type-safe interface to the API along with some extra benefits.

## 2. Prefer Fetcher over Axios (when possible)

- **Use Fetcher with OpenAPI Specs**: If there is an OpenAPI spec for the API endpoint you are using (in other words, there is a FastAPI route defined in Galaxy), always use the Fetcher. It will provide you with a type-safe interface to the API.

**Do**

```typescript
import { fetcher } from "@/api/schema";
const datasetsFetcher = fetcher.path("/api/dataset/{id}").method("get").create();

const { data: dataset } = await datasetsFetcher({ id: "testID" });
```

**Don't**

```js
import axios from "axios";
import { getAppRoot } from "onload/loadConfig";
import { rethrowSimple } from "utils/simple-error";

async getDataset(datasetId) {
const url = `${getAppRoot()}api/datasets/${datasetId}`;
try {
const response = await axios.get(url);
return response.data;
} catch (e) {
rethrowSimple(e);
}
}

const dataset = await getDataset("testID");
```

> **Reason**
>
> The `fetcher` class provides a type-safe interface to the API, and is already configured to use the correct base URL and error handling.
## 3. Where to put your API queries?

The short answer is: **it depends**. There are several factors to consider when deciding where to put your API queries:

### Is the data you are querying related exclusively to a particular component?

If so, you should put the query in the component itself. If not, you should consider putting it in a Composable or a Store.

### Can the data be cached?

If so, you should consider putting the query in a Store. If not, you should consider putting it in a Composable or the component itself.

### Is the query going to be used in more than one place?

If so, you should consider putting it under src/api/<resource>.ts and exporting it from there. This will allow you to reuse the query in multiple places specially if you need to do some extra processing of the data. Also it will help to keep track of what parts of the API are being used and where.

### Should I use the `fetcher` directly or should I write a wrapper function?

- If you **don't need to do any extra processing** of the data, you can use the `fetcher` directly.
- If you **need to do some extra processing**, you should consider writing a wrapper function. Extra processing can be anything from transforming the data to adding extra parameters to the query or omitting some of them, handling conditional types in response data, etc.
- Using a **wrapper function** will help in case we decide to replace the `fetcher` with something else in the future (as we are doing now with _Axios_).
Loading

0 comments on commit fba01ad

Please sign in to comment.