Skip to content
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

feat: new meta manager UI #513

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Kodylow
Copy link
Member

@Kodylow Kodylow commented Sep 2, 2024

New Meta Manager UI per @sbddesign figma
https://www.figma.com/design/TcAV8bmhcaQAxiZE8hjWY9/Fedimint-UI?node-id=0-1&node-type=CANVAS&t=aeKskxAmbQmahHrz-0

  • 2 tabs, one for consensus/proposing one for voting on proposals
  • Required and Optional fields: Required being Federation Name, Welcome Message, Popup (not actually required but just surfacing to the front to make it easy for people to set timeouts on their federations), and FederationIconUrl with a preview icon thing for it

TODO: Still can't come up with a good view on mobile, @sbddesign can you see if you can come up with something? just switch your UI to mobile and click through, it's hard to get the table looking correct

Summary by CodeRabbit

  • New Features

    • Introduced a modal for confirming new metadata entries.
    • Added functionality for proposing edits to metadata with a dedicated modal.
    • Enhanced the dashboard with improved metadata submission tracking and display.
    • New component to inform users when there are no pending proposals.
    • Added a component to manage and display metadata requirements with real-time feedback.
  • Improvements

    • Streamlined metadata management and validation processes.
    • Enhanced user interface for metadata input and display, including real-time feedback.
    • Simplified the rendering logic for displaying consensus metadata.
  • User Interface Updates

    • Updated labels and descriptions in the language configuration for clarity and consistency.
    • Improved responsiveness of the dashboard components.
  • Utility Enhancements

    • Added utility functions for JSON validation and string manipulation.
    • Introduced new interface for enhanced representation of consensus metadata.

@Kodylow Kodylow requested review from a team as code owners September 2, 2024 21:45
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

Walkthrough

The changes enhance metadata management within the application by introducing new components for confirming and proposing metadata edits, while also modifying existing components for improved state handling and rendering. The metadata-related types have been refined, and utility functions for string manipulation and JSON validation have been added. Additionally, user interface labels and descriptions have been updated for clarity and functionality.

Changes

File(s) Change Summary
apps/guardian-ui/src/components/dashboard/tabs/FederationTabsCard.tsx Introduced new state variables and polling functions for metadata submissions. Updated rendering logic to include new tabs and improved efficiency in fetching and displaying metadata.
apps/guardian-ui/src/components/dashboard/tabs/meta/ConfirmNewMetaModal.tsx Implemented a modal for confirming new metadata entries with internationalization support and structured UI using Chakra UI.
apps/guardian-ui/src/components/dashboard/tabs/meta/MetaManager.tsx Enhanced metadata management with new state variables, validation logic, and a simplified rendering interface for inline editing of metadata fields.
apps/guardian-ui/src/components/dashboard/tabs/meta/NoPendingProposals.tsx Created a component to inform users of no pending proposals, utilizing internationalization and Chakra UI for layout.
apps/guardian-ui/src/components/dashboard/tabs/meta/ProposeMetaModal.tsx Developed a modal for proposing metadata edits, featuring localized descriptions and interactive input fields.
apps/guardian-ui/src/components/dashboard/tabs/meta/ProposedMetas.tsx Streamlined component with updated props and state management, removed polling, and improved rendering logic for better performance.
apps/guardian-ui/src/components/dashboard/tabs/meta/RequiredMeta.tsx Introduced a component for managing required metadata, including image preview functionality and real-time validation feedback.
apps/guardian-ui/src/components/dashboard/tabs/meta/ViewConsensusMeta.tsx Simplified component logic by removing polling and unused props, focusing on direct rendering of consensus metadata.
apps/guardian-ui/src/languages/en.json Updated labels and descriptions for clarity in metadata management, including new buttons and improved terminology.
apps/guardian-ui/src/utils/index.ts Added a utility function, isJsonString, for validating JSON strings.
packages/types/src/meta.ts Introduced a new interface, ParsedConsensusMeta, to enhance the representation of consensus metadata.
packages/utils/src/index.tsx Added utility functions, snakeToTitleCase and titleToSnakeCase, for string formatting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as User Interface
    participant MetaManager
    participant ConfirmNewMetaModal
    participant ProposeMetaModal

    User->>UI: Open metadata management
    UI->>MetaManager: Load required metadata
    MetaManager->>UI: Display metadata fields
    User->>UI: Propose new metadata
    UI->>ProposeMetaModal: Open modal for proposing edits
    User->>ProposeMetaModal: Submit proposed changes
    ProposeMetaModal->>MetaManager: Send proposed edits
    MetaManager->>UI: Update displayed metadata
    User->>UI: Confirm new metadata
    UI->>ConfirmNewMetaModal: Open confirmation modal
    User->>ConfirmNewMetaModal: Confirm changes
    ConfirmNewMetaModal->>MetaManager: Finalize metadata updates
    MetaManager->>UI: Refresh metadata display
