Skip to content

Commit

Permalink
Merge branch 'development' of github.com:hotosm/fmtm into search-proj…
Browse files Browse the repository at this point in the history
…ects
  • Loading branch information
sujanadh committed Nov 21, 2023
2 parents a9868df + f73c972 commit 15cf2a3
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:

# Lint / autoformat: Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.5"
rev: "v0.1.6"
hooks:
- id: ruff
files: ^src/backend/(?:.*/)*.*$
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ services:
- "5434:5432"
networks:
- fmtm-net
restart: "on-failure:3"
restart: "unless-stopped"
healthcheck:
test: pg_isready -U ${CENTRAL_DB_USER} -d ${CENTRAL_DB_NAME}
start_period: 5s
Expand Down
Binary file modified src/frontend/src/assets/images/something_went_wrong.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
269 changes: 151 additions & 118 deletions src/frontend/src/components/GenerateBasemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI
const [selectedTileSource, setSelectedTileSource] = useState(null);
const [selectedOutputFormat, setSelectedOutputFormat] = useState(null);
const [tmsUrl, setTmsUrl] = useState('');
const [error, setError] = useState([]);

const modalStyle = (theme) => ({
width: '90vw', // Responsive modal width using vw
Expand Down Expand Up @@ -51,6 +52,35 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI
setTmsUrl(e.target.value);
};

const generateProjectTilesValidation = () => {
const currentError = [];
if (!selectedTileSource) {
currentError.push('selectedTileSource');
}
if (!selectedOutputFormat) {
currentError.push('selectedOutputFormat');
}
if (!tmsUrl && selectedTileSource === 'tms') {
currentError.push('tmsUrl');
}
setError(currentError);
return currentError;
};

const generateProjectTiles = () => {
const currentErrors = generateProjectTilesValidation();
if (currentErrors.length === 0) {
dispatch(
GenerateProjectTiles(
`${
import.meta.env.VITE_API_URL
}/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`,
decodedId,
),
);
}
};

return (
<CoreModules.CustomizedModal
isOpen={!!toggleGenerateModal}
Expand All @@ -69,137 +99,140 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI
</CoreModules.IconButton>
</CoreModules.Grid>

{/* Output Format Dropdown */}
<CoreModules.Grid item xs={12} sm={6}>
<CoreModules.FormControl fullWidth>
<CoreModules.InputLabel
id="output-format"
sx={{
'&.Mui-focused': {
color: defaultTheme.palette.black,
},
}}
>
Select Output Format
</CoreModules.InputLabel>
<CoreModules.Select
labelId="output-format"
id="output_format"
value={selectedOutputFormat}
label="Form Selection"
fullWidth
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
border: '2px solid black',
},
}}
onChange={(e) => {
setSelectedOutputFormat(e.target.value);
}}
>
{environment.tileOutputFormats?.map((form) => (
<CoreModules.MenuItem key={form.value} value={form.value}>
{form.label}
</CoreModules.MenuItem>
))}
</CoreModules.Select>
</CoreModules.FormControl>
</CoreModules.Grid>
<CoreModules.Grid container spacing={2} className="fmtm-px-4 fmtm-mb-4">
{/* Output Format Dropdown */}
<CoreModules.Grid item xs={12} sm={6} md={4}>
<CoreModules.FormControl fullWidth>
<CoreModules.InputLabel
id="output-format"
sx={{
'&.Mui-focused': {
color: defaultTheme.palette.black,
},
}}
>
Select Output Format
</CoreModules.InputLabel>
<CoreModules.Select
labelId="output-format"
id="output_format"
value={selectedOutputFormat}
label="Select Output Format"
fullWidth
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
border: '2px solid black',
},
}}
onChange={(e) => {
setSelectedOutputFormat(e.target.value);
}}
>
{environment.tileOutputFormats?.map((form) => (
<CoreModules.MenuItem key={form.value} value={form.value}>
{form.label}
</CoreModules.MenuItem>
))}
</CoreModules.Select>
</CoreModules.FormControl>
{error.includes('selectedOutputFormat') && (
<p className="fmtm-text-sm fmtm-text-red-500">Output Format is Required.</p>
)}
</CoreModules.Grid>

