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

Prevent errors when processing additional rdf metadata #2496

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions web-marketplace/src/lib/rdf/rdf.compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ContextDefinition, JsonLdDocument, NodeObject } from 'jsonld';

import { COMPACTED_CONTEXT } from './rdf.constants';

// TODO: Support documents with @graph
export const jsonLdCompact = async (
data: JsonLdDocument,
context?: object,
Expand Down
5 changes: 3 additions & 2 deletions web-marketplace/src/lib/rdf/rdf.unknown-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

function getUnknowFields(data: object, knownFields: string[]) {
return Object.entries(data).filter(
([key]) => !['@context', '@type', '@id', ...knownFields].includes(key),
([key]) => !['@context', '@graph', '@type', '@id', ...knownFields].includes(key),
);
}

Expand Down Expand Up @@ -92,7 +92,8 @@ export function getBatchUnknownFields<
}

export function getFieldLabel(fieldName: string) {
return fieldName.split(':')[1].replace(/([A-Z])/g, ' $1');
// Remove the field prefix and add space before capital letters.
return fieldName.replace(/[^:]*\:/, '').replace(/([A-Z])/g, ' $1');
Comment on lines +95 to +96
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes another bug we discovered where the page crashes if the field key doesn't have a colon prefix. This is a simple change to safely remove the first prefix: if one exists.

Compare: https://dev.app.regen.network/credit-batches/MBS01-001-20240601-20340531-002

And: https://deploy-preview-2496--regen-marketplace.netlify.app/credit-batches/MBS01-001-20240601-20340531-002

}

export function getFieldType(fieldName: string, context?: ContextDefinition) {
Expand Down