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

RUI race condition fix #1101

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { MatCheckbox } from '@angular/material/checkbox';
import { MatCheckbox, MatCheckboxChange } from '@angular/material/checkbox';
import { Shallow } from 'shallow-render';

import { CheckboxComponent } from './checkbox.component';
import { CheckboxModule } from './checkbox.module';
import { MatCheckboxChange } from '@angular/material/checkbox';


describe('FiltersCheckboxComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ReferenceDataState extends NgxsImmutableDataRepository<ReferenceDat
});
}

private getSourceDB(): Observable<ReferenceDataStateModel> {
getSourceDB(): Observable<ReferenceDataStateModel> {
return this.globalConfig.getOption('baseHref').pipe(
map(baseHref => (baseHref ?? '') + 'assets/reference-organ-data.json'),
switchMap(url => from(fetch(url)).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ describe('RegistrationState', () => {
{
provide: ReferenceDataState, useValue: {
state$: referenceDataStateSubject,
snapshot: initialReferenceDataState
snapshot: initialReferenceDataState,
getSourceDB: () => (
{
subscribe: () => undefined
}
)
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ export class RegistrationState extends NgxsImmutableDataRepository<RegistrationS
this.tags = this.injector.get(AnatomicalStructureTagState);
this.refData = this.injector.get(ReferenceDataState);

this.globalConfig.config$.pipe(
take(1),
tap(({ useDownload, register }) => this.ctx.patchState({
useRegistrationCallback: !!(!useDownload && register)
}))
).subscribe();

this.globalConfig.getOption('editRegistration').pipe(
filterNulls(),
tap(reg => this.editRegistration(reg as SpatialEntityJsonLd))
).subscribe();
this.refData.getSourceDB().subscribe(db => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may cause the database to be loaded twice. Instead listen to the refData state (or part of it) and then subscribe to that.

this.refData.setState(db);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done in the reference data state


this.globalConfig.config$.pipe(
take(1),
tap(({ useDownload, register }) => this.ctx.patchState({
useRegistrationCallback: !!(!useDownload && register)
}))
).subscribe();

this.globalConfig.getOption('editRegistration').pipe(
filterNulls(),
tap(reg => this.editRegistration(reg as SpatialEntityJsonLd))
).subscribe();
});
}

async editRegistration(reg: SpatialEntityJsonLd): Promise<void> {
Expand Down
10 changes: 5 additions & 5 deletions projects/ccf-rui/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<meta charset="utf-8">
<title>HuBMAP CCF Registration User Interface (CCF-RUI)</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet">
<script>
// To test embedded mode, from the console paste:
// localStorage.setItem('TEST_EMBEDDED', true);
Expand Down Expand Up @@ -50,8 +54,8 @@
window.addEventListener('DOMContentLoaded', () => {
const rui = document.querySelector('ccf-rui');
rui.baseHref = 'https://cdn.jsdelivr.net/gh/hubmapconsortium/ccf-ui@staging/rui/';
rui.user = {firstName: 'Jane', lastName: 'Doe'};
rui.useDownload = true;
rui.user = {firstName: 'Jane', lastName: 'Doe'};
rui.organ = { name: 'kidney', side: 'left', sex: 'female' };
rui.editRegistration = sampleRegistration;
rui.register = (data) => {
Expand All @@ -66,10 +70,6 @@
});
}
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Sharp" rel="stylesheet">
</head>
<body>
<ccf-rui></ccf-rui>
Expand Down
79 changes: 79 additions & 0 deletions projects/ccf-rui/src/webcomponent-async-inject-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HuBMAP CCF Registration User Interface (CCF-RUI)</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet">
<script>
// To test embedded mode, from the console paste:
// localStorage.setItem('TEST_EMBEDDED', true);
if (localStorage['TEST_EMBEDDED'] === 'true') {
const sampleRegistration = {
"@context": "https://hubmapconsortium.github.io/ccf-ontology/ccf-context.jsonld",
"@id": "http://purl.org/ccf/1.5/523ad946-115b-433a-bd1d-ba4b75f8c493",
"@type": "SpatialEntity",
"creator": "Jane Doe",
"creator_first_name": "Jane",
"creator_last_name": "Doe",
"creation_date": "2023-08-29",
"ccf_annotations": [
"http://purl.obolibrary.org/obo/UBERON_0002015",
"http://purl.obolibrary.org/obo/UBERON_0008716",
"http://purl.obolibrary.org/obo/UBERON_0000362",
"http://purl.obolibrary.org/obo/UBERON_0001228",
"http://purl.obolibrary.org/obo/UBERON_0004200",
"http://purl.obolibrary.org/obo/UBERON_0001225",
"http://purl.obolibrary.org/obo/UBERON_0001284",
"http://purl.obolibrary.org/obo/UBERON_0002189"
],
"slice_thickness": 1,
"slice_count": 2,
"x_dimension": 16,
"y_dimension": 12,
"z_dimension": 14,
"dimension_units": "millimeter",
"placement": {
"@context": "https://hubmapconsortium.github.io/ccf-ontology/ccf-context.jsonld",
"@id": "http://purl.org/ccf/1.5/523ad946-115b-433a-bd1d-ba4b75f8c493_placement",
"@type": "SpatialPlacement",
"target": "http://purl.org/ccf/latest/ccf.owl#VHFLeftKidneyV1.1",
"placement_date": "2023-08-29",
"x_scaling": 1,
"y_scaling": 1,
"z_scaling": 1,
"scaling_units": "ratio",
"x_rotation": 10,
"y_rotation": 25,
"z_rotation": 32,
"rotation_order": "XYZ",
"rotation_units": "degree",
"x_translation": 25.866,
"y_translation": 94.635,
"z_translation": 38.79,
"translation_units": "millimeter"
}
};

window.addEventListener('DOMContentLoaded', () => {
const rui = document.createElement("ccf-rui");
rui.baseHref = 'https://cdn.jsdelivr.net/gh/hubmapconsortium/ccf-ui@staging/rui/';
rui.useDownload = true;

setTimeout(() => {
rui.user = {firstName: 'Jane', lastName: 'Doe'};
rui.organ = { name: 'kidney', side: 'left', sex: 'female' };
rui.editRegistration = sampleRegistration;
document.body.appendChild(rui);
}, 2000);
});
}
</script>
</head>

<body class="mat-typography">
</body>
</html>
3 changes: 0 additions & 3 deletions projects/ccf-rui/src/webcomponent-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<script src="wc.js" defer></script>
<script>
// To test embedded mode, from the console paste:
// localStorage.setItem('TEST_EMBEDDED', true);
Expand Down Expand Up @@ -74,6 +72,5 @@
</script>
</head>
<body class="mat-typography">
<ccf-rui></ccf-rui>
</body>
</html>
Loading