{/* Tile Source Dropdown or TMS URL Input */}
<CoreModules.Grid item xs={12} sm={6}>
<CoreModules.FormControl fullWidth>
<CoreModules.InputLabel
id="tile-source"
sx={{
'&.Mui-focused': {
color: defaultTheme.palette.black,
},
}}
>
Select Tile Source
</CoreModules.InputLabel>
<CoreModules.Select
labelId="tile-source"
id="tile_source"
value={selectedTileSource}
label="Form Selection"
fullWidth
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
border: '2px solid black',
},
}}
onChange={handleTileSourceChange}
>
{environment.baseMapProviders?.map((form) => (
<CoreModules.MenuItem key={form.value} value={form.value}>
{form.label}
</CoreModules.MenuItem>
))}
</CoreModules.Select>
{selectedTileSource === 'tms' && (
<CoreModules.FormControl>
{/* Tile Source Dropdown or TMS URL Input */}
<CoreModules.Grid item xs={12} sm={6} md={4}>
<CoreModules.FormControl fullWidth>
<CoreModules.InputLabel
id="tile-source"
sx={{
'&.Mui-focused': {
color: defaultTheme.palette.black,
},
}}
>
Select Tile Source
</CoreModules.InputLabel>
<CoreModules.Select
labelId="tile-source"
id="tile_source"
value={selectedTileSource}
label="Select Tile Source"
fullWidth
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
border: '2px solid black',
},
}}
onChange={handleTileSourceChange}
>
{environment.baseMapProviders?.map((form) => (
<CoreModules.MenuItem key={form.value} value={form.value}>
{form.label}
</CoreModules.MenuItem>
))}
</CoreModules.Select>
</CoreModules.FormControl>
{error.includes('selectedTileSource') && (
<p className="fmtm-text-sm fmtm-text-red-500">Tile Source is Required.</p>
)}
</CoreModules.Grid>
{selectedTileSource === 'tms' && (
<CoreModules.Grid item xs={12} sm={12} md={4}>
<CoreModules.FormControl fullWidth>
<CoreModules.TextField
labelId="tms_url-label"
// labelId="tms_url-label"
id="tms_url"
variant="outlined"
value={tmsUrl}
label="Enter Tile Source"
fullWidth
color="black"
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
border: '2px solid black',
'& .MuiOutlinedInput-root': {
'&.Mui-focused fieldset': {
borderColor: 'black',
},
},
'&.Mui-focused .MuiFormLabel-root-MuiInputLabel-root': {
color: 'black',
},
}}
onChange={handleTmsUrlChange}
/>
</CoreModules.FormControl>
)}
</CoreModules.FormControl>
</CoreModules.Grid>

{/* Generate Button */}
<CoreModules.Grid item xs={12} sm={6}>
<CoreModules.LoadingButton
variant="contained"
loading={generateProjectTilesLoading}
color="error"
fullWidth
onClick={() => {
// Check if 'tms' is selected and tmsUrl is not empty
if (selectedTileSource === 'tms' && !tmsUrl) {
// Handle error, TMS URL is required
console.log('TMS URL is required');
return;
}
{error.includes('tmsUrl') && <p className="fmtm-text-sm fmtm-text-red-500">Tile Source is Required.</p>}
</CoreModules.Grid>
)}
<CoreModules.Grid item xs={12} sm={12} md={selectedTileSource === 'tms' ? 12 : 4}>
<div className="fmtm-w-full fmtm-flex fmtm-items-center fmtm-justify-center sm:fmtm-justify-end fmtm-mr-4 fmtm-gap-4 fmtm-h-full">
{/* Generate Button */}
<div>
<CoreModules.LoadingButton
variant="contained"
loading={generateProjectTilesLoading}
color="error"
onClick={() => generateProjectTiles()}
>
Generate
</CoreModules.LoadingButton>
</div>