Loading

Suggested reviewers


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 555f958 and 5e5d20c.

Files selected for processing (17)
  • apps/router/src/guardian-ui/components/dashboard/tabs/FederationTabsCard.tsx (6 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/MetaManager.tsx (0 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposedMetas.tsx (0 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ViewConsensusMeta.tsx (0 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/IconPreview.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/MetaInput.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/MetaManager.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/ProposeMetaModal.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/RequiredMeta.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/ConfirmNewMetaModal.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/NoPendingProposals.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/ProposedMetas.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/setup/screens/connectGuardians/ConnectGuardians.tsx (1 hunks)
  • apps/router/src/guardian-ui/utils/index.ts (1 hunks)
  • apps/router/src/languages/en.json (1 hunks)
  • packages/types/src/meta.ts (1 hunks)
  • packages/utils/src/index.tsx (1 hunks)
Files not reviewed due to no reviewable changes (3)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/MetaManager.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposedMetas.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ViewConsensusMeta.tsx
Files skipped from review due to trivial changes (1)
  • apps/router/src/languages/en.json
Files skipped from review as they are similar to previous changes (12)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/IconPreview.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/MetaInput.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/MetaManager.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/ProposeMetaModal.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/manager/RequiredMeta.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/ConfirmNewMetaModal.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/NoPendingProposals.tsx
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/proposals/ProposedMetas.tsx
  • apps/router/src/guardian-ui/components/setup/screens/connectGuardians/ConnectGuardians.tsx
  • apps/router/src/guardian-ui/utils/index.ts
  • packages/types/src/meta.ts
  • packages/utils/src/index.tsx
Additional comments not posted (1)
apps/router/src/guardian-ui/components/dashboard/tabs/FederationTabsCard.tsx (1)

Line range hint 1-262: Comprehensive enhancements to metadata management and user experience.

The changes introduce significant improvements to the FederationTabsCard component:

  • Polling mechanism for metadata submissions and consensus metadata keeps the data up-to-date.
  • MetaSubmissionMap structure enhances management and visibility of metadata submissions.
  • Optimized polling for consensus metadata improves performance by reducing unnecessary re-renders.
  • UI enhancements, such as the pending proposals badge, provide a more engaging user experience.

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment on lines 20 to 44
useEffect(() => {
if (requiredMeta.federation_icon_url) {
fetch(requiredMeta.federation_icon_url)
.then((response) => {
if (!response.ok) throw new Error('Invalid icon URL');
return response.blob();
})
.then((blob) => {
if (blob.type.startsWith('image/')) {
const objectURL = URL.createObjectURL(blob);
setIconPreview(objectURL);
setIsIconValid(true);
} else {
throw new Error('Invalid image format');
}
})
.catch(() => {
setIconPreview(null);
setIsIconValid(false);
});
} else {
setIconPreview(null);
setIsIconValid(true);
}
}, [requiredMeta.federation_icon_url]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling and prevent memory leaks.

Consider the following suggestions:

  1. Provide more specific error messages for different failure scenarios, such as invalid URL, network error, or invalid image format. This will help with debugging and error tracking.
  2. Revoke the objectURL using URL.revokeObjectURL when the component unmounts or the icon URL changes to prevent memory leaks.

@Kodylow
Copy link
Member Author

Kodylow commented Sep 6, 2024

#506 <- addresses

Copy link

vercel bot commented Sep 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2024 1:01pm

@Kodylow
Copy link
Member Author

Kodylow commented Sep 17, 2024

@sbddesign this is rebased onto the new UI so is good to test now

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
apps/router/src/guardian-ui/components/dashboard/tabs/meta/MetaManager.tsx (1)

139-168: LGTM!

The proposeMetaEdits function logic looks good. It validates the form, prepares the updated metadata, and handles the API submission correctly.

Consider improving the error handling by showing a more user-friendly error message instead of the generic "Failed to propose meta edits. Please try again." alert. You could parse the error response and display a specific message based on the error type.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 57fd133 and ab60569.

Files selected for processing (13)
  • apps/router/src/guardian-ui/components/dashboard/tabs/FederationTabsCard.tsx (6 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ConfirmNewMetaModal.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/MetaManager.tsx (2 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/NoPendingProposals.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposeMetaModal.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposedMetas.tsx (5 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/RequiredMeta.tsx (1 hunks)
  • apps/router/src/guardian-ui/components/dashboard/tabs/meta/ViewConsensusMeta.tsx (3 hunks)
  • apps/router/src/guardian-ui/components/setup/screens/connectGuardians/ConnectGuardians.tsx (1 hunks)
  • apps/router/src/guardian-ui/utils/index.ts (1 hunks)
  • apps/router/src/languages/en.json (1 hunks)
  • packages/types/src/meta.ts (1 hunks)
  • packages/utils/src/index.tsx (1 hunks)
Additional comments not posted (23)
packages/types/src/meta.ts (1)

22-25: LGTM!

The new ParsedConsensusMeta interface provides a more structured and type-safe way to handle parsed metadata values.

packages/utils/src/index.tsx (2)

32-37: LGTM!

The snakeToTitleCase function logic is correct, and the implementation is accurate.


39-44: LGTM!

The titleToSnakeCase function logic is correct, and the implementation is accurate.

apps/router/src/guardian-ui/components/dashboard/tabs/meta/ViewConsensusMeta.tsx (2)

7-9: LGTM!

The simplification of the component props is a good change. It makes the component more focused and easier to use.


50-59: LGTM!

The simplified rendering logic is easier to understand and maintain. Good job!

apps/router/src/guardian-ui/components/dashboard/tabs/meta/ConfirmNewMetaModal.tsx (1)

1-78: LGTM!

The ConfirmNewMetaModal component is well-structured, follows best practices, and uses appropriate libraries for UI components and translations. The code is readable and maintainable. No issues or improvements identified.

apps/router/src/guardian-ui/utils/index.ts (1)

81-88: LGTM!

The isJsonString function correctly checks if a string is valid JSON by attempting to parse it and handling any parsing errors. The implementation looks good.

apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposeMetaModal.tsx (1)

1-105: LGTM, no issues found.

apps/router/src/guardian-ui/components/setup/screens/connectGuardians/ConnectGuardians.tsx (1)

67-72: LGTM! The responsive minW change looks good.

apps/router/src/guardian-ui/components/dashboard/tabs/meta/MetaManager.tsx (4)

1-17: LGTM!

The imports, utility function, and interface changes look good.


41-93: LGTM!

The state management and utility functions look good. The logic is clear and handles the necessary checks.


95-137: LGTM!

The form submission and field handling utility functions are well-structured and the logic is sound. The dynamic custom field functionality is a nice addition.


170-239: LGTM!

The component UI is well-structured and the rendering logic is implemented correctly. The dynamic rendering of optional fields and the conditional rendering of form action buttons based on the form state are handled properly.

apps/router/src/guardian-ui/components/dashboard/tabs/FederationTabsCard.tsx (4)

59-65: LGTM!

The new state variables for managing consensus metadata, submissions, and tab state are necessary for the enhanced functionality.


67-108: LGTM!

The pollMetaSubmissions function is a key addition that effectively retrieves and organizes meta submissions from the API. It enables tracking of peer submissions and the current peer's voting status.


120-151: LGTM!

The polling effect for consensus metadata is well-implemented with optimizations to prevent unnecessary updates when there are no changes.


176-215: LGTM!

The UI enhancements with new tabs and badge for pending proposals improve the visibility and user engagement with the metadata management features.

apps/router/src/guardian-ui/components/dashboard/tabs/meta/ProposedMetas.tsx (1)

Line range hint 1-336: LGTM!

The refactoring improves the component's clarity, maintainability, and responsiveness. The changes enhance the handling of meta submissions and introduce a more modular approach for user interactions. No major issues or problems are apparent.

apps/router/src/languages/en.json (4)

91-91: LGTM!


98-99: LGTM!


102-104: LGTM!


111-118: LGTM!

apps/router/src/guardian-ui/components/dashboard/tabs/meta/NoPendingProposals.tsx (1)

1-41: LGTM!

The NoPendingProposals component is well-implemented and follows best practices. It effectively communicates the absence of pending proposals and guides users to propose new metadata.

Comment on lines 1 to 136
setIconPreview(null);
setIsIconValid(false);
if (error instanceof Error) {
console.error(`Icon validation failed: ${error.message}`);
}
}
};

if (requiredMeta.federation_icon_url) {
validateIcon(requiredMeta.federation_icon_url);
} else {
setIconPreview(null);
setIsIconValid(true);
}

return () => {
if (objectURL) {
URL.revokeObjectURL(objectURL);
}
};
}, [requiredMeta.federation_icon_url]);

useEffect(() => {
setIsValid(isIconValid);
}, [isIconValid, setIsValid]);

const handleChange = (key: string, value: string) => {
setRequiredMeta((prev) => ({ ...prev, [key]: value }));
};

return (
<Flex flexDirection='column' gap={4}>
{Object.entries(requiredMeta).map(([key, value]) => (
<Flex key={key} alignItems='center'>
<Flex flexDirection='column' flex={1}>
<FormLabel fontWeight='bold' mb={1}>
{snakeToTitleCase(key)}
</FormLabel>
<Flex alignItems='center'>
<Input
type={
key === 'popup_end_timestamp'
? 'datetime-local'
: key === 'federation_icon_url'
? 'url'
: 'text'
}
value={value}
onChange={(e) => handleChange(key, e.target.value)}
borderColor={
(['federation_name', 'welcome_message'].includes(key) &&
value.trim() === '') ||
(key === 'federation_icon_url' && !isIconValid)
? 'yellow.400'
: 'inherit'
}
/>
{key === 'federation_icon_url' && (
<Flex
ml={2}
alignItems='center'
justifyContent='center'
width='36px'
height='36px'
borderRadius='full'
overflow='hidden'
boxShadow='sm'
bg='gray.100'
flexShrink={0}
>
{iconPreview ? (
<Image
src={iconPreview}
alt='Federation Icon'
width='100%'
height='100%'
objectFit='cover'
/>
) : (
<Flex
width='100%'
height='100%'
alignItems='center'
justifyContent='center'
fontSize='md'
fontWeight='bold'
color='gray.400'
>
?
</Flex>
)}
</Flex>
)}
</Flex>
</Flex>
</Flex>
))}
</Flex>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring the component for better maintainability and reusability.

The RequiredMeta component is quite large and could benefit from being broken down into smaller, reusable components. For example, you could extract the icon preview and validation logic into a separate component.

Additionally, consider moving the icon URL validation logic into a separate utility function to keep the component focused on rendering and state management.

Lastly, instead of directly updating the parent's validity state, you could consider having the component manage its own validity state internally and expose it through a callback prop. This would make the component more reusable and less coupled to the parent's state.

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.

1 participant