θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content

Conversation

@shatfield4
Copy link
Collaborator

@shatfield4 shatfield4 commented Feb 14, 2024

Pull Request Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ”¨ chore
  • πŸ“ docs

Relevant Issues

resolves #705

What is in this change?

Describe the changes in this PR that are impactful to the repo.

  • Implement new workspace settings page and separate from document uploader modal

Additional Information

Add any other context about the Pull Request here that was not captured above.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

@shatfield4 shatfield4 self-assigned this Feb 14, 2024
@shatfield4 shatfield4 linked an issue Feb 14, 2024 that may be closed by this pull request
@review-agent-prime
Copy link

frontend/src/components/Sidebar/ActiveWorkspaces/index.jsx

Instead of calling setLoading(false) after setWorkspaces(workspaces), consider using a .finally block to ensure setLoading(false) is called even if an error occurs. This would prevent the UI from being stuck in a loading state if there's an error.
Create Issue
See the diff
Checkout the fix

    useEffect(() => {
      async function getWorkspaces() {
        try {
          const workspaces = await Workspace.all();
          setWorkspaces(workspaces);
        } catch (error) {
          console.error(error);
        } finally {
          setLoading(false);
        }
      }
      getWorkspaces();
    }, []);
git fetch origin && git checkout -b ReviewBot/There-gy626e4 origin/ReviewBot/There-gy626e4

frontend/src/pages/WorkspaceSettings/VectorDatabase/index.jsx

Consider destructuring workspace to avoid repeating workspace.slug multiple times. This would make the code cleaner and easier to read.
Create Issue
See the diff
Checkout the fix

    const handleUpdate = async (e) => {
      setSaving(true);
      e.preventDefault();
      const data = {};
      const form = new FormData(formEl.current);
      for (var [key, value] of form.entries()) data[key] = castToType(key, value);
      const { slug } = workspace;
      const { workspace: updatedWorkspace, message } = await Workspace.update(slug, data);
      // rest of the code
    };
git fetch origin && git checkout -b ReviewBot/There-nvx8bow origin/ReviewBot/There-nvx8bow

frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx

Consider using the useCallback hook for the handleUpdate function in the ChatSettings component. This will prevent unnecessary re-renders of the component when the function is used as a prop or within a useEffect, useMemo, or another useCallback.
Create Issue
See the diff
Checkout the fix

    const handleUpdate = useCallback(async (e) => {
+      setSaving(true);
+      e.preventDefault();
+      const data = {};
+      const form = new FormData(formEl.current);
+      for (var [key, value] of form.entries()) data[key] = castToType(key, value);
+      const { workspace: updatedWorkspace, message } = await Workspace.update(
+        workspace.slug,
+        data
+      );
+      if (!!updatedWorkspace) {
+        showToast("Workspace updated!", "success", { clear: true });
+      } else {
+        showToast(`Error: ${message}`, "error", { clear: true });
+      }
+      setSaving(false);
+      setHasChanges(false);
+    }, [workspace.slug]);
+    ```

git fetch origin && git checkout -b ReviewBot/Impro-thkn4rz origin/ReviewBot/Impro-thkn4rz


## frontend/src/pages/WorkspaceSettings/index.jsx

Consider using React.memo or useCallback to avoid unnecessary re-renders of the TabItem component. This will improve the performance of your application, especially when dealing with a large number of tabs.
[Create Issue](https://github.com/Mintplex-Labs/anything-llm/issues/new?title=The%20code%20has%20been%20refactored%20to%20improve%20readability%20and%20maintainability.%20However%2C%20there%20is%20room%20for%20further%20enhancement%20in%20terms%20of%20performance.&body=Consider%20using%20React.memo%20or%20useCallback%20to%20avoid%20unnecessary%20re-renders%20of%20the%20TabItem%20component.%20This%20will%20improve%20the%20performance%20of%20your%20application%2C%20especially%20when%20dealing%20with%20a%20large%20number%20of%20tabs.%0A%60%60%60jsx%0A%20%20%20%20const%20TabItem%20%3D%20React.memo((%7B%20title%2C%20icon%2C%20isActive%2C%20onClick%20%7D)%20%3D%3E%20%7B%0A%20%20%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20%3Cbutton%0A%20%20%20%20%20%20%20%20%20%20className%3D%7B%60flex%20gap-x-2%20text-sky-400%20text-white%2F60%20hover%3Atext-sky-400%20font-medium%20%24%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20isActive%20%3F%20%22text-sky-400%22%20%3A%20%22%22%0A%20%20%20%20%20%20%20%20%20%20%7D%60%7D%0A%20%20%20%20%20%20%20%20%20%20onClick%3D%7BonClick%7D%0A%20%20%20%20%20%20%20%20%3E%0A%20%20%20%20%20%20%20%20%20%20%7Bicon%7D%0A%20%20%20%20%20%20%20%20%20%20%3Cdiv%3E%7Btitle%7D%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fbutton%3E%0A%20%20%20%20%20%20)%3B%0A%20%20%20%20%7D)%3B%0A%60%60%60%0A)
[See the diff](https://github.com/Mintplex-Labs/anything-llm/compare/705-feat-new-workspace-settings-layout...ReviewBot/The-c-vx3p737)
[Checkout the fix](https://github.com/Mintplex-Labs/anything-llm/blob/ReviewBot/The-c-vx3p737/frontend/src/pages/WorkspaceSettings/index.jsx#L95)

```jsx
    const TabItem = React.memo(({ title, icon, isActive, onClick }) => {
      return (
        <button
          className={`flex gap-x-2 text-sky-400 text-white/60 hover:text-sky-400 font-medium ${
            isActive ? "text-sky-400" : ""
          }`}
          onClick={onClick}
        >
          {icon}
          <div>{title}</div>
        </button>
      );
    });
