diff --git a/server/zanata-frontend/src/app/components/DraggableVersionPanels/index.tsx b/server/zanata-frontend/src/app/components/DraggableVersionPanels/index.tsx index af1d0ca9eb6..f2aa87b8528 100644 --- a/server/zanata-frontend/src/app/components/DraggableVersionPanels/index.tsx +++ b/server/zanata-frontend/src/app/components/DraggableVersionPanels/index.tsx @@ -2,7 +2,8 @@ import * as PropTypes from 'prop-types' import React, { ClassAttributes, ReactElement, StatelessComponent } from 'react' import { Component } from 'react' import {Icon, LockIcon} from '../../components' -import {FromProjectVersionType} from '../../utils/prop-types-util' +import { FromProjectVersion, FromProjectVersionType +} from '../../utils/prop-types-util' import { SortableContainer, SortableElement, @@ -62,18 +63,6 @@ export class Item extends Component { const SortableItem = SortableElement(Item as any) as any -type EntityStatus = 'READONLY' | 'ACTIVE' | 'OBSOLETE' - -interface VersionDto { - id: string - status: EntityStatus -} - -interface FromProjectVersion { - projectSlug: string, - version: VersionDto -} - interface ItemsProps { items: FromProjectVersion[] removeVersion: (...args: any[]) => any diff --git a/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeModal.js b/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeModal.js index c525eaa9167..fa4d721156e 100644 --- a/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeModal.js +++ b/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeModal.js @@ -21,7 +21,7 @@ import { } from '../../actions/version-actions' import { ProjectType, LocaleType, FromProjectVersionType, processStatusType -} from '../../utils/prop-types-util.js' +} from '../../utils/prop-types-util' import {isProcessEnded, IGNORE_CHECK, FUZZY} from '../../utils/EnumValueUtils' import {getVersionLanguageSettingsUrl} from '../../utils/UrlHelper' import { diff --git a/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeProjectSources.js b/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeProjectSources.js index da4e3eb2bb2..e810e2a15ea 100644 --- a/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeProjectSources.js +++ b/server/zanata-frontend/src/app/containers/ProjectVersion/TMMergeProjectSources.js @@ -12,7 +12,7 @@ import Toggle from 'react-toggle' import { ProjectType, FromProjectVersionType -} from '../../utils/prop-types-util.js' +} from '../../utils/prop-types-util' const DO_NOT_RENDER = undefined const ALL = 'ALL' diff --git a/server/zanata-frontend/src/app/utils/EnumValueUtils.js b/server/zanata-frontend/src/app/utils/EnumValueUtils.ts similarity index 53% rename from server/zanata-frontend/src/app/utils/EnumValueUtils.js rename to server/zanata-frontend/src/app/utils/EnumValueUtils.ts index 4d91106b713..6b13290cff7 100644 --- a/server/zanata-frontend/src/app/utils/EnumValueUtils.js +++ b/server/zanata-frontend/src/app/utils/EnumValueUtils.ts @@ -1,3 +1,4 @@ +import { tuple } from './tuple' export const processStatusCodes = [ 'NotAccepted', 'Waiting', 'Running', 'Finished', 'Cancelled', 'Failed'] @@ -7,27 +8,30 @@ const isStatusCodeEnded = statusCode => { statusCode === 'Failed' } /** - * @param {{statusCode: string}} processStatus - * @returns {boolean} whether a process status represents an ended process + * @returns whether a process status represents an ended process */ -export function isProcessEnded (processStatus) { +export function isProcessEnded (processStatus: {statusCode: string}) { return processStatus && isStatusCodeEnded(processStatus.statusCode) } -export const entityStatuses = ['READONLY', 'ACTIVE', 'OBSOLETE'] +export const entityStatuses = tuple('READONLY', 'ACTIVE', 'OBSOLETE') +export type EntityStatus = typeof entityStatuses[number] + export function isEntityStatusReadOnly (status) { return status === 'READONLY' } -export const internalTMChoice = ['SelectNone', 'SelectAny', 'SelectSome'] +export const internalTMChoice = tuple('SelectNone', 'SelectAny', 'SelectSome') +export type InternalTMChoice = typeof internalTMChoice[number] /** - * - * @param {boolean} isFromAllProjects if we want to search TM from all projects - * @param {Array.} fromVersions - * @returns {*} + * @param isFromAllProjects if we want to search TM from all projects + * @param fromVersions */ -export function toInternalTMSource (isFromAllProjects, fromVersions) { +export function toInternalTMSource (isFromAllProjects: boolean, fromVersions: string[]): { + choice: InternalTMChoice; + projectIterationIds?: string[]; +} { if (isFromAllProjects) { return { choice: 'SelectAny' diff --git a/server/zanata-frontend/src/app/utils/prop-types-util.js b/server/zanata-frontend/src/app/utils/prop-types-util.ts similarity index 77% rename from server/zanata-frontend/src/app/utils/prop-types-util.js rename to server/zanata-frontend/src/app/utils/prop-types-util.ts index b28eaa31f05..c84627f2608 100644 --- a/server/zanata-frontend/src/app/utils/prop-types-util.js +++ b/server/zanata-frontend/src/app/utils/prop-types-util.ts @@ -1,5 +1,5 @@ import * as PropTypes from 'prop-types' -import {processStatusCodes, entityStatuses} from './EnumValueUtils' +import {processStatusCodes, entityStatuses, EntityStatus} from './EnumValueUtils' export const entityStatusPropType = PropTypes.oneOf(entityStatuses) @@ -8,6 +8,12 @@ export const versionDtoPropType = PropTypes.shape({ status: entityStatusPropType }) +export interface VersionDto { + id: string, + // TODO does entityStatusPropType implicitly have isRequired? + status?: EntityStatus, +} + export const ProjectType = PropTypes.shape({ id: PropTypes.string.isRequired, status: PropTypes.string.isRequired, @@ -26,6 +32,11 @@ export const FromProjectVersionType = PropTypes.shape({ version: versionDtoPropType.isRequired }) +export interface FromProjectVersion { + projectSlug: string, + version: VersionDto +} + export const processStatusCodeType = PropTypes.oneOf(processStatusCodes) export const processStatusType = PropTypes.shape({ diff --git a/server/zanata-frontend/src/app/utils/tuple.ts b/server/zanata-frontend/src/app/utils/tuple.ts new file mode 100644 index 00000000000..8b8202afa20 --- /dev/null +++ b/server/zanata-frontend/src/app/utils/tuple.ts @@ -0,0 +1,23 @@ +/* tslint:disable:max-line-length */ + +// TypeScript wizardry thanks to jcalz: +// https://stackoverflow.com/a/45486495/14379 +// https://gist.github.com/jcalz/381562d282ebaa9b41217d1b31e2c211 +export type Lit = string | number | boolean | undefined | null | void | {}; + +// infers a tuple type for up to twelve values (add more here if you need them) +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J, k: K, l: L): [A, B, C, D, E, F, G, H, I, J, K, L]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J, k: K): [A, B, C, D, E, F, G, H, I, J, K]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J): [A, B, C, D, E, F, G, H, I, J]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I): [A, B, C, D, E, F, G, H, I]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): [A, B, C, D, E, F, G, H]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F, g: G): [A, B, C, D, E, F, G]; +export function tuple(a: A, b: B, c: C, d: D, e: E, f: F): [A, B, C, D, E, F]; +export function tuple(a: A, b: B, c: C, d: D, e: E): [A, B, C, D, E]; +export function tuple(a: A, b: B, c: C, d: D): [A, B, C, D]; +export function tuple(a: A, b: B, c: C): [A, B, C]; +export function tuple(a: A, b: B): [A, B]; +export function tuple(a: A): [A]; +export function tuple(...args: any[]): any[] { + return args; +}