Skip to content

Commit

Permalink
Update template logic to use an environment array
Browse files Browse the repository at this point in the history
  • Loading branch information
marySalvi committed Sep 16, 2024
1 parent df95bad commit 3650877
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
58 changes: 35 additions & 23 deletions web/src/views/SubmissionPortal/HarmonizerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export default defineComponent({
// columns will not be rendered with the correct width.
harmonizerApi.setColumnsReadOnly(ALWAYS_READ_ONLY_COLUMNS);
// if we're not on the first tab, the common columns should be read-only
if (activeTemplateKey.value !== templateList.value[0]) {
const environmentList = templateList.value.filter((t) => HARMONIZER_TEMPLATES[t].status === 'published');
if (!environmentList.includes(activeTemplateKey.value)) {
harmonizerApi.setColumnsReadOnly(COMMON_COLUMNS);
harmonizerApi.setMaxRows(activeTemplateData.value.length);
}
Expand Down Expand Up @@ -324,37 +326,45 @@ export default defineComponent({
}
const nextData = { ...sampleData.value };
const templateSlot = HARMONIZER_TEMPLATES[templateKey].sampleDataSlot;
const environmentSlot = HARMONIZER_TEMPLATES[templateList.value[0]].sampleDataSlot;
if (!templateSlot || !environmentSlot) {
const environmentSlots = templateList.value
.filter((t) => HARMONIZER_TEMPLATES[t].status === 'published')
.map((t) => HARMONIZER_TEMPLATES[t].sampleDataSlot);
if (!templateSlot || !environmentSlots) {
return;
}
// ensure the necessary keys exist in the data object
if (!nextData[environmentSlot]) {
nextData[environmentSlot] = [];
}
environmentSlots.forEach((slot) => {
if (!nextData[slot as string]) {
nextData[slot as string] = [];
}
});
if (!nextData[templateSlot]) {
nextData[templateSlot] = [];
}
// add/update any rows from the first tab to the active tab if they apply and if
// they aren't there already.
nextData[environmentSlot].forEach((row) => {
const rowId = row[SCHEMA_ID];
const existing = nextData[templateSlot] && nextData[templateSlot].find((r) => r[SCHEMA_ID] === rowId);
if (!existing && rowIsVisibleForTemplate(row, templateKey)) {
const newRow = {} as Record<string, any>;
COMMON_COLUMNS.forEach((col) => {
newRow[col] = row[col];
});
nextData[templateSlot].push(newRow);
}
if (existing) {
COMMON_COLUMNS.forEach((col) => {
existing[col] = row[col];
});
}
environmentSlots.forEach((environmentSlot) => {
nextData[environmentSlot as string].forEach((row) => {
const rowId = row[SCHEMA_ID];
const existing = nextData[templateSlot] && nextData[templateSlot].find((r) => r[SCHEMA_ID] === rowId);
if (!existing && rowIsVisibleForTemplate(row, templateKey)) {
const newRow = {} as Record<string, any>;
COMMON_COLUMNS.forEach((col) => {
newRow[col] = row[col];
});
nextData[templateSlot].push(newRow);
}
if (existing) {
COMMON_COLUMNS.forEach((col) => {
existing[col] = row[col];
});
}
});
});
// remove any rows from the active tab if they were removed from the first tab
// or no longer apply to the active tab
Expand All @@ -364,8 +374,10 @@ export default defineComponent({
return false;
}
const rowId = row[SCHEMA_ID];
const environmentRow = nextData[environmentSlot].findIndex((r) => r[SCHEMA_ID] === rowId);
return environmentRow >= 0;
return environmentSlots.every((environmentSlot) => {
const environmentRow = nextData[environmentSlot as string].findIndex((r) => r[SCHEMA_ID] === rowId);
return environmentRow >= 0;
});
});
}
sampleData.value = nextData;
Expand Down
14 changes: 7 additions & 7 deletions web/src/views/SubmissionPortal/harmonizerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ export const JGI_MG = 'jgi_mg';
export const JGI_MG_LR = 'jgi_mg_lr';
export const JGT_MT = 'jgi_mt';
export function getVariants(checkBoxes: string[], dataGenerated: boolean | undefined, base: string[]): string[] {
const templates = base;
const templates = new Set(base);
if (dataGenerated) {
return templates;
return Array.from(templates);
}
if (checkBoxes.includes('mp-emsl') || checkBoxes.includes('mb-emsl') || checkBoxes.includes('nom-emsl')) {
templates.push(EMSL);
templates.add(EMSL);
}
if (checkBoxes.includes('mg-jgi')) {
templates.push(JGI_MG);
templates.add(JGI_MG);
}
if (checkBoxes.includes('mg-lr-jgi')) {
templates.push(JGI_MG_LR);
templates.add(JGI_MG_LR);
}
if (checkBoxes.includes('mt-jgi')) {
templates.push(JGT_MT);
templates.add(JGT_MT);
}
return templates;
return Array.from(templates);
}

/**
Expand Down
1 change: 0 additions & 1 deletion web/src/views/SubmissionPortal/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ const templateList = computed(() => {
const list = getVariants(checkBoxes, contextForm.dataGenerated, packageName.value);
return list;
});

/**
* DataHarmonizer Step
*/
Expand Down

0 comments on commit 3650877

Please sign in to comment.