chore(client): tsmigrate getTargetEditor.js (#45090)
This commit is contained in:
@ -9,7 +9,7 @@ import {
|
|||||||
consoleOutputSelector,
|
consoleOutputSelector,
|
||||||
visibleEditorsSelector
|
visibleEditorsSelector
|
||||||
} from '../redux';
|
} from '../redux';
|
||||||
import { getTargetEditor } from '../utils/getTargetEditor';
|
import { getTargetEditor } from '../utils/get-target-editor';
|
||||||
import './editor.css';
|
import './editor.css';
|
||||||
import Editor from './editor';
|
import Editor from './editor';
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { createAction, handleActions } from 'redux-actions';
|
|||||||
import { getLines } from '../../../../../utils/get-lines';
|
import { getLines } from '../../../../../utils/get-lines';
|
||||||
import { challengeTypes } from '../../../../utils/challenge-types';
|
import { challengeTypes } from '../../../../utils/challenge-types';
|
||||||
import { completedChallengesSelector } from '../../../redux';
|
import { completedChallengesSelector } from '../../../redux';
|
||||||
import { getTargetEditor } from '../utils/getTargetEditor';
|
import { getTargetEditor } from '../utils/get-target-editor';
|
||||||
import { actionTypes, ns } from './action-types';
|
import { actionTypes, ns } from './action-types';
|
||||||
import codeLockEpic from './code-lock-epic';
|
import codeLockEpic from './code-lock-epic';
|
||||||
import codeStorageEpic from './code-storage-epic';
|
import codeStorageEpic from './code-storage-epic';
|
||||||
|
17
client/src/templates/Challenges/utils/get-target-editor.ts
Normal file
17
client/src/templates/Challenges/utils/get-target-editor.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { isEmpty } from 'lodash-es';
|
||||||
|
import { sortChallengeFiles } from '../../../../../utils/sort-challengefiles';
|
||||||
|
import { ChallengeFiles, FileKey } from '../../../redux/prop-types';
|
||||||
|
|
||||||
|
export function getTargetEditor(
|
||||||
|
challengeFiles: ChallengeFiles
|
||||||
|
): FileKey | null {
|
||||||
|
if (isEmpty(challengeFiles)) return null;
|
||||||
|
|
||||||
|
const targetEditor = challengeFiles?.find(
|
||||||
|
({ editableRegionBoundaries }) => !isEmpty(editableRegionBoundaries)
|
||||||
|
)?.fileKey;
|
||||||
|
|
||||||
|
// fallback for when there is no editable region.
|
||||||
|
/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
||||||
|
return targetEditor || sortChallengeFiles(challengeFiles)[0].fileKey;
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
import { isEmpty } from 'lodash-es';
|
|
||||||
import { sortChallengeFiles } from '../../../../../utils/sort-challengefiles';
|
|
||||||
|
|
||||||
export function getTargetEditor(challengeFiles) {
|
|
||||||
if (isEmpty(challengeFiles)) return null;
|
|
||||||
else {
|
|
||||||
let targetEditor = challengeFiles.find(
|
|
||||||
({ editableRegionBoundaries }) => !isEmpty(editableRegionBoundaries)
|
|
||||||
)?.fileKey;
|
|
||||||
|
|
||||||
// fallback for when there is no editable region.
|
|
||||||
return targetEditor || sortChallengeFiles(challengeFiles)[0].fileKey;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user