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

view shelter 2 (DEV-1079) #781

Merged
merged 5 commits into from
Dec 17, 2024
Merged

view shelter 2 (DEV-1079) #781

merged 5 commits into from
Dec 17, 2024

Conversation

Davit-BetterAngels
Copy link
Contributor

@Davit-BetterAngels Davit-BetterAngels commented Dec 16, 2024

DEV-1079

Summary by Sourcery

Enhance the shelter page by introducing new components for modularity and readability, including Button, Pill, CardWrapper, and various shelter-specific components. Update enum display mappings and global styles to support these changes. Specify Yarn as the package manager in the project configuration.

New Features:

  • Introduce a new 'Button' component with customizable size and variant options.
  • Add a 'Pill' and 'PillContainer' component for displaying categorized information in a compact form.
  • Implement a 'CardWrapper' component for consistent card styling across the application.
  • Create a 'Header' component for displaying shelter information in a structured format.
  • Add 'EntryRequirements', 'GeneralInfo', 'OperationHours', 'RoomStyles', 'ShelterTypes', and 'SpecialRestrictions' components to enhance the shelter page.

Enhancements:

  • Refactor the shelter page to use new components for better modularity and readability.
  • Update enum display mappings to include additional choices for shelter-related categories.

Build:

  • Add new color variables to the global CSS and Tailwind configuration for consistent styling.

Chores:

  • Update package.json to specify the use of Yarn as the package manager.

Copy link

sourcery-ai bot commented Dec 16, 2024

Reviewer's Guide by Sourcery

This PR implements the shelter view page UI, introducing new reusable React components and enum display mappings. The implementation includes multiple sections for displaying shelter information such as general info, entry requirements, special restrictions, and room styles. The changes also include styling updates and new color variables.

Class diagram for new React components

classDiagram
    class Button {
        +size: 'sm' | 'md' | 'lg'
        +variant: 'primary' | 'secondary'
        +Button(props: IButtonProps)
    }
    class CardWrapper {
        +children: ReactNode
        +px: 'px-0' | 'px-6'
        +pb: 'pb-0' | 'pb-6'
        +title: string
        +CardWrapper(props: ICardWrapperProps)
    }
    class Pill {
        +type: 'success'
        +label: string
        +Pill(props: IPillProps)
    }
    class PillContainer {
        +data: string[]
        +type: 'success'
        +maxVisible: number
        +PillContainer(props: IPillContainerProps)
    }
    Button --> CardWrapper
    PillContainer --> Pill
Loading

Class diagram for Shelter Page components

classDiagram
    class Header {
        +Header(shelter: ViewShelterQuery['shelter'])
    }
    class OperationHours {
        +OperationHours()
    }
    class Actions {
        +Actions()
    }
    class EntryRequirements {
        +EntryRequirements(shelter: ViewShelterQuery['shelter'])
    }
    class GeneralInfo {
        +GeneralInfo(shelter: ViewShelterQuery['shelter'])
    }
    class GeneralServices {
        +GeneralServices(shelter: ViewShelterQuery['shelter'])
    }
    class SpecialRestrictions {
        +SpecialRestrictions(shelter: ViewShelterQuery['shelter'])
    }
    class ShelterTypes {
        +ShelterTypes(shelter: ViewShelterQuery['shelter'])
    }
    class RoomStyles {
        +RoomStyles(shelter: ViewShelterQuery['shelter'])
    }
    GeneralInfo --> GeneralServices
    ShelterPage --> Header
    ShelterPage --> OperationHours
    ShelterPage --> Actions
    ShelterPage --> EntryRequirements
    ShelterPage --> GeneralInfo
    ShelterPage --> SpecialRestrictions
    ShelterPage --> ShelterTypes
    ShelterPage --> RoomStyles
Loading

File-Level Changes

Change Details Files
Created new reusable React components for the UI
  • Added Button component with primary/secondary variants and size options
  • Created CardWrapper component for consistent card styling
  • Implemented Pill and PillContainer components for displaying tags
  • Set up component library structure with proper exports
libs/react/components/src/lib/Button/Button.tsx
libs/react/components/src/lib/CardWrapper/CardWrapper.tsx
libs/react/components/src/lib/Pill/Pill.tsx
libs/react/components/src/lib/PillContainer/PillContainer.tsx
Implemented shelter view page with multiple information sections
  • Created Header component for shelter name and demographics
  • Added GeneralInfo section with services and contact information
  • Implemented EntryRequirements section
  • Added SpecialRestrictions section
  • Created RoomStyles and ShelterTypes sections
  • Added OperationHours component
libs/react/shelter/src/lib/pages/shelter/index.tsx
libs/react/shelter/src/lib/pages/shelter/Header.tsx
libs/react/shelter/src/lib/pages/shelter/GeneralInfo/index.tsx
libs/react/shelter/src/lib/pages/shelter/EntryRequirements.tsx
libs/react/shelter/src/lib/pages/shelter/SpecialRestrictions.tsx
libs/react/shelter/src/lib/pages/shelter/RoomStyles.tsx
libs/react/shelter/src/lib/pages/shelter/ShelterTypes.tsx
libs/react/shelter/src/lib/pages/shelter/OperationHours.tsx
Added enum display mappings for various shelter attributes
  • Created mappings for general service choices
  • Added mappings for entry requirements
  • Implemented mappings for special situation restrictions
  • Added mappings for shelter types and room styles
libs/react/shelter/src/lib/static/enumDisplayMapping.ts
Updated styling configuration
  • Added new neutral and success color variables
  • Updated Tailwind configuration with new color definitions
