Skip to content
Merged
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
36 changes: 17 additions & 19 deletions src/renderer/src/components/Transcriber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ import {
pullTableList,
orgDefaultFeatures,
useOrganizedBy,
useProjectType,
isNoParatextWorkflow,
nextTranscriptionState,
resolvedProjectType,
} from '../crud';
import { MainAPI } from '@model/main-api';
import { useGetAsrSettings } from '../crud/useGetAsrSettings';
Expand Down Expand Up @@ -260,6 +264,7 @@ export function Transcriber(props: IProps) {
const [offlineOnly] = useGlobal('offlineOnly'); //will be constant here
const [project] = useGlobal('project'); //will be constant here
const [projType] = useGlobal('projType'); //verified this is not used in a function 2/18/25
const { getProjType } = useProjectType();
const [user] = useGlobal('user');
const [organization] = useGlobal('organization');
const [coordinator] = useGlobal('coordinator');
Expand Down Expand Up @@ -759,10 +764,12 @@ export function Transcriber(props: IProps) {

loadProjData();

const ptCheck =
[ArtifactTypeSlug.Retell, ArtifactTypeSlug.QandA].includes(
(artifactTypeSlug || '') as ArtifactTypeSlug
) || projType.toLowerCase() !== 'scripture';
const projRec = findRecord(memory, 'project', project) as
| Project
| undefined;
const recordType = projRec ? getProjType(project) : '';
const resolvedType = resolvedProjectType(projType, recordType);
const ptCheck = isNoParatextWorkflow(resolvedType, artifactTypeSlug);
if (ptCheck !== noParatext) setNoParatext(ptCheck);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [
Expand Down Expand Up @@ -897,28 +904,19 @@ export function Transcriber(props: IProps) {
);
const handleAddNoteCancel = () => setAddNoteVisible(false);

const next: { [key: string]: string } = {
incomplete: ActivityStates.Transcribed,
transcribing: ActivityStates.Transcribed,
reviewing: ActivityStates.Approved,
transcribeReady: ActivityStates.Transcribed,
transcribed: ActivityStates.Approved,
needsNewTranscription: ActivityStates.Transcribed,
};

const forcePosition = (position: number) => {
setDefaultPosition(playedSecsRef.current || 0);
setDefaultPosition(position);
};

const handleSubmit = useCallback(
async () => {
if (Object.prototype.hasOwnProperty.call(next, state)) {
let nextState = next[state];
if (nextState === ActivityStates.Transcribed && !hasChecking)
nextState = ActivityStates.Approved;
if (nextState === ActivityStates.Approved && noParatext)
nextState = ActivityStates.Done;
const nextState = nextTranscriptionState({
state,
hasChecking: !!hasChecking,
noParatext,
});
if (nextState) {
await save(
nextState || ActivityStates.TranscribeReady,
0,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/crud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from './useMediaCounts';
export * from './useSectionCounts';
export * from './useAddToOrgAndGroup';
export * from './useProjectType';
export * from './nextTranscriptionState';
export * from './useFetchMediaUrl';
export * from './useAudacityProjCreate';
export * from './useAudacityProjRead';
Expand Down
65 changes: 65 additions & 0 deletions src/renderer/src/crud/nextTranscriptionState.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ActivityStates } from '../model/activityStates';
import { ArtifactTypeSlug } from './artifactTypeSlug';
import {
isNoParatextWorkflow,
nextTranscriptionState,
resolvedProjectType,
} from './nextTranscriptionState';

describe('nextTranscriptionState', () => {
it('moves reviewing to approved when Paratext workflow applies', () => {
expect(
nextTranscriptionState({
state: ActivityStates.Reviewing,
hasChecking: true,
noParatext: false,
})
).toBe(ActivityStates.Approved);
});

it('moves reviewing to done when noParatext', () => {
expect(
nextTranscriptionState({
state: ActivityStates.Reviewing,
hasChecking: true,
noParatext: true,
})
).toBe(ActivityStates.Done);
});

it('skips transcribed when there is no checking step', () => {
expect(
nextTranscriptionState({
state: ActivityStates.Transcribing,
hasChecking: false,
noParatext: false,
})
).toBe(ActivityStates.Approved);
});
});

describe('resolvedProjectType (TT-5244)', () => {
it('uses the Scripture project record when the global type is empty', () => {
expect(resolvedProjectType('', 'Scripture')).toBe('Scripture');
});

it('uses the Scripture project record when the global type is stale', () => {
expect(resolvedProjectType('generic', 'Scripture')).toBe('Scripture');
});
});

describe('isNoParatextWorkflow', () => {
it('is false for Scripture', () => {
expect(isNoParatextWorkflow('Scripture')).toBe(false);
});

it('is true for empty type', () => {
expect(isNoParatextWorkflow('')).toBe(true);
});

it('is true for Retell artifacts even in a Scripture project', () => {
expect(isNoParatextWorkflow('Scripture', ArtifactTypeSlug.Retell)).toBe(
true
);
});
});
50 changes: 50 additions & 0 deletions src/renderer/src/crud/nextTranscriptionState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ActivityStates } from '../model/activityStates';
import { ArtifactTypeSlug } from './artifactTypeSlug';

const nextByState: { [key: string]: string } = {
[ActivityStates.Incomplete]: ActivityStates.Transcribed,
[ActivityStates.Transcribing]: ActivityStates.Transcribed,
[ActivityStates.Reviewing]: ActivityStates.Approved,
[ActivityStates.TranscribeReady]: ActivityStates.Transcribed,
[ActivityStates.Transcribed]: ActivityStates.Approved,
[ActivityStates.NeedsNewTranscription]: ActivityStates.Transcribed,
};
Comment thread
Copilot marked this conversation as resolved.

/** Prefer the project record type when the global is empty or stale. */
export function resolvedProjectType(
globalProjType?: string,
recordProjType?: string
): string {
const record = (recordProjType ?? '').trim();
if (record) return record;
return globalProjType ?? '';
}

export function isNoParatextWorkflow(
projType?: string,
artifactTypeSlug?: string
): boolean {
return (
[ArtifactTypeSlug.Retell, ArtifactTypeSlug.QandA].includes(
(artifactTypeSlug || '') as ArtifactTypeSlug
) || (projType || '').toLowerCase() !== 'scripture'
);
}

export function nextTranscriptionState(opts: {
state: string;
hasChecking: boolean;
noParatext: boolean;
}): string | undefined {
if (!Object.prototype.hasOwnProperty.call(nextByState, opts.state)) {
return undefined;
}
let nextState = nextByState[opts.state];
if (nextState === ActivityStates.Transcribed && !opts.hasChecking) {
nextState = ActivityStates.Approved;
}
if (nextState === ActivityStates.Approved && opts.noParatext) {
nextState = ActivityStates.Done;
}
return nextState;
}
4 changes: 2 additions & 2 deletions src/renderer/src/routes/PassageDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export const PassageDetail = () => {

useEffect(() => {
const projectId = setUrlContext(prjId ?? '');
if (user && projType === '') {
if (user) {
const tmp = setProjectType(projectId);
if (!tmp) {
if (projType === '' && !tmp) {
// If user is set but we don't have this project, go to the team screen
setView('/team');
}
Expand Down
Loading