generated from graasp/graasp-app-starter-ts-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
219,172 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
29 changes: 28 additions & 1 deletion
29
src/modules/scenes/SimulationControlPanel/SimulationControlPanel.tsx
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
63 changes: 63 additions & 0 deletions
63
src/modules/scenes/SimulationControlPanel/SimulationDurationControl.tsx
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,63 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { FormControl, InputLabel, MenuItem, Select } from '@mui/material'; | ||
|
||
import { SIMULATION_CSV_FILES } from '@/config/simulation'; | ||
import { useSimulation } from '@/context/SimulationContext'; | ||
import { SimulationStatus } from '@/types/simulation'; | ||
import { TimeUnit } from '@/types/time'; | ||
|
||
const OPTIONS = Object.keys(SIMULATION_CSV_FILES); | ||
|
||
export const SimulationDurationControl = (): JSX.Element => { | ||
const { t } = useTranslation('SIMULATION_CONTROL_PANEL', { | ||
keyPrefix: 'DURATION_CONTROL_PANEL', | ||
}); | ||
|
||
const { t: tDates } = useTranslation('DATES'); | ||
|
||
const { duration, updateSimulationDuration, status } = useSimulation(); | ||
|
||
const selectIsDisabled = | ||
status === SimulationStatus.LOADING || status === SimulationStatus.RUNNING; | ||
|
||
const handleChange = (newDuration: string | number): void => { | ||
if (selectIsDisabled) { | ||
return; | ||
} | ||
|
||
const value = | ||
typeof newDuration === 'number' | ||
? newDuration | ||
: Number.parseInt(newDuration, 10); | ||
|
||
if (!Number.isNaN(value)) { | ||
updateSimulationDuration({ value, unit: TimeUnit.Years }); | ||
} else { | ||
console.error(`The duration ${newDuration} is not a valid number!`); | ||
} | ||
}; | ||
|
||
return ( | ||
<FormControl fullWidth> | ||
<InputLabel id="house-duration-select-label">{t('LABEL')}</InputLabel> | ||
<Select | ||
labelId="house-duration-select-label" | ||
id="house-duration-select" | ||
label={t('LABEL')} | ||
value={duration.value} | ||
onChange={(e) => handleChange(e.target.value)} | ||
type="number" | ||
disabled={selectIsDisabled} | ||
> | ||
{OPTIONS.map((years) => ( | ||
<MenuItem key={years} value={years}> | ||
{tDates('YEARS', { | ||
count: Number.parseInt(years, 10), | ||
})} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import test, { expect } from '@playwright/test'; | ||
|
||
import { HousePage } from './HousePage'; | ||
|
||
test('simulation duration should be disabled when simulation is running', async ({ | ||
page, | ||
}) => { | ||
const housePage = new HousePage(page); | ||
await housePage.goto(); | ||
await housePage.setSimulationDuration(25); | ||
await housePage.simulationControlButton.click(); | ||
await expect(housePage.simulationDuration).toBeDisabled(); | ||
}); |