git fetch origin && git checkout -b ReviewBot/The-c-vx3p737 origin/ReviewBot/The-c-vx3p737

Consider using React.lazy for code splitting to load each tab content only when it's needed. This will improve the initial load time of your application.
Create Issue
See the diff
Checkout the fix

    const GeneralInfo = React.lazy(() => import('./GeneralInfo'));
    const ChatSettings = React.lazy(() => import('./ChatSettings'));
    const VectorDatabase = React.lazy(() => import('./VectorDatabase'));

    const tabsMapping = {
      "general-info": GeneralInfo,
      "chat-settings": ChatSettings,
      "vector-database": VectorDatabase,
    };

    const TabContent = tabsMapping[tab];

    return (
      <React.Suspense fallback={<div>Loading...</div>}>
        <TabContent slug={slug} workspace={workspace} />
      </React.Suspense>
    );
git fetch origin && git checkout -b ReviewBot/The-c-ip4zoth origin/ReviewBot/The-c-ip4zoth

frontend/src/hooks/useGetProvidersModels.js

Instead of using a reduce function to group models, consider using a more declarative approach with the help of a Map object. This will make the code easier to read and maintain.
Create Issue
See the diff
Checkout the fix

    function groupModels(models) {
      const groupedModels = new Map();
      models.forEach(model => {
        const modelsList = groupedModels.get(model.organization) || [];
        modelsList.push(model);
        groupedModels.set(model.organization, modelsList);
      });
      return Object.fromEntries(groupedModels);
    }
git fetch origin && git checkout -b ReviewBot/Impro-kcx14ag origin/ReviewBot/Impro-kcx14ag

Consider using the functional update form of the useState hook's setter function. This will ensure that the state updates are always based on the most recent state and avoid unnecessary re-rendering.
Create Issue
See the diff
Checkout the fix

    setDefaultModels(prevModels => PROVIDER_DEFAULT_MODELS[provider] || prevModels);
    setCustomModels(prevModels => provider === "togetherai" ? groupModels(models) : models || prevModels);
git fetch origin && git checkout -b ReviewBot/Impro-pro14ih origin/ReviewBot/Impro-pro14ih

frontend/src/utils/types.js

Instead of using a definitions object to handle the casting of values, consider using a Map object. This will make the code easier to read and maintain.
Create Issue
See the diff
Checkout the fix

    export function castToType(key, value) {
      const definitions = new Map([
        ['openAiTemp', Number],
        ['openAiHistory', Number],
        ['similarityThreshold', parseFloat],
        ['topN', Number]
      ]);

      const castFunction = definitions.get(key);
      return castFunction ? castFunction(value) : value;
    }
git fetch origin && git checkout -b ReviewBot/Impro-bhztn2f origin/ReviewBot/Impro-bhztn2f

@shatfield4 shatfield4 changed the title [STYLE] New Workspace Settings Layout [FEAT] New Workspace Settings Layout Feb 14, 2024
@shatfield4 shatfield4 marked this pull request as ready for review February 14, 2024 22:10
@timothycarambat timothycarambat merged commit 858b2fc into master Feb 14, 2024
@timothycarambat timothycarambat deleted the 705-feat-new-workspace-settings-layout branch February 14, 2024 23:29
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
* WIP new settings layout

* add suggested messages to general & appearance and clean up/make more user friendly

* lazy load workspace settings pages

* css fix on X button for document picker where button is barely clickable

* remove additional workspace settings page

* fix thread selection action when on thread

* refactor inputs into sub-components
remove unused paths

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: New Workspace Settings Layout

3 participants