-
Notifications
You must be signed in to change notification settings - Fork 560
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
Basic CRUD pages for Devices #10560
base: develop
Are you sure you want to change the base?
Basic CRUD pages for Devices #10560
Changes from 11 commits
594984c
70e99d8
c9ab317
ff5a99d
d061307
e865706
15b2f15
f05ceb8
f229a6a
ec4e42d
e36307a
493c069
e03da90
9e7bd2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
import { useQuery } from "@tanstack/react-query"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { useTranslation } from "react-i18next"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||||||
Command, | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -33,6 +34,7 @@ export function LocationSearch({ | |||||||||||||||||||||||||||||||||||||||||||||
disabled, | ||||||||||||||||||||||||||||||||||||||||||||||
value, | ||||||||||||||||||||||||||||||||||||||||||||||
}: LocationSearchProps) { | ||||||||||||||||||||||||||||||||||||||||||||||
const { t } = useTranslation(); | ||||||||||||||||||||||||||||||||||||||||||||||
const [open, setOpen] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||
const [search, setSearch] = useState(""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -61,6 +63,7 @@ export function LocationSearch({ | |||||||||||||||||||||||||||||||||||||||||||||
<CommandInput | ||||||||||||||||||||||||||||||||||||||||||||||
placeholder="Search locations..." | ||||||||||||||||||||||||||||||||||||||||||||||
value={search} | ||||||||||||||||||||||||||||||||||||||||||||||
className="outline-none border-none ring-0 shadow-none" | ||||||||||||||||||||||||||||||||||||||||||||||
onValueChange={setSearch} | ||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||
<CommandEmpty>No locations found.</CommandEmpty> | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -74,7 +77,15 @@ export function LocationSearch({ | |||||||||||||||||||||||||||||||||||||||||||||
setOpen(false); | ||||||||||||||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||
{location.name} | ||||||||||||||||||||||||||||||||||||||||||||||
<span>{location.name}</span> | ||||||||||||||||||||||||||||||||||||||||||||||
<span className="text-xs text-gray-500"> | ||||||||||||||||||||||||||||||||||||||||||||||
{t(`location_form__${location.form}`)} | ||||||||||||||||||||||||||||||||||||||||||||||
{" in "} | ||||||||||||||||||||||||||||||||||||||||||||||
{formatLocationParent(location)} | ||||||||||||||||||||||||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||||||||||||||||||||||||
<span className="text-xs text-gray-500 ml-auto"> | ||||||||||||||||||||||||||||||||||||||||||||||
{t(`location_status__${location.status}`)} | ||||||||||||||||||||||||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||||||||||||||||||||||||
</CommandItem> | ||||||||||||||||||||||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||||||||||||||||||||||
</CommandGroup> | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -83,3 +94,12 @@ export function LocationSearch({ | |||||||||||||||||||||||||||||||||||||||||||||
</Popover> | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const formatLocationParent = (location: LocationList) => { | ||||||||||||||||||||||||||||||||||||||||||||||
const parents: string[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||
while (location.parent?.name) { | ||||||||||||||||||||||||||||||||||||||||||||||
parents.push(location.parent?.name); | ||||||||||||||||||||||||||||||||||||||||||||||
location = location.parent; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
return parents.reverse().join(" > "); | ||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+97
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add safeguard against infinite loops in formatLocationParent. The while loop could potentially enter an infinite loop if there's a circular reference in the location hierarchy. const formatLocationParent = (location: LocationList) => {
const parents: string[] = [];
+ const visited = new Set<string>();
while (location.parent?.name) {
+ if (visited.has(location.parent.id)) {
+ console.error("Circular reference detected in location hierarchy");
+ break;
+ }
+ visited.add(location.parent.id);
parents.push(location.parent?.name);
location = location.parent;
}
return parents.reverse().join(" > ");
}; 📝 Committable suggestion
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Add error handling for missing translation keys.
The translation keys
location_form__${location.form}
andlocation_status__${location.status}
might not exist in the translation files. Consider adding fallback values or error handling.Run this script to check for missing translation keys:
🏁 Script executed:
Length of output: 5415
Enhance Fallbacks for Missing Translations
The dynamic translation keys (
location_form__${location.form}
andlocation_status__${location.status}
) currently lack a fallback mechanism. This may lead to unfriendly UI when a translation key is absent. Please implement fallbacks or leverage i18next’s default behavior to ensure a graceful display if the translation is missing. Also, note that the verification script appears to prepend file names to the keys, so double-check that the locale key extraction accurately reflects the keys used in the component.