dispatch(
GenerateProjectTiles(
`${
import.meta.env.VITE_API_URL
}/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`,
decodedId,
),
);
}}
>
Generate
</CoreModules.LoadingButton>
</CoreModules.Grid>

{/* Refresh Button */}
<CoreModules.Grid item xs={12} sm={6}>
<CoreModules.LoadingButton
variant="outlined"
loading={generateProjectTilesLoading}
color="error"
fullWidth
onClick={() => {
getTilesList();
}}
>
Refresh
</CoreModules.LoadingButton>
{/* Refresh Button */}
<div>
<CoreModules.LoadingButton
variant="outlined"
loading={generateProjectTilesLoading}
color="error"
onClick={() => {
getTilesList();
}}
>
Refresh
</CoreModules.LoadingButton>
</div>
</div>
</CoreModules.Grid>
</CoreModules.Grid>

{/* Table Content */}
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/components/common/StepSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CommonActions } from '../../store/slices/CommonSlice';
import CoreModules from '../../shared/CoreModules.js';
import { useNavigate } from 'react-router-dom';

const StepSwitcher = ({ data, flag }) => {
const StepSwitcher = ({ data, flag, switchSteps }) => {
interface IIndividualStep {
url: string;
step: number;
Expand Down Expand Up @@ -39,7 +39,11 @@ const StepSwitcher = ({ data, flag }) => {
} lg:fmtm-w-7 lg:fmtm-h-7 xl:fmtm-w-9 xl:fmtm-h-9 fmtm-rounded-full fmtm-flex fmtm-justify-center fmtm-items-center fmtm-border-[0.15rem] fmtm-border-primaryRed hover:fmtm-cursor-pointer ${
currentStep.step >= index ? 'fmtm-bg-primaryRed' : 'fmtm-bg-transparent'
}`}
onClick={() => toggleStep(step)}
onClick={() => {
if (switchSteps) {
toggleStep(step);
}
}}
>
<AssetModules.DoneIcon
className={`${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const DataExtract = ({ flag, customLineUpload, setCustomLineUpload, customPolygo
btnText="PREVIOUS"
btnType="secondary"
type="button"
onClick={() => toggleStep(2, '/upload-area')}
onClick={() => toggleStep(3, '/select-form')}
className="fmtm-font-bold"
/>
<Button btnText="NEXT" btnType="primary" type="submit" className="fmtm-font-bold" />
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/components/createnewproject/SplitTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
),
);
dispatch(CreateProjectActions.SetIndividualProjectDetailsData({ ...projectDetails, ...formValues }));
dispatch(CreateProjectActions.SetCanSwitchCreateProjectSteps(true));
};

useEffect(() => {
Expand Down Expand Up @@ -197,6 +198,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
dispatch(CreateProjectActions.SetGenerateProjectQRSuccess(null));
navigate(`/project_details/${encodedProjectId}`);
dispatch(CreateProjectActions.ClearCreateProjectFormData());
dispatch(CreateProjectActions.SetCanSwitchCreateProjectSteps(false));
}
if (generateQrSuccess && generateProjectLog?.status === 'PENDING') {
if (generateProjectLogIntervalCb === null) {
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/store/slices/CreateProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const initialState: CreateProjectStateTypes = {
lineGeojson: null,
createProjectValidations: {},
isUnsavedChanges: false,
canSwitchCreateProjectSteps: false,
};

const CreateProject = createSlice({
Expand Down Expand Up @@ -206,6 +207,9 @@ const CreateProject = createSlice({
SetIsUnsavedChanges(state, action) {
state.isUnsavedChanges = action.payload;
},
SetCanSwitchCreateProjectSteps(state, action) {
state.canSwitchCreateProjectSteps = action.payload;
},
},
});

Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/store/types/ICreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type CreateProjectStateTypes = {
lineGeojson: null;
createProjectValidations: {};
isUnsavedChanges: boolean;
canSwitchCreateProjectSteps: boolean;
};
export type ValidateCustomFormResponse = {
detail: { message: string; possible_reason: string };
Expand Down
Loading

0 comments on commit 15cf2a3

Please sign in to comment.