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

fix(gr-sheet): Add support for NONE for UoM references #19

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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
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
Loading