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

Merged
merged 4 commits into from
Sep 20, 2024
Merged

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

    • Added new buttons for adding custom fields and resetting to consensus in metadata management.
    • Introduced a new label for "view-meta" to enhance metadata functionalities.
  • Improvements

    • Simplified labels for "API Announcements" and "view-config" to improve user understanding.
    • Enhanced descriptions and headers for metadata management to provide better context.
  • User Interface Updates

    • Updated labels and descriptions in the language configuration for clarity and consistency.

@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 involve updates to the user interface's JSON configuration, focusing on improving labels and descriptions related to API and metadata management. Key modifications include renaming existing labels for clarity, adding new labels for enhanced functionality, and providing context for metadata management. These adjustments aim to streamline user understanding and improve the overall organization of the metadata section.

Changes

File(s) Change Summary
apps/guardian-ui/src/languages/en.json Updated labels and descriptions for API and metadata management, including renaming and adding new labels, enhancing clarity and functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as User Interface
    participant MetaManager

    User->>UI: Open metadata management
    UI->>MetaManager: Load metadata
    MetaManager->>UI: Display metadata fields
    User->>UI: Propose new metadata
    UI->>MetaManager: Send proposed edits
    MetaManager->>UI: Update displayed metadata
    User->>UI: Confirm new metadata
    UI->>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 5e5d20c and b7a4cd2.

Files selected for processing (1)
  • apps/router/src/languages/en.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/router/src/languages/en.json

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 20, 2024 6:03pm

@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.

@Kodylow Kodylow merged commit 2d1dc36 into fedimint:master Sep 20, 2024
3 checks passed
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.

2 participants