From 8d84475620e329abfa2854b3b54a08b03029f14e Mon Sep 17 00:00:00 2001
From: Ullas8296 <125345939+Ullas8296@users.noreply.github.com>
Date: Wed, 8 Jan 2025 23:17:55 +0530
Subject: [PATCH] Fix bug in Dropdown component (Issue #107) (#113)
---
client/src/components/Dropdown.tsx | 149 ++++++++++++++++-------------
package-lock.json | 55 +++++++----
2 files changed, 119 insertions(+), 85 deletions(-)
diff --git a/client/src/components/Dropdown.tsx b/client/src/components/Dropdown.tsx
index 5af2862..7983397 100644
--- a/client/src/components/Dropdown.tsx
+++ b/client/src/components/Dropdown.tsx
@@ -16,12 +16,90 @@ interface DropdownProps {
export interface DropdownOption {
text: string;
- value: string; // the main value used for api calls
+ value: string; // the main value used for API calls
}
-export default function Dropdown({ sx, id, disabled, value, options, onChange, decorator, icon, placeholder, loading }: DropdownProps) {
+export default function Dropdown({
+ sx,
+ id,
+ disabled,
+ value,
+ options,
+ onChange,
+ decorator,
+ icon,
+ placeholder,
+ loading,
+}: DropdownProps) {
const height = '60px';
+ // Determine the valid value for the dropdown
+ const validValue = options?.find((option) => option.value === value) ? value : '';
+
+ // Determine the content for the `renderValue` prop
+ const getRenderValue = (selected: string) => {
+ const selectedOption = options?.find((option) => option.value === selected);
+
+ if (placeholder && (!selected || selected.length === 0)) {
+ return (
+
+ {icon && icon}
+ {loading ? (
+
+ ) : (
+ ({
+ color: theme.palette.grey[500],
+ fontStyle: 'italic',
+ ml: 2,
+ fontWeight: 400,
+ }),
+ ]}
+ >
+ {placeholder}
+
+ )}
+
+ );
+ }
+
+ return (
+
+ {icon && icon}
+
+ {selectedOption ? selectedOption.text + (decorator || '') : '-'}
+
+
+ );
+ };
+
useEffect(() => {
console.log(id, value, options);
}, []);
@@ -32,74 +110,13 @@ export default function Dropdown({ sx, id, disabled, value, options, onChange, d
return (
);
-}
+}
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index f6b2ee7..48e78fa 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2011,15 +2011,16 @@
}
},
"node_modules/@nestjs/platform-express": {
- "version": "10.4.7",
- "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.7.tgz",
- "integrity": "sha512-q6XDOxZPTZ9cxALcVuKUlRBk+cVEv6dW2S8p2yVre22kpEQxq53/OI8EseDvzObGb6hepZ8+yBY04qoYqSlXNQ==",
+ "version": "10.4.15",
+ "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.15.tgz",
+ "integrity": "sha512-63ZZPkXHjoDyO7ahGOVcybZCRa7/Scp6mObQKjcX/fTEq1YJeU75ELvMsuQgc8U2opMGOBD7GVuc4DV0oeDHoA==",
+ "license": "MIT",
"dependencies": {
"body-parser": "1.20.3",
"cors": "2.8.5",
- "express": "4.21.1",
+ "express": "4.21.2",
"multer": "1.4.4-lts.1",
- "tslib": "2.7.0"
+ "tslib": "2.8.1"
},
"funding": {
"type": "opencollective",
@@ -2030,6 +2031,12 @@
"@nestjs/core": "^10.0.0"
}
},
+ "node_modules/@nestjs/platform-express/node_modules/tslib": {
+ "version": "2.8.1",
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
+ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
+ "license": "0BSD"
+ },
"node_modules/@nestjs/schematics": {
"version": "10.2.3",
"resolved": "https://registry.npmjs.org/@nestjs/schematics/-/schematics-10.2.3.tgz",
@@ -2056,6 +2063,7 @@
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@nestjs/serve-static/-/serve-static-4.0.2.tgz",
"integrity": "sha512-cT0vdWN5ar7jDI2NKbhf4LcwJzU4vS5sVpMkVrHuyLcltbrz6JdGi1TfIMMatP2pNiq5Ie/uUdPSFDVaZX/URQ==",
+ "license": "MIT",
"dependencies": {
"path-to-regexp": "0.2.5"
},
@@ -2081,7 +2089,8 @@
"node_modules/@nestjs/serve-static/node_modules/path-to-regexp": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.2.5.tgz",
- "integrity": "sha512-l6qtdDPIkmAmzEO6egquYDfqQGPMRNGjYtrU13HAXb3YSRrt7HSb1sJY0pKp6o2bAa86tSB6iwaW2JbthPKr7Q=="
+ "integrity": "sha512-l6qtdDPIkmAmzEO6egquYDfqQGPMRNGjYtrU13HAXb3YSRrt7HSb1sJY0pKp6o2bAa86tSB6iwaW2JbthPKr7Q==",
+ "license": "MIT"
},
"node_modules/@nestjs/throttler": {
"version": "6.2.1",
@@ -4480,9 +4489,10 @@
}
},
"node_modules/cross-spawn": {
- "version": "7.0.3",
- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
- "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
+ "version": "7.0.6",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
+ "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
+ "license": "MIT",
"dependencies": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
@@ -5314,9 +5324,10 @@
}
},
"node_modules/express": {
- "version": "4.21.1",
- "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz",
- "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==",
+ "version": "4.21.2",
+ "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
+ "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
+ "license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
@@ -5337,7 +5348,7 @@
"methods": "~1.1.2",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
- "path-to-regexp": "0.1.10",
+ "path-to-regexp": "0.1.12",
"proxy-addr": "~2.0.7",
"qs": "6.13.0",
"range-parser": "~1.2.1",
@@ -5352,6 +5363,10 @@
},
"engines": {
"node": ">= 0.10.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
}
},
"node_modules/express/node_modules/debug": {
@@ -5368,9 +5383,10 @@
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/express/node_modules/path-to-regexp": {
- "version": "0.1.10",
- "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz",
- "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w=="
+ "version": "0.1.12",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
+ "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
+ "license": "MIT"
},
"node_modules/extend": {
"version": "3.0.2",
@@ -7723,9 +7739,9 @@
"dev": true
},
"node_modules/nanoid": {
- "version": "3.3.7",
- "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
- "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==",
+ "version": "3.3.8",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz",
+ "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==",
"dev": true,
"funding": [
{
@@ -7733,6 +7749,7 @@
"url": "https://github.com/sponsors/ai"
}
],
+ "license": "MIT",
"bin": {
"nanoid": "bin/nanoid.cjs"
},