Skip to content
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
50 changes: 33 additions & 17 deletions packages/studio-ui/src/utils/courseConfigRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
export interface ProcessedQuestionData {
name: string;
course: string;
questionClass: any;

Check warning on line 30 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
dataShapes: any[];

Check warning on line 31 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
views: any[];

Check warning on line 32 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

/**
Expand All @@ -38,7 +38,7 @@
export interface ProcessedDataShape {
name: string;
course: string;
dataShape: any;

Check warning on line 41 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -137,20 +137,6 @@
dataShape: ProcessedDataShape,
courseConfig: CourseConfig
): boolean {
if (isDataShapeSchemaAvailable(dataShape, courseConfig)) {
console.log(
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered with schema`
);
return false;
}

if (isDataShapeRegistered(dataShape, courseConfig)) {
console.log(
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered, but with no schema` +
`\n ℹ️ Updating schema in-place`
);
}

const namespacedName = NameSpacer.getDataShapeString({
dataShape: dataShape.name,
course: dataShape.course,
Expand All @@ -165,11 +151,41 @@
serializedZodSchema = undefined;
}

// Check if entry exists but without schema (legacy entry) - remove it
// Check if DataShape already exists
const existingIndex = courseConfig.dataShapes.findIndex((ds) => ds.name === namespacedName);

if (existingIndex !== -1) {
console.log(` 🔧 Replacing legacy DataShape entry: ${namespacedName}`);
courseConfig.dataShapes.splice(existingIndex, 1);
const existingDataShape = courseConfig.dataShapes[existingIndex];

// If existing schema matches new schema, no update needed
if (existingDataShape.serializedZodSchema === serializedZodSchema) {
console.log(
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered with identical schema`
);
return false;
}

// Schema has changed or was missing - update it
if (existingDataShape.serializedZodSchema) {
console.log(
` 🔄 DataShape '${dataShape.name}' from '${dataShape.course}' schema has changed, updating...`
);
} else {
console.log(
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered, but with no schema` +
`\n ℹ️ Adding schema to existing entry`
);
}

// Update the existing entry
courseConfig.dataShapes[existingIndex] = {
name: namespacedName,
questionTypes: existingDataShape.questionTypes, // Preserve existing question type associations
serializedZodSchema,
};

console.log(` ✅ Updated DataShape: ${namespacedName}`);
return true;
}

courseConfig.dataShapes.push({
Expand Down Expand Up @@ -282,8 +298,8 @@
* Register BlanksCard (markdown fillIn) question type specifically
*/
export async function registerBlanksCard(
BlanksCard: any,

Check warning on line 301 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
BlanksCardDataShapes: any[],

Check warning on line 302 in packages/studio-ui/src/utils/courseConfigRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
courseConfig: CourseConfig,
courseDB: CourseDBInterface
): Promise<{ success: boolean; errorMessage?: string }> {
Expand Down
Loading