Skip to content

Commit 89ce084

Browse files
committed
feat: add allocation time unit to instrument picker question
1 parent c943ca8 commit 89ce084

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

apps/backend/src/models/questionTypes/InstrumentPicker.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { InstrumentPickerConfig } from '../../resolvers/types/FieldConfig';
1212
import { QuestionFilterCompareOperator } from '../Questionary';
1313
import { DataType, QuestionTemplateRelation } from '../Template';
1414
import { Question } from './QuestionRegistry';
15+
import { CallDataSource } from '../../datasources/CallDataSource';
1516

1617
export class InstrumentOptionClass {
1718
constructor(
@@ -40,6 +41,7 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
4041
config.isMultipleSelect = false;
4142
config.requestTime = false;
4243
config.readPermissions = [];
44+
config.allocationTimeUnit = '';
4345

4446
return config;
4547
},
@@ -57,7 +59,7 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
5759
}
5860
},
5961
transformConfig: async (config, callId) => {
60-
const fallBackConfig = { ...config, instruments: [] };
62+
const fallBackConfig = { ...config, instruments: [], allocationTimeUnit: ''};
6163
try {
6264
if (!callId) return fallBackConfig;
6365

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

75+
const callDataSource = container.resolve<CallDataSource>(
76+
Tokens.CallDataSource
77+
);
78+
const call = await callDataSource.getCall(callId);
79+
if (!call) {
80+
throw new Error('Call not found');
81+
}
82+
const allocationTimeUnit = call.allocationTimeUnit;
83+
7384
return {
7485
...config,
7586
instruments: instruments.map(
7687
(instrument) =>
7788
new InstrumentOptionClass(instrument.id, instrument.name)
7889
),
90+
allocationTimeUnit: allocationTimeUnit,
7991
};
8092
} catch (err) {
81-
logger.logError('Call Instruments fetch failed', {
93+
logger.logError('Call/Instruments fetch failed', {
8294
err,
8395
});
8496
}

apps/backend/src/resolvers/types/FieldConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ export class InstrumentPickerConfig extends ConfigBase {
202202
@Field(() => [InstrumentOption])
203203
instruments: InstrumentOption[];
204204

205+
@Field(() => String)
206+
allocationTimeUnit: string;
207+
205208
@Field(() => Boolean)
206209
isMultipleSelect: boolean;
207210

apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionaryComponentInstrumentPicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function QuestionaryComponentInstrumentPicker(
6868
} = answer;
6969

7070
const config = answer.config as InstrumentPickerConfig;
71+
const allocationTimeUnit = config.allocationTimeUnit;
7172
const [stateValue, setStateValue] = useState<
7273
Array<InstrumentIdAndTime> | InstrumentIdAndTime
7374
>(() => processInstrumentPickerValue(answer, config));
@@ -185,7 +186,7 @@ export function QuestionaryComponentInstrumentPicker(
185186
value={value.timeRequested === '0' ? '' : value.timeRequested}
186187
required={config.required}
187188
error={isError}
188-
label={`Request Time`}
189+
label={`Request Time (${allocationTimeUnit}s)`}
189190
type="number"
190191
InputProps={{
191192
startAdornment: (

apps/frontend/src/graphql/template/fragment.fieldConfig.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ fragment fieldConfig on FieldConfig {
217217
id
218218
name
219219
}
220+
allocationTimeUnit
220221
}
221222

222223
... on TechniquePickerConfig {

0 commit comments

Comments
 (0)