Skip to content

Commit 7082cec

Browse files
authored
Playground: Fix Feeback sorting in Side-by-Side view (#382)
1 parent 779bac6 commit 7082cec

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

playground/src/components/view_mode/evaluation_mode/expert_evaluation/evaluation_management.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function EvaluationManagement() {
6666
return newConfig;
6767
};
6868

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

8383
setSelectedConfig(newConfig);
84-
externalSaveExpertEvaluationConfig(dataMode, newConfig, isNewConfig);
84+
externalSaveExpertEvaluationConfig(dataMode, newConfig, isAnonymize);
8585
setHasUnsavedChanges(false);
8686
};
8787

@@ -122,7 +122,7 @@ export default function EvaluationManagement() {
122122
const startEvaluation = () => {
123123
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!")) {
124124
const updatedConfig = updateSelectedConfig({ started: true });
125-
saveExpertEvaluationConfig(updatedConfig);
125+
saveExpertEvaluationConfig(updatedConfig, true);
126126
}
127127
};
128128

playground/src/helpers/get_data.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,18 @@ export function anonymizeFeedbackCategoriesAndShuffle(
364364
export function saveConfigToFileSync(
365365
dataMode: DataMode,
366366
expertEvaluation: ExpertEvaluationConfig,
367-
) {
368-
const configData = JSON.stringify(expertEvaluation, null, 2);
367+
isAddExpertLinksAfterStart = false
368+
){
369+
370+
if (isAddExpertLinksAfterStart) {
371+
let config = getConfigFromFileSync(dataMode, expertEvaluation.id);
372+
if (config && config.expertIds) {
373+
config.expertIds = expertEvaluation.expertIds;
374+
expertEvaluation = config;
375+
}
376+
}
377+
378+
let configData = JSON.stringify(expertEvaluation, null, 2);
369379

370380
const configPath = path.join(
371381
process.cwd(),
@@ -410,7 +420,8 @@ export function saveConfigToFileSync(
410420
}
411421

412422
// Create or update config file with exercises and data
413-
return fs.writeFileSync(configPath, configData, 'utf8');
423+
fs.writeFileSync(configPath, configData, 'utf8');
424+
return configData;
414425
}
415426

416427
export function getProgressStatsFromFileSync(

playground/src/hooks/playground/expert_evaluation_config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { DataMode } from "@/model/data_mode";
66
export async function saveExpertEvaluationConfig(
77
dataMode: DataMode,
88
config: ExpertEvaluationConfig,
9-
isCreate: boolean) {
9+
isAnonymize: boolean) {
1010

11-
const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config`, {
12-
method: isCreate ? 'POST' : 'PUT',
11+
const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config?isAnonymize=${isAnonymize}`, {
12+
method: 'POST',
1313
headers: { "Content-Type": "application/json" },
1414
body: JSON.stringify(config),
1515
});

playground/src/pages/api/data/[dataMode]/expert_evaluation/[expertEvaluationId]/config.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import { ExpertEvaluationConfig } from "@/model/expert_evaluation_config";
1111

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

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

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

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

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

0 commit comments

Comments
 (0)