Skip to content

Commit

Permalink
Playground: Fix Feeback sorting in Side-by-Side view (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
laadvo authored Dec 19, 2024
1 parent 779bac6 commit 7082cec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function EvaluationManagement() {
return newConfig;
};

const saveExpertEvaluationConfig = (configToSave = selectedConfig) => {
const saveExpertEvaluationConfig = (configToSave = selectedConfig, isAnonymize = false) => {
const isNewConfig = configToSave.id === "new";
const newConfig = isNewConfig ? { ...configToSave, id: uuidv4() } : configToSave;
setExpertEvaluationConfigs((prevConfigs) => {
Expand All @@ -81,7 +81,7 @@ export default function EvaluationManagement() {
});

setSelectedConfig(newConfig);
externalSaveExpertEvaluationConfig(dataMode, newConfig, isNewConfig);
externalSaveExpertEvaluationConfig(dataMode, newConfig, isAnonymize);
setHasUnsavedChanges(false);
};

Expand Down Expand Up @@ -122,7 +122,7 @@ export default function EvaluationManagement() {
const startEvaluation = () => {
if (confirm("Are you sure you want to start the evaluation? Once started, you can add new expert links but no other changes can be made to the configuration!")) {
const updatedConfig = updateSelectedConfig({ started: true });
saveExpertEvaluationConfig(updatedConfig);
saveExpertEvaluationConfig(updatedConfig, true);
}
};

Expand Down
17 changes: 14 additions & 3 deletions playground/src/helpers/get_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,18 @@ export function anonymizeFeedbackCategoriesAndShuffle(
export function saveConfigToFileSync(
dataMode: DataMode,
expertEvaluation: ExpertEvaluationConfig,
) {
const configData = JSON.stringify(expertEvaluation, null, 2);
isAddExpertLinksAfterStart = false
){

if (isAddExpertLinksAfterStart) {
let config = getConfigFromFileSync(dataMode, expertEvaluation.id);
if (config && config.expertIds) {
config.expertIds = expertEvaluation.expertIds;
expertEvaluation = config;
}
}

let configData = JSON.stringify(expertEvaluation, null, 2);

const configPath = path.join(
process.cwd(),
Expand Down Expand Up @@ -410,7 +420,8 @@ export function saveConfigToFileSync(
}

// Create or update config file with exercises and data
return fs.writeFileSync(configPath, configData, 'utf8');
fs.writeFileSync(configPath, configData, 'utf8');
return configData;
}

export function getProgressStatsFromFileSync(
Expand Down
6 changes: 3 additions & 3 deletions playground/src/hooks/playground/expert_evaluation_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { DataMode } from "@/model/data_mode";
export async function saveExpertEvaluationConfig(
dataMode: DataMode,
config: ExpertEvaluationConfig,
isCreate: boolean) {
isAnonymize: boolean) {

const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config`, {
method: isCreate ? 'POST' : 'PUT',
const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config?isAnonymize=${isAnonymize}`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(config),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import { ExpertEvaluationConfig } from "@/model/expert_evaluation_config";

function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method == 'POST') {
const { dataMode } = req.query as { dataMode: DataMode };
const { dataMode, isAnonymize } = req.query as { dataMode: DataMode, isAnonymize: string };
const expertEvaluationConfig: ExpertEvaluationConfig = req.body;

anonymizeFeedbackCategoriesAndShuffle(expertEvaluationConfig);
saveConfigToFileSync(dataMode, expertEvaluationConfig);
return res.status(200).json({ message: 'Config created successfully' });
if (isAnonymize == "true") {
anonymizeFeedbackCategoriesAndShuffle(expertEvaluationConfig);
saveConfigToFileSync(dataMode, expertEvaluationConfig);

} else if (req.method == 'PUT') {
const { dataMode } = req.query as { dataMode: DataMode };
const expertEvaluationConfig: ExpertEvaluationConfig = req.body;
// Add expert links after the evaluation has already started
} else {
saveConfigToFileSync(dataMode, expertEvaluationConfig, expertEvaluationConfig.started);
}

saveConfigToFileSync(dataMode, expertEvaluationConfig);
return res.status(200).json({ message: 'Config saved successfully' });
return res.status(200).json({expertEvaluationConfig});

} else if (req.method == 'GET') {
const { dataMode, expertEvaluationId } = req.query as { dataMode: DataMode; expertEvaluationId: string };
Expand All @@ -33,7 +33,7 @@ function handler(req: NextApiRequest, res: NextApiResponse) {
return res.status(200).json(config);
} else {
res.setHeader('Allow', ['POST']);
return res.status(405).json({ message: 'Only GET, POST and PUT requests allowed' });
return res.status(405).json({ message: 'Only GET and POST requests allowed' });
}
}

Expand Down

0 comments on commit 7082cec

Please sign in to comment.