Skip to content

Commit

Permalink
fix(gr-sheet): Add support for NONE for UoM references
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Jan 2, 2025
1 parent 69ff7a3 commit 40875c6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/gr-sheet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ async function * generateGRItems(parsedSheetItems, opts) {
throw new Error(`Unable to resolve reference, ${itemID}`);
}

const isCellNull = function (cellContents: string): boolean {
return cellContents.trim().length === 0 || cellContents.trim().toLowerCase() === 'none';
}

const resolveNullableReference = function (cellContents: string, mode: Predicate["mode"]): ReturnType<typeof resolveReference> | null {
if (isCellNull(cellContents)) {
return null;
}
return resolveReference(cellContents, mode);
}

const resolveRelated = function resolveRelated(cellContents: string) {

//const itemID = sheetItemID.split(' ')[0];
Expand Down Expand Up @@ -277,7 +288,7 @@ async function * generateGRItems(parsedSheetItems, opts) {
if (isRegisterItemProcessor(processor)) {
return processor.toRegisterItem(pr, resolveAndConstruct, resolveReference, opts);
} else if (isBasicSheetItemProcessor(processor)) {
return processor.toItem(pr, resolveAndConstruct, resolveReference, opts);
return processor.toItem(pr, resolveAndConstruct, resolveNullableReference, opts);
} else {
throw new Error("Unknown processor");
}
Expand Down Expand Up @@ -375,7 +386,7 @@ interface BaseSheetItemProcessor<F extends string, I> {
*/
resolveReference:
(rawCellContents: string, mode: Predicate["mode"]) =>
Predicate | InternalItemReference | string,
Predicate | InternalItemReference | string | null,
opts?: { onProgress?: (msg: string) => void },
) => I;
}
Expand Down Expand Up @@ -411,7 +422,7 @@ extends Omit<BaseSheetItemProcessor<F, RI>, 'toItem'> {
*/
resolveReference:
(rawCellContents: string, mode: Predicate["mode"]) =>
Predicate | InternalItemReference | string,
Predicate | InternalItemReference | string | null,
opts?: { onProgress?: (msg: string) => void },
) => RI;
}
Expand Down Expand Up @@ -751,7 +762,7 @@ const SupportedSheets = {
: ParameterType.MEASURE,
unitOfMeasurement: ["Reference File", 'Integer'].includes(type)
? null
: resolveReference(unitOfMeasurement, 'id') as string | Predicate,
: resolveReference(unitOfMeasurement, 'id') as string | Predicate | null,
value: type === "Reference File"
? fileRef
: value,
Expand Down

0 comments on commit 40875c6

Please sign in to comment.