Skip to content

Commit 84d060e

Browse files
authored
SF-3163a Forward compatibility with the upcoming draft source arrays (#3531)
1 parent 93615cb commit 84d060e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SFProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
22
import { TranslateSource } from 'realtime-server/lib/esm/scriptureforge/models/translate-config';
33
import language_code_mapping from '../../../../../language_code_mapping.json';
4+
import { hasArrayProp } from '../../../type-utils';
45
import { SelectableProjectWithLanguageCode } from '../../core/paratext.service';
56

67
/** Represents draft sources as a set of two {@link TranslateSource} arrays, and one {@link SFProjectProfile} array. */
@@ -70,6 +71,16 @@ export function projectToDraftSources(project: SFProjectProfile): DraftSourcesAs
7071
const draftingSources: TranslateSource[] & ({ length: 0 } | { length: 1 }) = [];
7172
const trainingTargets: [SFProjectProfile] = [project];
7273
const draftConfig = project.translateConfig.draftConfig;
74+
// Forward compatibility with the upcoming SF-3163 change to allow draft sources as arrays
75+
if (
76+
hasArrayProp(project.translateConfig.draftConfig, 'trainingSources') &&
77+
hasArrayProp(project.translateConfig.draftConfig, 'draftingSources')
78+
) {
79+
const trainingSources: TranslateSource[] = [...project.translateConfig.draftConfig.trainingSources] as any[];
80+
const draftingSources: TranslateSource[] = [...project.translateConfig.draftConfig.draftingSources] as any[];
81+
const trainingTargets: SFProjectProfile[] = [project];
82+
return { trainingSources, trainingTargets, draftingSources };
83+
}
7384
let trainingSource: TranslateSource | undefined;
7485
if (draftConfig.alternateTrainingSourceEnabled && draftConfig.alternateTrainingSource != null) {
7586
trainingSource = draftConfig.alternateTrainingSource;

src/SIL.XForge.Scripture/ClientApp/src/type-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export function hasProp<X, Y extends PropertyKey>(value: X, property: Y): value
2424
return (isObj(value) || isFn(value)) && property in value;
2525
}
2626

27+
export function hasArrayProp<X, Y extends PropertyKey>(value: X, property: Y): value is X & Record<Y, unknown[]> {
28+
return hasProp(value, property) && Array.isArray(value[property]);
29+
}
30+
2731
export function hasStringProp<X, Y extends PropertyKey>(value: X, property: Y): value is X & Record<Y, string> {
2832
return hasProp(value, property) && typeof value[property] === 'string';
2933
}

0 commit comments

Comments
 (0)