Skip to content

Commit 4998bc3

Browse files
Fixed PluginChooser button width problem (#3014)
Fix for PluginChooser Button width UI problem and for plugins variable 'undefined' from localsorage --------- Co-authored-by: notmd <33456881+notmd@users.noreply.github.com>
1 parent 66399b3 commit 4998bc3

File tree

2 files changed

+50
-57
lines changed

2 files changed

+50
-57
lines changed

website/src/components/Chat/ChatConfigForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const ChatConfigForm = memo(function ChatConfigForm() {
9292

9393
const { control, getValues, register, setValue } = useFormContext<ChatConfigFormData>();
9494
const selectedModel = getValues("model_config_name"); // have to use getValues to here to access latest value
95-
const plugins = getValues("plugins");
95+
const plugins = getValues("plugins") || [];
9696
const presets = modelInfos.find((model) => model.name === selectedModel)!.parameter_configs;
9797
const [selectedPresetName, setSelectedPresetName] = useState(() => findPresetName(presets, getValues()));
9898
const [lockPresetSelection, setLockPresetSelection] = useState(false);

website/src/components/Chat/PluginsChooser.tsx

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ import { PluginEntry } from "src/types/Chat";
3939
import { get, post } from "src/lib/api";
4040
import { API_ROUTES } from "src/lib/routes";
4141

42-
// TODO: Delete me!
43-
const measureDivWidth = (div: HTMLDivElement | null) => {
44-
if (!div) return 0;
45-
const width = div?.parentElement?.offsetWidth - 15;
46-
return width;
47-
};
48-
4942
export const PluginsChooser = ({ plugins }: { plugins: PluginEntry[] }) => {
5043
const { t } = useTranslation("chat");
5144
const { control, register, reset, setValue } = useFormContext<ChatConfigFormData>();
@@ -114,30 +107,30 @@ export const PluginsChooser = ({ plugins }: { plugins: PluginEntry[] }) => {
114107
}, [setValue, plugins, handlePluginEdit]);
115108

116109
return (
117-
<FormControl mb="40px" ref={containerRef}>
118-
<Box position="fixed" zIndex="1">
119-
<Menu placement="auto">
120-
<MenuButton as={Button} pr="3" rightIcon={<Cog />} w={measureDivWidth(containerRef.current) + 15} size="lg">
121-
{plugins && plugins[activePluginIndex]?.enabled ? (
122-
<Box display="flex" justifyContent="flex-start" gap={2}>
123-
<Image
124-
src={plugins[activePluginIndex]?.plugin_config?.logo_url}
125-
alt="Plugins"
126-
width="25px"
127-
height="25px"
128-
marginRight="5px"
129-
/>
130-
<Text mt="4px" fontSize="sm" isTruncated>
131-
{plugins[activePluginIndex]?.plugin_config?.name_for_human}
132-
</Text>
133-
</Box>
134-
) : (
135-
<Box display="flex" justifyContent="center" gap={2}>
136-
<AttachmentIcon boxSize="5" />
137-
{t("plugins")}
138-
</Box>
139-
)}
140-
</MenuButton>
110+
<FormControl ref={containerRef}>
111+
<Menu placement="auto">
112+
<MenuButton as={Button} pr="3" rightIcon={<Cog />} size="lg" width="100%">
113+
{activePluginIndex > -1 && plugins[activePluginIndex]?.enabled ? (
114+
<Box display="flex" justifyContent="flex-start" gap={2}>
115+
<Image
116+
src={plugins[activePluginIndex]?.plugin_config?.logo_url}
117+
alt="Plugins"
118+
width="25px"
119+
height="25px"
120+
marginRight="5px"
121+
/>
122+
<Text mt="4px" fontSize="sm" isTruncated>
123+
{plugins[activePluginIndex]?.plugin_config?.name_for_human}
124+
</Text>
125+
</Box>
126+
) : (
127+
<Box display="flex" justifyContent="center" gap={2}>
128+
<AttachmentIcon boxSize="5" />
129+
{t("plugins")}
130+
</Box>
131+
)}
132+
</MenuButton>
133+
<Box position="fixed" zIndex="1">
141134
<MenuList left="-150px" position="absolute" w="280px">
142135
<RadioGroup value={plugins?.findIndex((plugin) => plugin.enabled).toString()}>
143136
{plugins?.map((plugin, index) => (
@@ -214,31 +207,31 @@ export const PluginsChooser = ({ plugins }: { plugins: PluginEntry[] }) => {
214207
</Box>
215208
</MenuItem>
216209
</MenuList>
217-
</Menu>
218-
<Modal isOpen={isOpen} onClose={onClose} size="xl">
219-
<ModalOverlay />
220-
<ModalContent>
221-
<ModalHeader>{t("edit_plugin")}</ModalHeader>
222-
<ModalCloseButton />
223-
<ModalBody>
224-
<Textarea
225-
minHeight="40px"
226-
defaultValue={selectedForEditPluginIndex !== null ? plugins[selectedForEditPluginIndex!]?.url : ""}
227-
ref={textareaRef}
228-
mb={4}
229-
/>
230-
<Box as="pre" whiteSpace="pre-wrap" fontSize="xs">
231-
{JSON.stringify(plugins[selectedForEditPluginIndex!], null, 4)}
232-
</Box>
233-
</ModalBody>
234-
<ModalFooter>
235-
<Button colorScheme="blue" onClick={handlePluginSave}>
236-
{t("save")}
237-
</Button>
238-
</ModalFooter>
239-
</ModalContent>
240-
</Modal>
241-
</Box>
210+
</Box>
211+
</Menu>
212+
<Modal isOpen={isOpen} onClose={onClose} size="xl">
213+
<ModalOverlay />
214+
<ModalContent>
215+
<ModalHeader>{t("edit_plugin")}</ModalHeader>
216+
<ModalCloseButton />
217+
<ModalBody>
218+
<Textarea
219+
minHeight="40px"
220+
defaultValue={selectedForEditPluginIndex !== null ? plugins[selectedForEditPluginIndex!]?.url : ""}
221+
ref={textareaRef}
222+
mb={4}
223+
/>
224+
<Box as="pre" whiteSpace="pre-wrap" fontSize="xs">
225+
{JSON.stringify(plugins[selectedForEditPluginIndex!], null, 4)}
226+
</Box>
227+
</ModalBody>
228+
<ModalFooter>
229+
<Button colorScheme="blue" onClick={handlePluginSave}>
230+
{t("save")}
231+
</Button>
232+
</ModalFooter>
233+
</ModalContent>
234+
</Modal>
242235
</FormControl>
243236
);
244237
};

0 commit comments

Comments
 (0)