apps/shelter-web/src/assets/styles/global.css
apps/shelter-web/tailwind.config.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Davit-BetterAngels - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Avoid using dangerouslySetInnerHTML with string concatenation as it poses security risks (link)

Overall Comments:

  • There's a typo in the 'Special Situatioin Restrictions' title that should be fixed
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

{shelter?.entryInfo && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Avoid using dangerouslySetInnerHTML with string concatenation as it poses security risks

Consider using regular JSX with template literals instead, like:

Entry Info: {shelter?.entryInfo}

}) {
if (!shelter?.specialSituationRestrictions?.length) return null;
return (
<CardWrapper title="Special Situatioin Restictions">
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): Fix typo in CardWrapper title

Suggested change
<CardWrapper title="Special Situatioin Restictions">
<CardWrapper title="Special Situation Restrictions">

<div className="pb-6">
<PillContainer
maxVisible={5}
data={
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider simplifying the data transformation using filter and map instead of reduce for improved readability.

The data transformation can be simplified while maintaining all safety checks. Using filter() and map() makes the intent clearer than reduce() here since we're transforming data rather than accumulating it.

data={
  shelter?.generalServices
    ?.filter(service => service.name && enumDisplayGeneralServiceChoices[service.name])
    .map(service => enumDisplayGeneralServiceChoices[service.name]) ?? []
}

This maintains all null checks while being more direct about the data flow: first filter out invalid services, then transform the remaining ones.

<CardWrapper title="Entry Requirements">
<div className="flex flex-col gap-2">
{shelter?.entryRequirements.map((requirement, idx) => {
if (!requirement.name) return null;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!requirement.name) return null;
if (!requirement.name) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

if (service.name) {
const displayName =
enumDisplayGeneralServiceChoices[service.name];
if (displayName) acc.push(displayName);
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (displayName) acc.push(displayName);
if (displayName) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

}: {
shelter?: ViewShelterQuery['shelter'];
}) {
if (!shelter?.roomStyles?.length) return null;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!shelter?.roomStyles?.length) return null;
if (!shelter?.roomStyles?.length) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

}: {
shelter?: ViewShelterQuery['shelter'];
}) {
if (!shelter?.shelterTypes?.length) return null;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!shelter?.shelterTypes?.length) return null;
if (!shelter?.shelterTypes?.length) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

}: {
shelter?: ViewShelterQuery['shelter'];
}) {
if (!shelter?.specialSituationRestrictions?.length) return null;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!shelter?.specialSituationRestrictions?.length) return null;
if (!shelter?.specialSituationRestrictions?.length) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

const baseClasses = 'rounded-[20px] inline-flex items-center justify-center';

const typeClasses = {
success: 'bg-success-90 text-primary-20 px-4 py-1',
Copy link
Contributor

Choose a reason for hiding this comment

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

the color success-90 is only defined in the context of shelter-web. that's ok for today, but we may need add global tailwind config file in libs somwhere. for now maybe just leave a TODO comment?

also, should px-4 py-1 go with baseClasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddings no because if border comes the size will be different

Copy link
Contributor

Choose a reason for hiding this comment

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

aaah ok.

if a different variant can have a border, then another way is to include border in baseClasses (with same color as background), and then just override the border-color. but not necessary

success: 'bg-success-90 text-primary-20 px-4 py-1',
};

const pillClass = clsx(baseClasses, typeClasses[type], className);
Copy link
Contributor

Choose a reason for hiding this comment

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

just FYI: twMerge together with clsx (like in mergeCss) can be really useful here

to allow className to override everyting:
const pillClass = mergeCss(baseClasses, typeClasses[type], className);

to allow adding className, but never overriding baseClasses or typeClasses[type]:
const pillClass = mergeCss(className, baseClasses, typeClasses[type]);

libs/react/components/src/lib/CardWrapper/CardWrapper.tsx Outdated Show resolved Hide resolved
libs/react/components/src/lib/CardWrapper/CardWrapper.tsx Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Dec 17, 2024

🚀 Expo continuous deployment is ready for betterangels!

  • Project → betterangels
  • Environment → Preview
  • Platforms → android, ios
  • Scheme → betterangels
  🤖 Android 🍎 iOS
Runtime Version 17ec4c804e86216b10e381df8e376b90a2b23764 17ec4c804e86216b10e381df8e376b90a2b23764
Build Details Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview
Runtime version: 17ec4c804e86216b10e381df8e376b90a2b23764
App version: 1.0.31
Git commit: 84fa12683902a7d148acf71a8b8d3fbdde9d6c45
Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview
Runtime version: 17ec4c804e86216b10e381df8e376b90a2b23764
App version: 1.0.31
Git commit: 84fa12683902a7d148acf71a8b8d3fbdde9d6c45
Update Details Update Permalink
DetailsBranch: DEV-1079/view-shelter-2
Runtime version: 17ec4c804e86216b10e381df8e376b90a2b23764
Git commit: 32c9b011d3942d4aea1393e4c012382ee5ecc006
Update Permalink
DetailsBranch: DEV-1079/view-shelter-2
Runtime version: 17ec4c804e86216b10e381df8e376b90a2b23764
Git commit: 32c9b011d3942d4aea1393e4c012382ee5ecc006
Update QR

iOS Simulator Build: Simulator Build Link

@Davit-BetterAngels Davit-BetterAngels merged commit 78ee5fd into main Dec 17, 2024
8 checks passed
@Davit-BetterAngels Davit-BetterAngels deleted the DEV-1079/view-shelter-2 branch December 17, 2024 21:10
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