Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further upgrades from JavaScript to TypeScript #1746

Merged
merged 36 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2e6a6f1
fix(project): convert js to ts
NSUWAL123 Aug 7, 2024
f271f1f
fix(projectById): remove first argument from projectById action
NSUWAL123 Aug 7, 2024
279b955
fix(projectOptions): types add
NSUWAL123 Aug 7, 2024
a07b1c1
fix(project): ts types add to project services
NSUWAL123 Aug 7, 2024
3ee498e
fix(submissions): store filterType seperately
NSUWAL123 Aug 7, 2024
d051a93
feat(api): add ts types to remaining services
NSUWAL123 Aug 7, 2024
7be275c
fix(dropdown): props fix
NSUWAL123 Aug 7, 2024
224549e
fix(submissionsTable): customSelect value props ts error fix
NSUWAL123 Aug 7, 2024
b13560e
fix(tasks): unused component remove
NSUWAL123 Aug 8, 2024
7b05c39
fix(merge): merge conflict solve
NSUWAL123 Aug 8, 2024
126cbf7
fix(stepFormConstants): export interface
NSUWAL123 Aug 8, 2024
e6c9d5a
fix(stepSwitcher): add stepSwitcher props type
NSUWAL123 Aug 8, 2024
0f07577
fix(uploadArea): uploadArea prop type add
NSUWAL123 Aug 8, 2024
db161ac
fix(kebabMenu): direction type add to getPosition function
NSUWAL123 Aug 8, 2024
4135ac1
fix(fileInputComponent): prop type add
NSUWAL123 Aug 8, 2024
71f6382
fix(bottomSheet): prop type add
NSUWAL123 Aug 8, 2024
9b153db
fix(checkbox): ts error solve
NSUWAL123 Aug 8, 2024
498d4b2
fix(chips): prop type add
NSUWAL123 Aug 8, 2024
715c777
fix(barChart): prop type add
NSUWAL123 Aug 8, 2024
7ac1075
fix(lineChart): prop type add
NSUWAL123 Aug 8, 2024
435be02
fix(pieChart): prop type add
NSUWAL123 Aug 8, 2024
479b1cc
fix(toolbar): ts type add to function
NSUWAL123 Aug 8, 2024
f9917c0
fix(checkWGS84Projection): convert js to ts
NSUWAL123 Aug 8, 2024
d350c82
fix(compareUtils): convert js to ts
NSUWAL123 Aug 8, 2024
5855b2a
fix(getTaskStatusStyle): convert js to ts
NSUWAL123 Aug 8, 2024
fc495ad
fix(commonUtils): add ts types
NSUWAL123 Aug 8, 2024
fe92d2d
fix(filterParam): convert js to ts
NSUWAL123 Aug 8, 2024
e9f34c7
refactor(submissions): remove unused component
NSUWAL123 Aug 8, 2024
7906852
refactor(tabbed): remove unused tabbed component
NSUWAL123 Aug 8, 2024
dfeee06
fix(customizedModal): prop type add
NSUWAL123 Aug 8, 2024
ff65383
fix(appLoader): remove unused imports
NSUWAL123 Aug 8, 2024
3e5ffbc
refactor(geojsonObjectModal): remove redundant file, add ts type
NSUWAL123 Aug 8, 2024
dedd3ce
fix(projectListMap): update imports & types
NSUWAL123 Aug 8, 2024
a35fb80
fix(customizedImage): update ts types
NSUWAL123 Aug 8, 2024
119387e
fix(organisationGridCard): add ts type
NSUWAL123 Aug 8, 2024
95cdb78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const FormUpdateTab = ({ projectId }) => {
multiple={false}
data={uploadForm || []}
filterKey="url"
onUploadFile={(updatedFiles) => {
onUploadFile={(updatedFiles: FileType[]) => {
dispatch(CreateProjectActions.SetCustomFileValidity(false));
setUploadForm(updatedFiles);
}}
Expand Down
10 changes: 9 additions & 1 deletion src/frontend/src/components/common/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useState } from 'react';
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts';

const CustomBarChart = ({ data, xLabel, yLabel, dataKey, nameKey }) => {
type customBarChartType = {
data: Record<string, string | number>[];
xLabel: string;
yLabel: string;
dataKey: string;
nameKey: string;
};

const CustomBarChart = ({ data, xLabel, yLabel, dataKey, nameKey }: customBarChartType) => {
const [size, setSize] = useState({ width: 0, height: 0 });

return (
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/src/components/common/BottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React, { useEffect, useRef, useState } from 'react';
import FmtmLogo from '@/assets/images/hotLog.png';

const BottomSheet = ({ body, onClose }) => {
type bottomSheetType = {
body: React.ReactElement;
onClose: () => void;
};

const BottomSheet = ({ body, onClose }: bottomSheetType) => {
const sheetContentRef: any = useRef(null);
const bottomSheetRef: any = useRef(null);
const logoRef: any = useRef(null);
Expand All @@ -19,7 +24,7 @@ const BottomSheet = ({ body, onClose }) => {
updateSheetHeight(50);
}, []);

const updateSheetHeight = (height) => {
const updateSheetHeight = (height: number) => {
if (sheetContentRef.current) {
sheetContentRef.current.style.height = `${height}vh`;
const top = sheetContentRef.current.getBoundingClientRect().top;
Expand Down
8 changes: 7 additions & 1 deletion src/frontend/src/components/common/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export const CustomCheckbox = ({

return (
<div className="fmtm-flex fmtm-gap-2 sm:fmtm-gap-4">
<Checkbox checked={checked} onCheckedChange={onCheckedChange} className="fmtm-mt-[2px]" disabled={disabled} />
<Checkbox
ref={null}
checked={checked}
onCheckedChange={onCheckedChange}
className="fmtm-mt-[2px]"
disabled={disabled}
/>
<p
style={labelStyle}
className={`fmtm-text-[#7A7676] fmtm-font-archivo fmtm-text-base fmtm-break-words ${className}`}
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/src/components/common/Chips.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from 'react';
import AssetModule from '../../shared/AssetModules.js';

const Chips = ({ data, clearChip }) => {
type chipsType = {
data: string[];
clearChip: (i: number) => void;
};

const Chips = ({ data, clearChip }: chipsType) => {
return (
<div className="fmtm-flex fmtm-gap-2 fmtm-items-center fmtm-flex-wrap fmtm-my-2">
{data.map((item, i) => (
{data.map((item: string, i: number) => (
<div
key={i}
className="fmtm-px-2 fmtm-py-1 fmtm-border-[1px] fmtm-border-[#D7D7D7] fmtm-rounded-[40px] fmtm-flex fmtm-w-fit fmtm-items-center fmtm-gap-1"
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/common/Editor/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Toolbar = ({ editor }: ToolbarProps) => {
const [imageURL, setImageURL] = useState('');
const [imageDropdownOpen, setImageDropdownOpen] = useState(false);

const isEditorActive = (editorItem) => {
const isEditorActive = (editorItem: string) => {
if (editor?.isActive(editorItem)) {
return 'fmtm-text-primaryRed fmtm-bg-red-100';
}
Expand Down
12 changes: 11 additions & 1 deletion src/frontend/src/components/common/FileInputComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import React, { useRef } from 'react';
import AssetModules from '@/shared/AssetModules.js';

type fileInputComponentType = {
accept: string;
customFile: any;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
onResetFile: () => void;
btnText: string;
fileDescription: string;
errorMsg: string;
};

const FileInputComponent = ({
accept = '.geojson, .json',
customFile,
Expand All @@ -9,7 +19,7 @@ const FileInputComponent = ({
btnText = 'Select File',
fileDescription = '*The supported file formats are zipped shapefile, geojson or kml files.',
errorMsg,
}) => {
}: fileInputComponentType) => {
const customFileRef = useRef<any>(null);
return (
<div className="fmtm-mt-3 fmtm-pb-3">
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/src/components/common/KebabMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import AssetModules from '../../shared/AssetModules.js';

type optionType = { id: number | string; icon: React.ReactNode; label: string; onClick: any };

type directionType = 'left-top' | 'left-bottom' | 'right-bottom' | 'right-top' | 'top-left' | 'top-right';

type kebabMenuType = {
options: optionType[];
stopPropagation: boolean;
direction?: 'left-top' | 'left-bottom' | 'right-bottom' | 'right-top' | 'top-left' | 'top-right';
direction?: directionType;
data: {};
pid: string | number;
openedModalId: string | number;
onDropdownOpen: () => void;
};

function getPosition(direction) {
function getPosition(direction: directionType) {
switch (direction) {
case 'left-top':
return 'fmtm-top-[2px] fmtm-right-[40px]';
Expand Down
11 changes: 10 additions & 1 deletion src/frontend/src/components/common/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import React, { useState } from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';

const CustomLineChart = ({ data, xAxisDataKey, lineOneKey, lineTwoKey, xLabel, yLabel }) => {
type customLineChartType = {
data: Record<string, string | number>[];
xAxisDataKey: string;
lineOneKey: string;
lineTwoKey: string;
xLabel?: string;
yLabel?: string;
};

const CustomLineChart = ({ data, xAxisDataKey, lineOneKey, lineTwoKey, xLabel, yLabel }: customLineChartType) => {
const [size, setSize] = useState({ width: 0, height: 0 });

return (
Expand Down
12 changes: 9 additions & 3 deletions src/frontend/src/components/common/PieChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useState } from 'react';
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Legend } from 'recharts';

type customPieChartType = {
data: Record<string, string | number>[];
dataKey: string;
nameKey: string;
};

const COLORS = ['#F19C3C', '#D73F3F', '#FFB74D', '#EC407A'];

const RADIAN = Math.PI / 180;
Expand All @@ -17,7 +23,7 @@ const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, per
);
};

const renderColorfulLegendText = (value, entry) => (
const renderColorfulLegendText = (value: string, entry: any) => (
<span style={{ color: '#596579', fontWeight: 500, padding: '10px' }}>{value}</span>
);

Expand Down Expand Up @@ -45,7 +51,7 @@ const CustomLegend = ({ payload }) => (
</div>
);

const CustomPieChart = ({ data, dataKey, nameKey }) => {
const CustomPieChart = ({ data, dataKey, nameKey }: customPieChartType) => {
const [size, setSize] = useState({ width: 0, height: 0 });

return (
Expand Down Expand Up @@ -79,7 +85,7 @@ const CustomPieChart = ({ data, dataKey, nameKey }) => {
verticalAlign="bottom"
iconSize={10}
formatter={renderColorfulLegendText}
content={<CustomLegend payload={data?.map((index) => COLORS[index % COLORS.length])} />}
content={<CustomLegend payload={data?.map((_, index) => COLORS[index % COLORS.length])} />}
/>
</PieChart>
</ResponsiveContainer>
Expand Down
21 changes: 14 additions & 7 deletions src/frontend/src/components/common/StepSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import AssetModules from '@/shared/AssetModules.js';
import { CommonActions } from '@/store/slices/CommonSlice';
import CoreModules from '@/shared/CoreModules.js';
import { useNavigate } from 'react-router-dom';
import { ICreateProjectSteps } from '@/constants/StepFormConstants';

const StepSwitcher = ({ data, flag, switchSteps }) => {
interface IIndividualStep {
url: string;
step: number;
label: string;
name: string;
}
type stepSwitcherPropType = {
data: ICreateProjectSteps[];
flag: string;
switchSteps: boolean;
};

interface IIndividualStep {
url: string;
step: number;
label: string;
name: string;
}

const StepSwitcher = ({ data, flag, switchSteps }: stepSwitcherPropType) => {
const dispatch = CoreModules.useAppDispatch();
const navigate = useNavigate();
const currentStep = CoreModules.useAppSelector((state) => state.common.currentStepFormStep[flag]);
Expand Down
20 changes: 15 additions & 5 deletions src/frontend/src/components/common/UploadArea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch } from 'react-redux';
import { CommonActions } from '../../store/slices/CommonSlice';
import AssetModules from '../../shared/AssetModules.js';
import { CommonActions } from '@/store/slices/CommonSlice';
import AssetModules from '@/shared/AssetModules';
import { v4 as uuidv4 } from 'uuid';

type FileType = {
Expand All @@ -11,7 +11,17 @@ type FileType = {
isDeleted: boolean;
};

const UploadArea = ({ title, label, acceptedInput, data, onUploadFile, multiple, filterKey }) => {
type uploadAreaPropType = {
title: string;
label: string;
multiple: boolean;
data: FileType[];
filterKey: string;
onUploadFile: (updatedFiles: FileType[]) => void;
acceptedInput: string;
};

const UploadArea = ({ title, label, acceptedInput, data, onUploadFile, multiple, filterKey }: uploadAreaPropType) => {
const fileInputRef = useRef<HTMLInputElement>(null);
const dispatch = useDispatch();
const [selectedFiles, setSelectedFiles] = useState<FileType[]>([]);
Expand Down Expand Up @@ -83,7 +93,7 @@ const UploadArea = ({ title, label, acceptedInput, data, onUploadFile, multiple,
const id = uuidv4();
return fileList.push({ id, name, [filterKey]: file, isDeleted });
}
if (acceptedInput.includes(fileType)) {
if (fileType && acceptedInput.includes(fileType)) {
const id = uuidv4();
const isDeleted = false;
return fileList.push({ id, name, [filterKey]: file, isDeleted });
Expand All @@ -102,7 +112,7 @@ const UploadArea = ({ title, label, acceptedInput, data, onUploadFile, multiple,
if (multiple) {
onUploadFile([...fileList, ...data]);
} else {
onUploadFile([fileList.at(fileList.length - 1)]);
onUploadFile([fileList.at(fileList.length - 1) as FileType]);
}
} else {
onUploadFile(data);
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/components/createnewproject/DataExtract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,11 @@ const DataExtract = ({ flag, customDataExtractUpload, setCustomDataExtractUpload
<div className="fmtm-bg-white lg:fmtm-w-[20%] xl:fmtm-w-[17%] fmtm-px-5 fmtm-py-6">
<h6 className="fmtm-text-xl fmtm-font-[600] fmtm-pb-2 lg:fmtm-pb-6">Map Features</h6>
<p className="fmtm-text-gray-500 lg:fmtm-flex lg:fmtm-flex-col lg:fmtm-gap-3">
<span>
You may either choose to use OSM data, or upload your own data for the mapping project.
</span>
<span>You may either choose to use OSM data, or upload your own data for the mapping project.</span>
<span> The relevant map features that exist on OSM are imported based on the select map area.</span>{' '}
<span>
You can use these map features to use the 'select from map' functionality from ODK that allows you
to select the feature to collect data for.
You can use these map features to use the 'select from map' functionality from ODK that allows you to select
the feature to collect data for.
</span>{' '}
</p>
</div>
Expand Down
19 changes: 4 additions & 15 deletions src/frontend/src/components/home/ProjectListMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@ import { MapContainer as MapComponent } from '@/components/MapComponent/OpenLaye
import LayerSwitcherControl from '@/components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js';
import { ClusterLayer } from '@/components/MapComponent/OpenLayersComponent/Layers';
import CoreModules from '@/shared/CoreModules';
import { geojsonObjectModel } from '@/constants/geojsonObjectModal';
import { defaultStyles, getStyles } from '@/components/MapComponent/OpenLayersComponent/helpers/styleUtils';
import { geojsonObjectModel, geojsonObjectModelType } from '@/constants/geojsonObjectModal';
import { defaultStyles } from '@/components/MapComponent/OpenLayersComponent/helpers/styleUtils';
import MarkerIcon from '@/assets/images/red_marker.png';
import { useNavigate } from 'react-router-dom';
import { Style, Text, Icon, Fill } from 'ol/style';
import { projectType } from '@/models/home/homeModel';

type HomeProjectSummaryType = {
features: { geometry: any; properties: any; type: any }[];
type: string;
SRID: {
type: string;
properties: {
name: string;
};
};
};

const getIndividualStyle = (featureProperty) => {
const style = new Style({
image: new Icon({
Expand All @@ -43,7 +32,7 @@ const getIndividualStyle = (featureProperty) => {
const ProjectListMap = () => {
const navigate = useNavigate();

const [projectGeojson, setProjectGeojson] = useState<HomeProjectSummaryType | null>(null);
const [projectGeojson, setProjectGeojson] = useState<geojsonObjectModelType | null>(null);
const { mapRef, map } = useOLMap({
// center: fromLonLat([85.3, 27.7]),
center: [0, 0],
Expand All @@ -54,7 +43,7 @@ const ProjectListMap = () => {
const homeProjectSummary: projectType[] = CoreModules.useAppSelector((state) => state.home.homeProjectSummary);
useEffect(() => {
if (homeProjectSummary?.length === 0) return;
const convertedHomeProjectSummaryGeojson: HomeProjectSummaryType = {
const convertedHomeProjectSummaryGeojson: geojsonObjectModelType = {
...geojsonObjectModel,
features: homeProjectSummary.map((project) => ({
type: 'Feature',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import CoreModules from '@/shared/CoreModules';
import CustomizedImage from '@/utilities/CustomizedImage';
import { useNavigate } from 'react-router-dom';
import { user_roles } from '@/types/enums';
import { GetOrganisationDataModel } from '@/models/organisation/organisationModel';

const OrganisationGridCard = ({ filteredData, allDataLength }) => {
type organizationGridCardType = {
filteredData: GetOrganisationDataModel[];
allDataLength: number;
};

const OrganisationGridCard = ({ filteredData, allDataLength }: organizationGridCardType) => {
const navigate = useNavigate();
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails);
const cardStyle = {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/constants/StepFormConstants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface ICreateProjectSteps {
export interface ICreateProjectSteps {
url: string;
step: number;
label: string;
Expand Down
13 changes: 12 additions & 1 deletion src/frontend/src/constants/geojsonObjectModal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
export const geojsonObjectModel = {
export type geojsonObjectModelType = {
features: { geometry: any; properties: any; type: any }[];
type: string;
SRID: {
type: string;
properties: {
name: string;
};
};
};

export const geojsonObjectModel: geojsonObjectModelType = {
type: 'FeatureCollection',
SRID: {
type: 'name',
Expand Down
10 changes: 0 additions & 10 deletions src/frontend/src/models/geojsonObjectModel.js

This file was deleted.

Loading
Loading