Fixed badge showing blank when no type is selected

This commit is contained in:
Lucas Oliveira 2024-04-30 17:01:26 +02:00
commit 239a24ac16

View file

@ -8,32 +8,45 @@ import Dropdown from "../../../../components/dropdownComponent";
import ForwardedIconComponent from "../../../../components/genericIconComponent"; import ForwardedIconComponent from "../../../../components/genericIconComponent";
import TableComponent from "../../../../components/tableComponent"; import TableComponent from "../../../../components/tableComponent";
import { Badge } from "../../../../components/ui/badge"; import { Badge } from "../../../../components/ui/badge";
import { cn } from "../../../../utils/utils";
import { useGlobalVariablesStore } from "../../../../stores/globalVariables"; import { useGlobalVariablesStore } from "../../../../stores/globalVariables";
import { cn } from "../../../../utils/utils";
export default function GlobalVariablesPage() { export default function GlobalVariablesPage() {
const rows: Array<{type: string | undefined; id: string; name: string}> = []; const rows: Array<{ type: string | undefined; id: string; name: string }> =
const globalVariablesEntries = useGlobalVariablesStore(state => state.globalVariablesEntries); [];
const removeGlobalVariable = useGlobalVariablesStore(state => state.removeGlobalVariable); const globalVariablesEntries = useGlobalVariablesStore(
const globalVariables = useGlobalVariablesStore(state => state.globalVariables); (state) => state.globalVariablesEntries
);
const removeGlobalVariable = useGlobalVariablesStore(
(state) => state.removeGlobalVariable
);
const globalVariables = useGlobalVariablesStore(
(state) => state.globalVariables
);
globalVariablesEntries.forEach((e) => { globalVariablesEntries.forEach((e) => {
const globalVariableObj = globalVariables[e] const globalVariableObj = globalVariables[e];
rows.push({type: globalVariableObj.type, id: globalVariableObj.id, name: e}) rows.push({
}) type: globalVariableObj.type,
id: globalVariableObj.id,
name: e,
});
});
const BadgeRenderer = (props) => { const BadgeRenderer = (props) => {
return ( return props.value !== "" ? (
<div> <div>
<Badge variant="outline" size="md" className="font-normal"> <Badge variant="outline" size="md" className="font-normal">
{props.value} {props.value}
</Badge> </Badge>
</div> </div>
) : (
<div></div>
); );
}; };
useEffect(() => { useEffect(() => {
setRowData(rows) setRowData(rows);
}, [globalVariables]) }, [globalVariables]);
const DropdownEditor = ({ options, value, onValueChange }) => { const DropdownEditor = ({ options, value, onValueChange }) => {
return ( return (
@ -113,9 +126,9 @@ export default function GlobalVariablesPage() {
const [selectedRows, setSelectedRows] = useState<string[]>([]); const [selectedRows, setSelectedRows] = useState<string[]>([]);
function removeVariables() { function removeVariables() {
selectedRows.forEach(row => { selectedRows.forEach((row) => {
removeGlobalVariable(row) removeGlobalVariable(row);
}) });
} }
return ( return (