Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PXP-11166: explorer file downloads #141

Merged
merged 26 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/release-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#name: Node.js Package
#
#on:
# push:
# branches:
# - develop
#
#jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v3
# with:
# node-version: 18.15.0
# - run: npm ci
# - run: npm test
#
# publish-gpr:
# needs: build
# runs-on: ubuntu-latest
# permissions:
# packages: write
# contents: read
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v3.4.1
# with:
# node-version: 18.15.0
# registry-url: https://npm.pkg.github.com/
# - run: npm ci
# - run: npm publish --workspace packages/core
# env:
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
#
47 changes: 38 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@swc/core": "^1.3.62",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.4.0",
"@types/jest": "^29.5.12",
"@types/node": "20.4.1",
"@types/react": "^18.2.21",
"@typescript-eslint/eslint-plugin": "^5.31.0",
Expand All @@ -61,7 +61,7 @@
"rollup-plugin-swc3": "^0.10.2",
"rollup-swc-preserve-directives": "^0.5.0",
"terser-webpack-plugin": "^5.3.3",
"ts-jest": "^29.0.5",
"ts-jest": "^29.1.2",
"ts-node-dev": "^2.0.0",
"typescript": "5.0.2"
}
Expand Down
8 changes: 6 additions & 2 deletions packages/core/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testEnvironment: 'node',
transform: {
'node_modules/(flat)/.+\\.(j|t)s?$': 'ts-jest',
},
transformIgnorePatterns: ['node_modules/(?!flat)/'],
globalSetup: '<rootDir>/setupTests.ts',
moduleNameMapper: {
'^@/core/(.*)$': '<rootDir>/src/$1',
},
modulePaths: ['<rootDir>'],
globals: {
fetch: global.fetch,
}
},
};
7 changes: 6 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"scripts": {
"compile": "tsc",
"clean": "rimraf dist",
"types": "tsc --emitDeclarationOnly",
"build": "npm run clean && npm run compile && rollup --config rollup.config.mjs",
"build:clean": "npm run clean && npm run compile && npm run types && rollup --config rollup.config.mjs",
"build:watch": "npm run compile && npm run build -- --watch",
"test": "jest unit",
"test:watch": "jest unit --watch",
Expand All @@ -42,17 +44,20 @@
"@swc/wasm": "^1.3.85",
"@testing-library/react": "^14.0.0",
"@types/estree": "^1.0.0",
"@types/jsonpath-plus": "5.0.5",
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.14.191",
"@types/papaparse": "^5.3.14",
"@types/flat": "^5.0.3",
"@types/uuid": "^9.0.0",
"eslint": "^8.36.0",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"rollup": "^3.29.2",
"rollup-plugin-dts": "^6.0.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"ts-jest": "^29.0.3"
"ts-jest": "^29.1.2"
},
"dependencies": {
"flat": "^6.0.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const globals = {
'react-cookie': 'reactCookie',
'swr': 'swr',
'jsonpath-plus': 'jsonpathPlus',
'flat': 'flat',
'papaparse': 'papaparse',
};

