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

Derive Excel worksheet names from schema annotations #1311

Merged
merged 5 commits into from
Jul 25, 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
4 changes: 0 additions & 4 deletions nmdc_server/static_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def generate_submission_schema_files(directory: Path) -> None:
# The entire submission schema in JSON format
json_dumper.dump(sv.schema, out_dir / "submission_schema.json")

# Each class of the submission schema in JSON format
for class_name, class_definition in sv.all_classes().items():
json_dumper.dump(class_definition, out_dir / f"{class_name}.json")

# The GOLD ecosystem tree that the submission schema re-exports
gold_tree_path = submission_schema_files / "project/thirdparty/GoldEcosystemTree.json"
shutil.copyfile(str(gold_tree_path), out_dir / "GoldEcosystemTree.json")
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ dependencies = [
"ipython==7.31.1",
"itsdangerous==2.0.1",
"mypy<0.920",
"nmdc-schema==10.5.5",
"nmdc-submission-schema==10.5.1",
"nmdc-schema==10.7.0",
"nmdc-submission-schema==10.7.0",
"pint==0.18",
"psycopg2==2.9.3",
"pydantic==1.10.2",
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"linkify-it": "^4.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"nmdc-schema": "https://github.com/microbiomedata/nmdc-schema#v10.5.5",
"nmdc-schema": "https://github.com/microbiomedata/nmdc-schema#v10.7.0",
"popper.js": "1.16.1",
"protobufjs": "^6.11.3",
"serialize-javascript": "^6.0.0",
Expand Down
24 changes: 22 additions & 2 deletions web/src/views/SubmissionPortal/HarmonizerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export default defineComponent({
const submitDialog = ref(false);

const snackbar = ref(false);
const importErrorSnackbar = ref(false);
const notImportedWorksheetNames = ref([] as string[]);

watch(activeTemplate, () => {
// WARNING: It's important to do the column settings update /before/ data. Otherwise,
Expand Down Expand Up @@ -384,7 +386,7 @@ export default defineComponent({
], {
skipHeader: true,
});
utils.book_append_sheet(workbook, worksheet, template.displayName);
utils.book_append_sheet(workbook, worksheet, template.excelWorksheetName || template.displayName);
});
writeFile(workbook, EXPORT_FILENAME, { compression: true });
}
Expand All @@ -401,9 +403,13 @@ export default defineComponent({
}
const workbook = read(event.target.result);
const imported = {} as Record<string, any>;
const notImported = [] as string[];
Object.entries(workbook.Sheets).forEach(([name, worksheet]) => {
const template = Object.values(HARMONIZER_TEMPLATES).find((template) => template.displayName === name);
const template = Object.values(HARMONIZER_TEMPLATES).find((template) => (
template.excelWorksheetName === name || template.displayName === name
));
if (!template || !template.sampleDataSlot || !template.schemaClass) {
notImported.push(name);
return;
}

Expand All @@ -422,6 +428,11 @@ export default defineComponent({
template.schemaClass,
);
});

// Alert the user if any worksheets were not imported
notImportedWorksheetNames.value = notImported;
importErrorSnackbar.value = notImported.length > 0;

// Load imported data
sampleData.value = imported;

Expand Down Expand Up @@ -497,6 +508,8 @@ export default defineComponent({
submitDialog,
snackbar,
schemaLoading,
importErrorSnackbar,
notImportedWorksheetNames,
/* methods */
doSubmit,
downloadSamples,
Expand Down Expand Up @@ -572,6 +585,13 @@ export default defineComponent({
>
Validation Passed! You can now submit or continue editing.
</v-snackbar>
<v-snackbar
v-model="importErrorSnackbar"
color="error"
timeout="5000"
>
The following worksheet names were not recognized: {{ notImportedWorksheetNames.join(', ') }}
</v-snackbar>
<v-card
v-if="validationErrorGroups.length"
color="error"
Expand Down
16 changes: 16 additions & 0 deletions web/src/views/SubmissionPortal/harmonizerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ interface HarmonizerTemplateInfo {
schemaClass?: string,
sampleDataSlot?: string,
status: 'published' | 'mixin' | 'disabled',
// This value comes from annotations in the schema. It will be populated once the schema is loaded.
excelWorksheetName?: string,
}
export const HARMONIZER_TEMPLATES: Record<string, HarmonizerTemplateInfo> = {
air: {
Expand Down Expand Up @@ -208,6 +210,20 @@ export class HarmonizerApi {
this.schema = schema;
this.goldEcosystemTree = goldEcosystemTree;

// Attempt to find each template's underlying schema class, pull the excel_worksheet_name annotation from it
// and add it to the template object.
Object.values(HARMONIZER_TEMPLATES).forEach((template) => {
if (!template.schemaClass) {
return;
}
const classDefinition = schema.classes[template.schemaClass];
if (!classDefinition) {
return;
}
// eslint-disable-next-line no-param-reassign
template.excelWorksheetName = classDefinition.annotations?.excel_worksheet_name?.value;
});

this.dh = new DataHarmonizer(r, {
modalsRoot: document.querySelector('.harmonizer-style-container'),
fieldSettings: this._getFieldSettings(),
Expand Down
4 changes: 2 additions & 2 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7635,9 +7635,9 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

"nmdc-schema@https://github.com/microbiomedata/nmdc-schema#v10.5.5":
"nmdc-schema@https://github.com/microbiomedata/nmdc-schema#v10.7.0":
version "0.0.0"
resolved "https://github.com/microbiomedata/nmdc-schema#0ed6dfd1823deaa8ede6ca8250188429d7d86305"
resolved "https://github.com/microbiomedata/nmdc-schema#ad1440736c1e088705a8b09f88727c0e195abfb3"

no-case@^2.2.0:
version "2.3.2"
Expand Down