ui - fix bug showing mdoels to pic

This commit is contained in:
Ishaan Jaff 2024-04-27 16:01:50 -07:00
parent 2f9418eb46
commit 0e891528b6

View file

@ -39,6 +39,7 @@ const CreateKey: React.FC<CreateKeyProps> = ({
const [apiKey, setApiKey] = useState(null); const [apiKey, setApiKey] = useState(null);
const [softBudget, setSoftBudget] = useState(null); const [softBudget, setSoftBudget] = useState(null);
const [userModels, setUserModels] = useState([]); const [userModels, setUserModels] = useState([]);
const [modelsToPick, setModelsToPick] = useState([]);
const handleOk = () => { const handleOk = () => {
setIsModalVisible(false); setIsModalVisible(false);
form.resetFields(); form.resetFields();
@ -95,6 +96,30 @@ const CreateKey: React.FC<CreateKeyProps> = ({
message.success('API Key copied to clipboard'); message.success('API Key copied to clipboard');
}; };
useEffect(() => {
let tempModelsToPick = [];
if (team) {
if (team.models.length > 0) {
if (team.models.includes("all-proxy-models")) {
// if the team has all-proxy-models show all available models
tempModelsToPick = userModels;
} else {
// show team models
tempModelsToPick = team.models;
}
} else {
// show all available models if the team has no models set
tempModelsToPick = userModels;
}
} else {
// no team set, show all available models
tempModelsToPick = userModels;
}
setModelsToPick(tempModelsToPick);
}, [team, userModels]);
return ( return (
<div> <div>
@ -161,30 +186,15 @@ const CreateKey: React.FC<CreateKeyProps> = ({
<Option key="all-team-models" value="all-team-models"> <Option key="all-team-models" value="all-team-models">
All Team Models All Team Models
</Option> </Option>
{team && team.models ? ( {
team.models.includes("all-proxy-models") ? ( modelsToPick.map((model: string) => (
userModels.map((model: string) => (
( (
<Option key={model} value={model}> <Option key={model} value={model}>
{model} {model}
</Option> </Option>
) )
)) ))
) : ( }
team.models.map((model: string) => (
<Option key={model} value={model}>
{model}
</Option>
))
)
) : (
userModels.map((model: string) => (
<Option key={model} value={model}>
{model}
</Option>
))
)}
</Select> </Select>
</Form.Item> </Form.Item>
<Accordion className="mt-20 mb-8" > <Accordion className="mt-20 mb-8" >