const config = [
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/features/cohort/cohortSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
if (!filters) {
return;
}
const { [field]: _a, ...updated } = filters;

Check warning on line 81 in packages/core/src/features/cohort/cohortSlice.ts

View workflow job for this annotation

GitHub Actions / build

'_a' is assigned a value but never used
return {
cohort: {
...state.cohort,
Expand All @@ -94,7 +94,7 @@
state: Draft<CohortState>,
action: PayloadAction<string>
) => {
const { [action.payload]: _a, ...updated } = state.cohort.filters[action.payload].root;
const { [action.payload]: _rest, ...updated } = state.cohort.filters[action.payload].root;

Check warning on line 97 in packages/core/src/features/cohort/cohortSlice.ts

View workflow job for this annotation

GitHub Actions / build

'_rest' is assigned a value but never used
return {
cohort: { ...state.cohort, ...{ ...state.cohort.filters, [action.payload]: updated } },
};
Expand Down Expand Up @@ -131,6 +131,7 @@
return state.cohorts.cohort.filters[index]?.root[name];
};

const EmptyFilterSet: FilterSet = { mode: 'and', root: {} };
/**
* Select a filter from the index.
* returns undefined.
Expand All @@ -141,7 +142,7 @@
state: CoreState,
index: string
): FilterSet => {
return state.cohorts.cohort.filters?.[index] ?? { mode: 'and', root: {}}; // TODO: check if this is undefined
return state.cohorts.cohort.filters?.[index] ?? EmptyFilterSet; // TODO: check if this is undefined
};

export const cohortReducer = cohortSlice.reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('resolveDRSWithDataGUISOrg', () => {
it('should return empty object if input is an empty array', async () => {
const guidsForHostnameResolution: string[] = [];

await expect(resolveDRSWithDataGUISOrg(guidsForHostnameResolution)).toEqual(
expect(resolveDRSWithDataGUISOrg(guidsForHostnameResolution)).toEqual(
expect.objectContaining({}),
);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/features/guppy/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Papa, { UnparseConfig } from 'papaparse';
* @param {JSON} json
*/
export function flattenJson(json: JSONObject) {
const flattenedJson : JSONArray = [];
const flattenedJson: JSONArray = [];
Object.keys(json).forEach((key) => {
flattenedJson.push(flatten(json[key], { delimiter: '_' }));
});
Expand All @@ -28,7 +28,7 @@ export async function conversion(json: JSONArray, config: UnparseConfig) {

/**
* Converts JSON to a specified file format.
* Defaultes to JSON if file format is not supported.
* Defaults to JSON if file format is not supported.
* @param {JSON} json
* @param {string} format
*/
Expand All @@ -40,7 +40,7 @@ export async function jsonToFormat(
const flatJson = await flattenJson(json);
const data = await conversion(flatJson, {
delimiter: FILE_DELIMITERS[format] as string,
} );
});
return data;
}
return json;
Expand Down
40 changes: 14 additions & 26 deletions packages/core/src/features/guppy/guppyDownloadSlice.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
import { gen3Api } from '../gen3';
import { GEN3_API } from '../../constants';
import { FilterSet } from '../filters/types';
import { Accessibility } from '../../constants';
import { GEN3_GUPPY_API } from '../../constants';
import { convertFilterSetToGqlFilter, GQLFilter } from '../filters';
import { BaseGuppyDataRequest, GuppyDownloadDataParams } from './types';

export interface GuppyDownloadDataQueryParams extends BaseGuppyDataRequest {
filter: GQLFilter;
}

interface DownloadRequestStatus {
readonly status: string;
readonly message: string;
}

interface BaseDownloadRequest {
type: string;
accessibility?: Accessibility;
fields?: string[];
sort?: string[];
format?: string;
}

interface DownloadQueryParams extends BaseDownloadRequest {
filters: FilterSet;
}

interface DownloadRequestParams extends BaseDownloadRequest {
readonly filter: GQLFilter;
}

export const downloadRequestApi = gen3Api.injectEndpoints({
endpoints: (builder) => ({
downloadFromGuppy: builder.query({
downloadFromGuppy: builder.mutation({
query: ({
type,
filters,
filter,
accessibility,
fields,
sort,
}: DownloadQueryParams) => {
const queryBody: DownloadRequestParams = {
filter: convertFilterSetToGqlFilter(filters),
}: GuppyDownloadDataParams) => {
const queryBody: GuppyDownloadDataQueryParams = {
filter: convertFilterSetToGqlFilter(filter),
...{ type, accessibility, fields, sort },
};
return {
url: `${GEN3_API}/guppy/download`,
url: `${GEN3_GUPPY_API}/download`,
method: 'POST',
queryBody,
cache: 'no-cache',
};
},
transformResponse: (response: DownloadRequestStatus) => {
Expand All @@ -52,4 +40,4 @@ export const downloadRequestApi = gen3Api.injectEndpoints({
}),
});

export const { useDownloadFromGuppyQuery } = downloadRequestApi;
export const { useDownloadFromGuppyMutation } = downloadRequestApi;
2 changes: 0 additions & 2 deletions packages/core/src/features/guppy/guppySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ interface QueryCountsParams {
accessibility?: Accessibility;
}



const explorerApi = guppyApi.injectEndpoints({
endpoints: (builder) => ({
getAllFieldsForType: builder.query({
Expand Down
Loading
Loading