11import React , { ReactElement , useEffect , useState } from 'react' ;
22import { Chip , ButtonGroup , Select , MenuItem , FormControl , Box , Badge , Tooltip } from '@mui/material' ;
33import { PlayArrow , Stop } from '@mui/icons-material' ;
4- import { isALocalStackContainer , useDDClient , useLocalStack , useMountPoint , useRunConfig } from '../../services' ;
4+ import {
5+ isALocalStackContainer ,
6+ removeTagFromImage ,
7+ useDDClient ,
8+ useLocalStack ,
9+ useMountPoint ,
10+ useRunConfigs ,
11+ } from '../../services' ;
512import {
613 DEFAULT_CONFIGURATION_ID ,
714 CORS_ALLOW_DEFAULT ,
8- LATEST_IMAGE ,
915 START_ARGS ,
1016 FLAGS ,
17+ IMAGE ,
18+ PRO_IMAGE ,
1119} from '../../constants' ;
1220import { LongMenu } from './Menu' ;
1321import { DockerContainer , DockerImage } from '../../types' ;
@@ -17,11 +25,11 @@ import { ProgressButton } from '../Feedback';
1725const EXCLUDED_ERROR_TOAST = [ 'INFO' , 'WARN' , 'DEBUG' ] ;
1826
1927export const Controller = ( ) : ReactElement => {
20- const { runConfig , isLoading, createConfig } = useRunConfig ( ) ;
28+ const { runConfigs , isLoading, createConfig } = useRunConfigs ( ) ;
2129 const { data, mutate } = useLocalStack ( ) ;
2230 const { user, os, hasSkippedConfiguration } = useMountPoint ( ) ;
2331 const [ runningConfig , setRunningConfig ] = useState < string > ( 'Default' ) ;
24- const [ downloadProps , setDownloadProps ] = useState ( { open : false , image : LATEST_IMAGE } ) ;
32+ const [ downloadProps , setDownloadProps ] = useState ( { open : false , image : IMAGE } ) ;
2533 const [ isStarting , setIsStarting ] = useState < boolean > ( false ) ;
2634 const [ isStopping , setIsStopping ] = useState < boolean > ( false ) ;
2735 const ddClient = useDDClient ( ) ;
@@ -30,7 +38,7 @@ export const Controller = (): ReactElement => {
3038 const tooltipLabel = isUnhealthy ? 'Unhealthy' : 'Healthy' ;
3139
3240 useEffect ( ( ) => {
33- if ( ! isLoading && ( ! runConfig || ! runConfig . find ( item => item . name === 'Default' ) ) ) {
41+ if ( ! isLoading && ( ! runConfigs || ! runConfigs . find ( item => item . name === 'Default' ) ) ) {
3442 createConfig ( {
3543 name : 'Default' , id : DEFAULT_CONFIGURATION_ID , vars : [ ] ,
3644 } ,
@@ -61,7 +69,7 @@ export const Controller = (): ReactElement => {
6169
6270 const corsArg = [ '-e' , `EXTRA_CORS_ALLOWED_ORIGINS=${ CORS_ALLOW_DEFAULT } ` ] ;
6371
64- const addedArgs = runConfig . find ( config => config . name === runningConfig )
72+ const addedArgs = runConfigs . find ( config => config . name === runningConfig )
6573 . vars . map ( item => {
6674 if ( item . variable === 'EXTRA_CORS_ALLOWED_ORIGINS' ) { // prevent overriding variable
6775 corsArg . slice ( 0 , 0 ) ;
@@ -79,10 +87,15 @@ export const Controller = (): ReactElement => {
7987
8088 const start = async ( ) => {
8189 const images = await ddClient . docker . listImages ( ) as [ DockerImage ] ;
82- const haveLocally = images . some ( image => image . RepoTags ?. at ( 0 ) === LATEST_IMAGE ) ;
90+
91+ const isPro = runConfigs . find ( config => config . name === runningConfig )
92+ . vars . some ( item => item . variable === 'LOCALSTACK_API_KEY' ) ;
93+
94+ const imageToUse = isPro ? PRO_IMAGE : IMAGE ;
95+ const haveLocally = images . some ( image => removeTagFromImage ( image ) === imageToUse ) ;
8396
8497 if ( ! haveLocally ) {
85- setDownloadProps ( { open : true , image : LATEST_IMAGE } ) ;
98+ setDownloadProps ( { open : true , image : imageToUse } ) ;
8699 return ;
87100 }
88101 const args = await normalizeArguments ( ) ;
@@ -164,7 +177,7 @@ export const Controller = (): ReactElement => {
164177 onChange = { ( { target } ) => setRunningConfig ( target . value ) }
165178 >
166179 {
167- runConfig ?. map ( config => (
180+ runConfigs ?. map ( config => (
168181 < MenuItem key = { config . id } value = { config . name } > { config . name } </ MenuItem >
169182 ) )
170183 }
0 commit comments