Skip to content

Commit

Permalink
refactor(anni): make placeholders more extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Jul 14, 2022
1 parent cb6a11f commit d126fa6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 2 additions & 9 deletions annotation-interface/components/bricks/BrickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import {
translationsToArray,
translationsToMap,
} from '../../database/helpers/brick-translations';
import {
allBrickPlaceholders,
medicationBrickPlaceholders,
} from '../../database/helpers/resolve-bricks';
import { placeHoldersForBrick } from '../../database/helpers/resolve-bricks';
import {
ITextBrick,
ITextBrickTranslation,
Expand Down Expand Up @@ -126,11 +123,7 @@ const BrickForm = ({ usage, brick }: Props) => {
onChange={(text) =>
updateTranslation(language, text)
}
validPlaceholders={
usage.startsWith('Drug')
? [...medicationBrickPlaceholders]
: [...allBrickPlaceholders]
}
validPlaceholders={placeHoldersForBrick(usage)}
/>
</div>
))}
Expand Down
20 changes: 17 additions & 3 deletions annotation-interface/database/helpers/resolve-bricks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { pharMeLanguage, SupportedLanguage } from '../../common/constants';
import {
BrickUsage,
pharMeLanguage,
SupportedLanguage,
} from '../../common/constants';
import {
ServerGuidelineOverview,
ServerMedication,
Expand All @@ -9,12 +13,22 @@ import { ITextBrick } from '../models/TextBrick';
import { translationsToMap } from './brick-translations';
import { MongooseId, OptionalId } from './types';

export const medicationBrickPlaceholders = ['drug-name'] as const;
export const allBrickPlaceholders = [
const medicationBrickPlaceholders = ['drug-name'] as const;
const allBrickPlaceholders = [
...medicationBrickPlaceholders,
'gene-symbol',
'gene-result',
] as const;
export const placeHoldersForBrick = (category: BrickUsage): string[] => {
switch (category) {
case 'Drug class':
case 'Drug indication':
return [...medicationBrickPlaceholders];
case 'Implication':
case 'Recommendation':
return [...allBrickPlaceholders];
}
};
type BrickPlaceholderValues = {
[Property in typeof allBrickPlaceholders[number]]?: string;
};
Expand Down

0 comments on commit d126fa6

Please sign in to comment.