-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename formatRunTimeParameterDefaultValue
- Loading branch information
Showing
9 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
shared-data/js/helpers/formatRunTimeParameterDefaultValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { RunTimeParameter } from '../types' | ||
|
||
export const formatRunTimeParameterDefaultValue = ( | ||
runTimeParameter: RunTimeParameter, | ||
t?: any | ||
): string => { | ||
const { type, default: defaultValue } = runTimeParameter | ||
const suffix = | ||
'suffix' in runTimeParameter && runTimeParameter.suffix != null | ||
? runTimeParameter.suffix | ||
: null | ||
switch (type) { | ||
case 'int': | ||
case 'float': | ||
return suffix !== null | ||
? `${defaultValue.toString()} ${suffix}` | ||
: defaultValue.toString() | ||
case 'boolean': | ||
if (t != null) { | ||
return Boolean(defaultValue) ? t('on') : t('off') | ||
} else { | ||
return Boolean(defaultValue) ? 'On' : 'Off' | ||
} | ||
case 'str': | ||
if ('choices' in runTimeParameter && runTimeParameter.choices != null) { | ||
const choice = runTimeParameter.choices.find( | ||
choice => choice.value === defaultValue | ||
) | ||
if (choice != null) { | ||
return choice.displayName | ||
} | ||
} | ||
break | ||
} | ||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters