Skip to content
Draft
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
16 changes: 14 additions & 2 deletions apps/backend/src/models/questionTypes/InstrumentPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { InstrumentPickerConfig } from '../../resolvers/types/FieldConfig';
import { QuestionFilterCompareOperator } from '../Questionary';
import { DataType, QuestionTemplateRelation } from '../Template';
import { Question } from './QuestionRegistry';
import { CallDataSource } from '../../datasources/CallDataSource';

export class InstrumentOptionClass {
constructor(
Expand Down Expand Up @@ -40,6 +41,7 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
config.isMultipleSelect = false;
config.requestTime = false;
config.readPermissions = [];
config.allocationTimeUnit = '';

return config;
},
Expand All @@ -57,7 +59,7 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
}
},
transformConfig: async (config, callId) => {
const fallBackConfig = { ...config, instruments: [] };
const fallBackConfig = { ...config, instruments: [], allocationTimeUnit: ''};
try {
if (!callId) return fallBackConfig;

Expand All @@ -70,15 +72,25 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
true
);

const callDataSource = container.resolve<CallDataSource>(
Tokens.CallDataSource
);
const call = await callDataSource.getCall(callId);
if (!call) {
throw new Error('Call not found');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see this is in a try block, but if the try fails then it just errors out. Maybe we'd rather go back to fallBackConfig, if we can't get the call? or still show the instrument picker on screen, just without a allocatedTimeUnit?

}
const allocationTimeUnit = call.allocationTimeUnit;

return {
...config,
instruments: instruments.map(
(instrument) =>
new InstrumentOptionClass(instrument.id, instrument.name)
),
allocationTimeUnit: allocationTimeUnit,
};
} catch (err) {
logger.logError('Call Instruments fetch failed', {
logger.logError('Call/Instruments fetch failed', {
err,
});
}
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/resolvers/types/FieldConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ export class InstrumentPickerConfig extends ConfigBase {
@Field(() => [InstrumentOption])
instruments: InstrumentOption[];

@Field(() => String)
allocationTimeUnit: string;

@Field(() => Boolean)
isMultipleSelect: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function QuestionaryComponentInstrumentPicker(
} = answer;

const config = answer.config as InstrumentPickerConfig;
const allocationTimeUnit = config.allocationTimeUnit;
const [stateValue, setStateValue] = useState<
Array<InstrumentIdAndTime> | InstrumentIdAndTime
>(() => processInstrumentPickerValue(answer, config));
Expand Down Expand Up @@ -185,7 +186,7 @@ export function QuestionaryComponentInstrumentPicker(
value={value.timeRequested === '0' ? '' : value.timeRequested}
required={config.required}
error={isError}
label={`Request Time`}
label={`Request Time (${allocationTimeUnit}s)`}
type="number"
InputProps={{
startAdornment: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fragment fieldConfig on FieldConfig {
id
name
}
allocationTimeUnit
}

... on TechniquePickerConfig {
Expand Down
Loading