-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add conditional file download for anvil-cmg (#4635) #4679
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d040092
feat: add conditional file download for anvil-cmg (#4635)
MillenniumFalconMechanic 05a7eb4
test: add unit tests for buildFileDownload (#4635)
MillenniumFalconMechanic a40b0c8
refactor: rename AzulFileDownloadController to match naming conventio…
MillenniumFalconMechanic cafded6
fix: linting #4679
MillenniumFalconMechanic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| import { buildFileDownload } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders"; | ||
| import { FilesResponse } from "../../app/apis/azul/anvil-cmg/common/responses"; | ||
|
|
||
| /** | ||
| * Creates a mock FilesResponse with configurable file and dataset values. | ||
| * @param overrides - Partial overrides for the files array. | ||
| * @param datasetOverrides - Partial overrides for the datasets array. | ||
| * @returns Mock FilesResponse. | ||
| */ | ||
| const createMockFilesResponse = ( | ||
| overrides: Partial<FilesResponse["files"][0]> = {}, | ||
| datasetOverrides: Partial<FilesResponse["datasets"][0]> = {} | ||
| ): FilesResponse => ({ | ||
| activities: [ | ||
| { | ||
| activity_type: ["Sequencing"], | ||
| data_modality: ["Genomic"], | ||
| }, | ||
| ], | ||
| biosamples: [ | ||
| { | ||
| anatomical_site: ["Blood"], | ||
| biosample_type: ["Normal"], | ||
| }, | ||
| ], | ||
| datasets: [ | ||
| { | ||
| dataset_id: ["dataset-123"], | ||
| title: ["Test Dataset"], | ||
| ...datasetOverrides, | ||
| }, | ||
| ], | ||
| donors: [ | ||
| { | ||
| organism_type: ["Homo sapiens"], | ||
| phenotypic_sex: ["Female"], | ||
| reported_ethnicity: ["Not reported"], | ||
| }, | ||
| ], | ||
| entryId: "entry-123", | ||
| files: [ | ||
| { | ||
| accessible: true, | ||
| azul_mirror_uri: null, | ||
| azul_url: "https://service.azul.data/repository/files/file-123", | ||
| data_modality: ["Genomic"], | ||
| date_created: "2024-01-01", | ||
| document_id: "doc-123", | ||
| drs_uri: "drs://data.azul/file-123", | ||
| file_format: "bam", | ||
| file_id: "file-123", | ||
| file_name: "sample.bam", | ||
| file_size: 1024, | ||
| file_type: "Analysis", | ||
| ...overrides, | ||
| }, | ||
| ], | ||
| libraries: [ | ||
| { | ||
| prep_material_name: ["RNA"], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| describe("buildFileDownload", () => { | ||
| describe("url prop based on azul_mirror_uri", () => { | ||
| it("returns undefined url when azul_mirror_uri is null", () => { | ||
| const response = createMockFilesResponse({ | ||
| azul_mirror_uri: null, | ||
| azul_url: "https://service.azul.data/repository/files/file-123", | ||
| }); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.url).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns undefined url when azul_mirror_uri is empty string", () => { | ||
| const response = createMockFilesResponse({ | ||
| azul_mirror_uri: "", | ||
| azul_url: "https://service.azul.data/repository/files/file-123", | ||
| }); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.url).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns azul_url when azul_mirror_uri has a value", () => { | ||
| const azulUrl = "https://service.azul.data/repository/files/file-123"; | ||
| const response = createMockFilesResponse({ | ||
| azul_mirror_uri: "s3://bucket/path/to/file.bam", | ||
| azul_url: azulUrl, | ||
| }); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.url).toBe(azulUrl); | ||
| }); | ||
|
|
||
| it("returns azul_url value exactly as provided when mirror uri exists", () => { | ||
| const azulUrl = | ||
| "https://service.azul.data/repository/files/different-file-456"; | ||
| const response = createMockFilesResponse({ | ||
| azul_mirror_uri: "s3://other-bucket/other-path.bam", | ||
| azul_url: azulUrl, | ||
| }); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.url).toBe(azulUrl); | ||
| }); | ||
| }); | ||
|
|
||
| describe("other props", () => { | ||
| it("returns correct entityName from file_name", () => { | ||
| const response = createMockFilesResponse({ | ||
| file_name: "my-sample-file.bam", | ||
| }); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.entityName).toBe("my-sample-file.bam"); | ||
| }); | ||
|
|
||
| it("returns correct relatedEntityId from dataset_id", () => { | ||
| const response = createMockFilesResponse( | ||
| {}, | ||
| { dataset_id: ["my-dataset-id-123"] } | ||
| ); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.relatedEntityId).toBe("my-dataset-id-123"); | ||
| }); | ||
|
|
||
| it("returns correct relatedEntityName from dataset title", () => { | ||
| const response = createMockFilesResponse( | ||
| {}, | ||
| { title: ["My Research Dataset"] } | ||
| ); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result.relatedEntityName).toBe("My Research Dataset"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("integration scenarios", () => { | ||
| it("returns all props correctly when download is enabled", () => { | ||
| const response = createMockFilesResponse( | ||
| { | ||
| azul_mirror_uri: "s3://bucket/file.bam", | ||
| azul_url: "https://azul.service/files/123", | ||
| file_name: "research-data.bam", | ||
| }, | ||
| { | ||
| dataset_id: ["dataset-abc"], | ||
| title: ["Genomics Research Project"], | ||
| } | ||
| ); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result).toEqual({ | ||
| entityName: "research-data.bam", | ||
| relatedEntityId: "dataset-abc", | ||
| relatedEntityName: "Genomics Research Project", | ||
| url: "https://azul.service/files/123", | ||
| }); | ||
| }); | ||
|
|
||
| it("returns all props correctly when download is disabled", () => { | ||
| const response = createMockFilesResponse( | ||
| { | ||
| azul_mirror_uri: null, | ||
| azul_url: "https://azul.service/files/123", | ||
| file_name: "research-data.bam", | ||
| }, | ||
| { | ||
| dataset_id: ["dataset-abc"], | ||
| title: ["Genomics Research Project"], | ||
| } | ||
| ); | ||
|
|
||
| const result = buildFileDownload(response); | ||
|
|
||
| expect(result).toEqual({ | ||
| entityName: "research-data.bam", | ||
| relatedEntityId: "dataset-abc", | ||
| relatedEntityName: "Genomics Research Project", | ||
| url: undefined, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/components/Index/components/AzulFileDownload/azulFileDownload.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { useExploreState } from "@databiosphere/findable-ui/lib/hooks/useExploreState"; | ||
| import { useFeatureFlag } from "@databiosphere/findable-ui/lib/hooks/useFeatureFlag/useFeatureFlag"; | ||
| import { updateVisibility } from "@databiosphere/findable-ui/lib/providers/exploreState/actions/updateVisibility/dispatch"; | ||
| import { JSX, useEffect } from "react"; | ||
| import { FEATURES } from "../../../../shared/entities"; | ||
| import { ANVIL_CMG_CATEGORY_KEY } from "../../../../../site-config/anvil-cmg/category"; | ||
|
|
||
| /** | ||
| * Controller component that syncs the AZUL_DOWNLOAD feature flag with column visibility. | ||
| * Renders nothing but manages the download column visibility based on the feature flag. | ||
| * @returns Empty fragment. | ||
| */ | ||
| export const AzulFileDownload = (): JSX.Element => { | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const isDownloadEnabled = useFeatureFlag(FEATURES.AZUL_DOWNLOAD); | ||
| const { exploreDispatch } = useExploreState(); | ||
|
|
||
| useEffect(() => { | ||
| exploreDispatch( | ||
| updateVisibility({ | ||
| updaterOrValue: (prev) => ({ | ||
| ...prev, | ||
| [ANVIL_CMG_CATEGORY_KEY.AZUL_FILE_DOWNLOAD]: isDownloadEnabled, | ||
| }), | ||
| }) | ||
| ); | ||
| }, [isDownloadEnabled, exploreDispatch]); | ||
|
|
||
| return <></>; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { | ||
| ComponentConfig, | ||
| ComponentsConfig, | ||
| } from "@databiosphere/findable-ui/lib/config/entities"; | ||
| import * as C from "../../../../app/components"; | ||
| import * as MDX from "../../../../app/components/common/MDXContent/anvil-cmg"; | ||
| import * as V from "../../../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders"; | ||
|
|
||
| export const filesEntityListSlot: ComponentsConfig = [ | ||
| { | ||
| component: MDX.AlertEntityListWarning, | ||
| viewBuilder: V.buildAlertEntityListWarning, | ||
| } as ComponentConfig<typeof MDX.AlertEntityListWarning>, | ||
| { | ||
| component: C.AzulFileDownloadVisibilityController, | ||
| } as ComponentConfig<typeof C.AzulFileDownloadVisibilityController>, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.