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

best deals expansions #492

Merged
merged 3 commits into from
Sep 2, 2024
Merged

best deals expansions #492

merged 3 commits into from
Sep 2, 2024

Conversation

cohenaj194
Copy link
Contributor

@cohenaj194 cohenaj194 commented Sep 2, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new property for handling expansion-related data in the deals form.
    • Enhanced dropdown menu terminology to reflect a broader scope of content available.
    • Updated the focus of deals from "Dragonflight" to "The War Within" (TWW), including rebranding of queries and recipes.

These changes improve the user experience by allowing for more nuanced filtering of deals and clearer content categorization, while promoting the latest offerings.

Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes introduce an expansionNumber property to the defaultFormValues object in the app/routes/wow.best-deals._index.tsx file, initialized to -1. Additionally, the label in the BestDeals component's dropdown menu is updated from 'Dragonflight Only' to 'Current Content'. In the app/routes/wow.best-deals.recommended.tsx file, references to "Dragonflight" are replaced with "The War Within" (TWW), including updates to the searchParams and recommendedQueries. These adjustments enhance the data structure and user interface of the component.

Changes

Files Change Summary
app/routes/wow.best-deals._index.tsx Added expansionNumber: -1 to defaultFormValues; updated dropdown label from 'Dragonflight Only' to 'Current Content'.
app/routes/wow.best-deals.recommended.tsx Updated searchParams keys from defaultDragonflight to defaultTWW and dragonflightRecipes to recipesTWW; modified recommendedQueries entries from 'Default Dragonflight Deals' to 'Default TWW Deals' and 'Dragonflight Recipes' to 'TWW Recipes'.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Form
    participant Dropdown

    User->>Form: Open Best Deals Form
    Form->>Dropdown: Load Options
    Dropdown->>Form: Display Options (Current Content)
    User->>Form: Select Option
    Form->>Dropdown: Update Selection
    Dropdown->>Form: Confirm Selection
Loading

🐰 In the meadow, changes bloom,
A dropdown shifts, dispelling gloom.
Expansion number, set to play,
New content shines, brightens the day!
Hops of joy, in fields we roam,
With every deal, we feel at home! 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

@@ -34,7 +34,8 @@ const defaultFormValues = {
itemSubClass: '-1',
discount: '90',
minPrice: '2000',
salesPerDay: '1.1'
salesPerDay: '1.1',
expansionNumber: '-1'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coderabbitai tell me exactly what files to update and changes that need to be made

it will be similar to this pr #485

Copy link
Contributor

Choose a reason for hiding this comment

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

@cohenaj194, here are the files that need to be updated to integrate the expansionNumber parameter into the wow.best-deals._index.tsx route, similar to the changes made in PR #485:

  1. app/routes/wow.best-deals._index.tsx:

    • Loader Function: Update the loader function to include expansionNumber in the values object and validate it using parseStringToNumber.
    • Action Function: Ensure that the expansionNumber is passed to the WoWBestDeals API request.
    • Form Handling: Add a new form field for expansionNumber in the form component, similar to how it's done in wow.marketshare._index.tsx.
  2. app/components/form/WoW/WoWScanForm.tsx:

    • Form Field: Add a form field for expansionNumber if it’s not already present. This will allow users to select the expansion number when searching for best deals.
  3. app/requests/WoW/BestDeals.ts:

    • API Request: Ensure that the expansionNumber is included in the API request payload, similar to how it’s done in ItemStatLookup.ts.

These changes will ensure that the expansionNumber parameter is correctly integrated and handled throughout the wow.best-deals._index.tsx route.

Let me know if you need further assistance!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to `expansionNumber` in the codebase to identify where it needs to be added or updated.
rg 'expansionNumber'

Length of output: 1299


Learnings added
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.642Z
Learning: When adding the `expansionNumber` parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the `wow.marketshare._index.tsx` route.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


Learnings used
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.

Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok lets start with app/routes/wow.best-deals._index.tsx can you make me a full updated version?

Copy link
Contributor

Choose a reason for hiding this comment

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

@cohenaj194, here is the full updated version of the app/routes/wow.best-deals._index.tsx file with the necessary changes to integrate the expansionNumber parameter:

import type { ActionFunction, LoaderFunction } from '@remix-run/cloudflare'
import { json } from '@remix-run/cloudflare'
import { useEffect, useState } from 'react'
import { PageWrapper } from '~/components/Common'
import SmallFormContainer from '~/components/form/SmallFormContainer'
import type { DealItem, WoWDealResponse } from '~/requests/WoW/BestDeals'
import WoWBestDeals from '~/requests/WoW/BestDeals'
import { getUserSessionData } from '~/sessions'
import z from 'zod'
import { useActionData, useLoaderData, useNavigation } from '@remix-run/react'
import { InputWithLabel } from '~/components/form/InputWithLabel'
import Select from '~/components/form/select'
import NoResults from '~/components/Common/NoResults'
import SmallTable from '~/components/WoWResults/FullScan/SmallTable'
import type { ColumnList } from '~/components/types'
import ExternalLink from '~/components/utilities/ExternalLink'
import { ItemClassSelect } from '~/components/form/WoW/WoWScanForm'
import {
  parseStringToNumber,
  parseZodErrorsToDisplayString
} from '~/utils/zodHelpers'
import {
  getActionUrl,
  handleCopyButton,
  handleSearchParamChange
} from '~/utils/urlSeachParamsHelpers'
import { SubmitButton } from '~/components/form/SubmitButton'

const PAGE_URL = '/wow/best-deals'

const defaultFormValues = {
  type: 'df',
  itemClass: '-1',
  itemSubClass: '-1',
  discount: '90',
  minPrice: '2000',
  salesPerDay: '1.1',
  expansionNumber: '-1' // Added expansionNumber to defaultFormValues
}

const inputMap: Record<string, string> = {
  type: 'Item Type',
  itemClass: 'Item Class',
  itemSubClass: 'Item Subclass',
  discount: 'Discount Percentage',
  minPrice: 'Minimum TSM Average Price',
  salesPerDay: 'Sales Per Day',
  expansionNumber: 'Expansion Number' // Added expansionNumber to inputMap
}

const validateInput = z.object({
  type: z.string(),
  itemClass: parseStringToNumber,
  itemSubClass: parseStringToNumber,
  discount: parseStringToNumber,
  minPrice: parseStringToNumber,
  salesPerDay: z
    .string()
    .min(1)
    .transform((value) => parseFloat(value)),
  expansionNumber: parseStringToNumber // Added validation for expansionNumber
})

// Overwrite default meta in the root.tsx
export const meta: MetaFunction = () => {
  return {
    charset: 'utf-8',
    viewport: 'width=device-width,initial-scale=1',
    title: 'Saddlebag Exchange: WoW Auctionhouse Best Deals',
    description:
      'Find the best deals on every auctionhouse region wide with our WoW Best Deals search!'
  }
}

export const links: LinksFunction = () => [
  { rel: 'canonical', href: 'https://saddlebagexchange.com/wow/best-deals' }
]

export const loader: LoaderFunction = async ({ request }) => {
  const params = new URL(request.url).searchParams

  const values = {
    type: params.get('type') || defaultFormValues.type.toString(),
    itemClass:
      params.get('itemClass') || defaultFormValues.itemClass.toString(),
    itemSubClass:
      params.get('itemSubClass') || defaultFormValues.itemSubClass.toString(),
    discount: params.get('discount') || defaultFormValues.discount.toString(),
    minPrice: params.get('minPrice') || defaultFormValues.minPrice.toString(),
    salesPerDay:
      params.get('salesPerDay') || defaultFormValues.salesPerDay.toString(),
    expansionNumber:
      params.get('expansionNumber') || defaultFormValues.expansionNumber.toString() // Added expansionNumber to loader values
  }
  const validParams = validateInput.safeParse(values)
  if (!validParams.success) {
    return json({
      exception: parseZodErrorsToDisplayString(validParams.error, inputMap)
    })
  }
  return json(validParams.data)
}

export const action: ActionFunction = async ({ request }) => {
  const session = await getUserSessionData(request)

  const region = session.getWoWSessionData().region

  const formData = Object.fromEntries(await request.formData())

  const validatedFormData = validateInput.safeParse(formData)
  if (!validatedFormData.success) {
    return json({
      exception: parseZodErrorsToDisplayString(
        validatedFormData.error,
        inputMap
      )
    })
  }

  const result = await WoWBestDeals({
    region,
    ...validatedFormData.data
  })

  // await the result and then return the json

  return json({
    ...(await result.json()),
    sortby: 'discount'
  })
}

type ActionResponseType =
  | {}
  | { exception: string }
  | (WoWDealResponse & { sortby: string })

const BestDeals = () => {
  const loaderData = useLoaderData<typeof defaultFormValues>()
  const result = useActionData<ActionResponseType>()
  const transistion = useNavigation()

  const isSubmitting = transistion.state === 'submitting'

  const [searchParams, setSearchParams] = useState<typeof defaultFormValues>({
    ...loaderData
  })
  const error = result && 'exception' in result ? result.exception : undefined

  if (result && !Object.keys(result).length) {
    return <NoResults href={PAGE_URL} />
  }

  if (result && 'data' in result && !error) {
    return <Results {...result} />
  }

  const handleSubmit = (
    event: React.MouseEvent<HTMLButtonElement, MouseEvent>
  ) => {
    if (isSubmitting) {
      event.preventDefault()
    }
  }

  const handleFormChange = (
    name: keyof typeof defaultFormValues,
    value: string
  ) => {
    handleSearchParamChange(name, value)
    setSearchParams((prev) => ({ ...prev, [name]: value }))
  }

  return (
    <PageWrapper>
      <SmallFormContainer
        title="Best Deals"
        description="Find the best deals on your server and region wide with our Best Deals search!"
        onClick={handleSubmit}
        error={error}
        loading={isSubmitting}
        action={getActionUrl(PAGE_URL, searchParams)}>
        <div className="pt-2">
          <div className="flex justify-end mb-2">
            <SubmitButton
              title="Share this search!"
              onClick={handleCopyButton}
              type="button"
            />
          </div>
        </div>
        <div className="pt-3 flex flex-col">
          <Select
            title="Item Type"
            name="type"
            defaultValue={loaderData.type}
            options={[
              { label: 'Current Content', value: 'df' },
              { label: 'Pets Only', value: 'pets' },
              { label: 'Legacy Only', value: 'legacy' },
              { label: 'All', value: 'all' }
            ]}
            onChange={(e) => handleFormChange('type', e.target.value)}
          />
          <ItemClassSelect
            itemClass={parseInt(loaderData.itemClass)}
            itemSubClass={parseInt(loaderData.itemSubClass)}
            onChange={(itemClassValue, itemSubClassValue) => {
              handleFormChange('itemClass', itemClassValue.toString())
              handleFormChange('itemSubClass', itemSubClassValue.toString())
            }}
          />
          <InputWithLabel
            labelTitle="Discount Percentage"
            name="discount"
            type="number"
            defaultValue={loaderData.discount}
            min={0}
            onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
              handleFormChange('discount', e.currentTarget.value)
            }
          />
          <InputWithLabel
            labelTitle="Minimum TSM Average Price"
            name="minPrice"
            type="number"
            defaultValue={loaderData.minPrice}
            min={0}
            onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
              handleFormChange('minPrice', e.currentTarget.value)
            }
          />
          <InputWithLabel
            labelTitle="Sales Per Day"
            name="salesPerDay"
            type="number"
            defaultValue={loaderData.salesPerDay}
            step={0.01}
            min={0}
            onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
              handleFormChange('salesPerDay', e.currentTarget.value)
            }
          />
          <InputWithLabel
            labelTitle="Expansion Number"
            name="expansionNumber"
            type="number"
            defaultValue={loaderData.expansionNumber}
            min={-1}
            onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
              handleFormChange('expansionNumber', e.currentTarget.value)
            }
          />
        </div>
      </SmallFormContainer>
    </PageWrapper>
  )
}

export default BestDeals

const Results = ({ data, sortby }: WoWDealResponse & { sortby: string }) => {
  useEffect(() => {
    if (window && document) {
      window.scroll({ top: 0, behavior: 'smooth' })
    }
  }, [])
  return (
    <PageWrapper>
      <SmallTable
        title="Best Deals"
        sortingOrder={[{ desc: true, id: sortby }]}
        columnList={columnList}
        mobileColumnList={mobileColumnList}
        columnSelectOptions={[
          'discount',
          'salesPerDay',
          'minPrice',
          'historicPrice'
        ]}
        data={data}
        csvOptions={{
          filename: 'saddlebag-best-deals.csv',
          columns: [
            { title: 'Item ID', value: 'itemID' },
            { title: 'Item Name', value: 'itemName' },
            { title: 'Min Price', value: 'minPrice' },
            { title: 'Historic Price', value: 'historicPrice' },
            { title: 'Min Price', value: 'Sales Per Day' },
            { title: 'Discount', value: 'discount' },
            { title: 'Realm', value: 'realmName' },
            { title: 'Connected Realm ID', value: 'connectedRealmId' }
          ]
        }}
      />
    </PageWrapper>
  )
}

const columnList: Array<ColumnList<DealItem>> = [
  { columnId: 'itemName', header: 'Item Name' },
  {
    columnId: 'realmName',
    header: 'Realm Name',
    accessor: ({ row }) => (
      <p className=" px-3 py-2 max-w-[200px] overflow-x-scroll">
        {row.realmName}
      </p>
    )
  },
  {
    columnId: 'exportLink',
    header: 'Where to Sell',
    accessor: ({ getValue }) => <ExternalLink link={getValue() as string} />
  },
  {
    columnId: 'link',
    header: 'Undermine Link',
    accessor: ({ getValue }) => <ExternalLink link={getValue() as string} />
  },
  { columnId: 'discount', header: 'Discount' },
  { columnId: 'salesPerDay', header: 'Sales Per Day' },
  { columnId: 'minPrice', header: 'Minimum Price' },
  { columnId: 'historicPrice', header: 'Historic Price' }
]

const mobileColumnList: Array<ColumnList<DealItem>> = [
  { columnId: 'discount', header: 'Discount' },
  { columnId: 'itemName', header: 'Item Name' }
]

This updated version includes the necessary changes to integrate the expansionNumber parameter into the loader and action functions, form components, and API requests, as discussed. Let me know if you need any further adjustments!


Learnings used
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.

Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the `expansionNumber` parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the `wow.marketshare._index.tsx` route.

Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.

Copy link
Contributor Author

@cohenaj194 cohenaj194 Sep 2, 2024

Choose a reason for hiding this comment

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

@coderabbitai add to your memory that I want to use ExpansionSelect from ./app/components/form/WoW/WoWScanForm.tsx when adding expansion buttons to web forms

<ExpansionSelect
  defaultValue={loaderData.expansionNumber}
  onChange={(value) => handleFormChange('expansionNumber', value)}
/>

Copy link
Contributor

Choose a reason for hiding this comment

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

@cohenaj194, I've added your preference to use the ExpansionSelect component from ./app/components/form/WoW/WoWScanForm.tsx whenever possible to my memory. This will be taken into account in future reviews.


Learnings added
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:29:36.785Z
Learning: User: cohenaj194 prefers to use the `ExpansionSelect` component from `./app/components/form/WoW/WoWScanForm.tsx` whenever possible. The component should be used as shown in the following code snippet:

```typescript
<ExpansionSelect
  defaultValue={loaderData.expansionNumber}
  onChange={(value) => handleFormChange('expansionNumber', value)}
/>

> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>

---

<details>
<summary>Learnings used</summary>

Learnt from: cohenaj194
PR: #492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the expansionNumber parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the wow.marketshare._index.tsx route.


---

Learnt from: cohenaj194
PR: #485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the expansion_number parameter is mapped correctly to the expansion names and that the default value is -1.


---

Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.


</details>

<!-- This is an auto-generated reply by CodeRabbit -->

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc6a840 and 9e9a5e1.

Files selected for processing (1)
  • app/routes/wow.best-deals._index.tsx (2 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.
app/routes/wow.best-deals._index.tsx (1)
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.
Additional comments not posted (2)
app/routes/wow.best-deals._index.tsx (2)

37-38: LGTM! Consider completing the implementation of expansionNumber.

The addition of expansionNumber with a default value of '-1' is correct and aligns with the previous learnings. However, there are a few points to consider:

  1. The expansionNumber is not used elsewhere in the visible code. Ensure that it's properly implemented in the BestDeals component.
  2. Update the validateInput schema to include expansionNumber. This will ensure proper validation when the form is submitted.

To verify the usage of expansionNumber, run the following script:


195-195: LGTM! Consider updating the option value to match the new label.

The change from 'Dragonflight Only' to 'Current Content' is a good improvement, making the label more generic and future-proof. However, there are a couple of points to consider:

  1. The value for this option is still 'df', which might be confusing or outdated. Consider updating it to a more generic value, such as 'current'.
  2. Ensure that this change is reflected in any other parts of the application that might be using the 'df' value for filtering or processing.

To verify the impact of this change and find any potential areas that need updating, run the following script:

Copy link

cloudflare-workers-and-pages bot commented Sep 2, 2024

Deploying saddlebag-with-pockets with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4125d67
Status: ✅  Deploy successful!
Preview URL: https://f3101210.saddlebag-with-pockets.pages.dev
Branch Preview URL: https://fix-wow-best-expansion-numbe.saddlebag-with-pockets.pages.dev

View logs

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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e9a5e1 and 88c28c0.

Files selected for processing (1)
  • app/routes/wow.best-deals.recommended.tsx (6 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the `expansionNumber` parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the `wow.marketshare._index.tsx` route.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.
app/routes/wow.best-deals.recommended.tsx (1)
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the `expansionNumber` parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the `wow.marketshare._index.tsx` route.

Comment on lines +25 to +26
defaultTWW:
'/wow/best-deals?type=df&itemClass=-1&itemSubClass=-1&discount=50&minPrice=2000&salesPerDay=1.1&expansionNumber=11',
Copy link
Contributor

Choose a reason for hiding this comment

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

Update searchParams object to reflect new expansion

The searchParams object has been updated to replace "Dragonflight" references with "TWW" (The War Within). The expansionNumber=11 parameter has been added to the URLs.

However, consider the following suggestions:

  1. Update the illusionsAndConsumables URL to include the expansionNumber=11 parameter for consistency.
  2. Consider adding a comment explaining what the expansionNumber represents for better code readability.

Example:

 const searchParams = {
   defaultTWW:
     '/wow/best-deals?type=df&itemClass=-1&itemSubClass=-1&discount=50&minPrice=2000&salesPerDay=1.1&expansionNumber=11',
   // ... other params ...
   recipesTWW:
     '/wow/best-deals?type=df&itemClass=9&itemSubClass=-1&discount=50&minPrice=10000&salesPerDay=0.1&expansionNumber=11',
   // ... other params ...
-  illusionsAndConsumables:
-    '/wow/best-deals?type=df&itemClass=0&itemSubClass=-1&discount=50&minPrice=100&salesPerDay=0.1',
+  illusionsAndConsumables:
+    '/wow/best-deals?type=df&itemClass=0&itemSubClass=-1&discount=50&minPrice=100&salesPerDay=0.1&expansionNumber=11',
   // ... other params ...
 }

Also applies to: 37-38

Comment on lines +82 to +85
name: 'Default TWW Deals',
description: 'Find deals on current content.',
Icon: DocumentSearchIcon,
href: searchParams.defaultDragonflight
href: searchParams.defaultTWW
Copy link
Contributor

Choose a reason for hiding this comment

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

Update recommendedQueries to reflect new expansion

The recommendedQueries array has been updated to replace "Dragonflight" references with "TWW" (The War Within).

However, consider the following suggestions:

  1. Update the description for the "Illusions and Consumables" query to remove the "Dragonflight" reference.
  2. Consider adding a comment explaining what TWW stands for, for better code readability.

Example:

 const recommendedQueries = [
   // ... other queries ...
   {
     name: 'Default TWW Deals',
     description: 'Find deals on current content.',
     Icon: DocumentSearchIcon,
     href: searchParams.defaultTWW
   },
   // ... other queries ...
   {
     name: 'TWW Recipes',
     description: 'Find TWW recipes at a discount for crafting advancements.',
     Icon: DocumentSearchIcon,
     href: searchParams.recipesTWW
   },
   // ... other queries ...
   {
     name: 'Illusions and Consumables',
-    description: 'Seek out deals on Weapon Illusions and consumable transmog.',
+    description: 'Seek out deals on TWW Weapon Illusions and consumable transmog.',
     Icon: DocumentSearchIcon,
     href: searchParams.illusionsAndConsumables
   },
   // ... other queries ...
 ]

 // Add a comment explaining TWW
 // TWW: The War Within (latest World of Warcraft expansion)

Also applies to: 115-118, 129-129

app/routes/wow.best-deals.recommended.tsx Show resolved Hide resolved
Copy link

sonarcloud bot commented Sep 2, 2024

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: 0

Outside diff range, codebase verification and nitpick comments (1)
app/routes/wow.best-deals._index.tsx (1)

63-64: Type Safety Concerns with parseNumber Function

The parseNumber function currently accepts a parameter of type any, which can lead to unsafe type handling. Since parseStringToNumber is defined as z.string().min(1).transform(parseNumber), the parameter for parseNumber should be explicitly typed as string to ensure type safety and align with the expectations set by z.string().

  • Consider updating the parseNumber function to accept a string parameter instead of any to prevent potential type mismatches and improve type safety.
Analysis chain

LGTM: Validation for expansionNumber added correctly.

The expansionNumber has been added to the validateInput schema using parseStringToNumber, which is correct.

However, there are some type safety concerns flagged by the static analysis tool:

  1. On line 63, there's a warning about an unsafe argument of type any assigned to a parameter of type string.
  2. On line 63, there's also a warning about unsafe member access .transform on an error typed value.
  3. On line 64, there's a warning about unsafe assignment of an error typed value.

These warnings suggest that we might need to add some type assertions or checks to ensure type safety. Could you verify if these warnings are valid in the context of the zod library usage? If they are, we might need to add appropriate type guards or assertions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the zod library usage and type definitions
grep -rn "z.string()" app/
grep -rn "parseStringToNumber" app/utils/zodHelpers.ts

Length of output: 2036


Script:

#!/bin/bash
# Use ast-grep to find the usage of parseStringToNumber in app/routes/wow.best-deals._index.tsx
ast-grep --lang typescript --pattern 'parseStringToNumber' app/routes/wow.best-deals._index.tsx

# Check the definition of parseNumber in app/utils/zodHelpers/index.ts
grep -A 5 'function parseNumber' app/utils/zodHelpers/index.ts

Length of output: 160


Script:

#!/bin/bash
# Use rg to find the usage of parseStringToNumber in app/routes/wow.best-deals._index.tsx
rg 'parseStringToNumber' app/routes/wow.best-deals._index.tsx -A 5

# Use rg to find the definition of parseNumber in app/utils/zodHelpers/index.ts
rg 'parseNumber' app/utils/zodHelpers/index.ts -A 5

Length of output: 1035

Tools
GitHub Check: Codacy Static Code Analysis

[failure] 63-63: app/routes/wow.best-deals._index.tsx#L63
Unsafe argument of type any assigned to a parameter of type string.


[failure] 63-63: app/routes/wow.best-deals._index.tsx#L63
Unsafe member access .transform on an error typed value.


[failure] 64-64: app/routes/wow.best-deals._index.tsx#L64
Unsafe assignment of an error typed value.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 88c28c0 and 4125d67.

Files selected for processing (1)
  • app/routes/wow.best-deals._index.tsx (6 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the `expansion_number` parameter is mapped correctly to the expansion names and that the default value is `-1`.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the `expansionNumber` parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the `wow.marketshare._index.tsx` route.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:29:37.020Z
Learning: User: cohenaj194 prefers to use the `ExpansionSelect` component from `./app/components/form/WoW/WoWScanForm.tsx` whenever possible. The component should be used as shown in the following code snippet:

```typescript
<ExpansionSelect
  defaultValue={loaderData.expansionNumber}
  onChange={(value) => handleFormChange('expansionNumber', value)}
/>

Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#0
File: :0-0
Timestamp: 2024-06-09T21:34:49.875Z
Learning: User: cohenaj194 prefers detailed, actionable responses that directly address the code issues with specific solutions and examples.


</blockquote></details>
<details>
<summary>app/routes/wow.best-deals._index.tsx (3)</summary><blockquote>

Learnt from: cohenaj194
PR: #492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:29:37.020Z
Learning: User: cohenaj194 prefers to use the ExpansionSelect component from ./app/components/form/WoW/WoWScanForm.tsx whenever possible. The component should be used as shown in the following code snippet:

<ExpansionSelect
  defaultValue={loaderData.expansionNumber}
  onChange={(value) => handleFormChange('expansionNumber', value)}
/>

Learnt from: cohenaj194
PR: #485
File: app/routes/wow.marketshare._index.tsx:35-35
Timestamp: 2024-08-25T18:00:21.008Z
Learning: When adding a new menu option for expansions in the WoW Marketshare form, ensure that the expansion_number parameter is mapped correctly to the expansion names and that the default value is -1.


Learnt from: cohenaj194
PR: #492
File: app/routes/wow.best-deals._index.tsx:38-38
Timestamp: 2024-09-02T01:07:41.860Z
Learning: When adding the expansionNumber parameter to a new route, ensure that it is integrated into the loader and action functions, form components, and API requests, similar to how it is handled in the wow.marketshare._index.tsx route.


</blockquote></details>

</blockquote></details>

<details>
<summary>GitHub Check: Codacy Static Code Analysis</summary><blockquote>

<details>
<summary>app/routes/wow.best-deals._index.tsx</summary><blockquote>

[failure] 63-63: app/routes/wow.best-deals._index.tsx#L63
Unsafe argument of type `any` assigned to a parameter of type `string`.

---

[failure] 63-63: app/routes/wow.best-deals._index.tsx#L63
Unsafe member access .transform on an `error` typed value.

---

[failure] 64-64: app/routes/wow.best-deals._index.tsx#L64
Unsafe assignment of an error typed value.

</blockquote></details>

</blockquote></details>

</details>
<details>
<summary>Additional comments not posted (5)</summary><blockquote>

<details>
<summary>app/routes/wow.best-deals._index.tsx (5)</summary><blockquote>

`17-20`: **LGTM: Import statement updated correctly.**

The `ExpansionSelect` component has been added to the import statement, which aligns with the requirement to use this component in the form.

---

`40-41`: **LGTM: Default value for `expansionNumber` added correctly.**

The `expansionNumber` property has been added to `defaultFormValues` with a default value of '-1', which is correct and follows the best practices for handling expansion numbers.

---

`50-51`: **LGTM: Input map updated with `expansionNumber`.**

The `expansionNumber` has been added to the `inputMap` with the label 'WoW Expansion', which provides a clear description for the new input field.

---

`94-97`: **LGTM: Loader function updated to include `expansionNumber`.**

The `expansionNumber` has been correctly added to the `values` object in the loader function. This ensures that the expansion number is properly retrieved from the URL parameters or set to the default value if not present.

---

`203-213`: **LGTM: Form component updated with `ExpansionSelect` and revised options.**

The following changes have been implemented correctly:
1. The "Item Type" select options have been updated, changing "Dragonflight Only" to "Current Content".
2. The `ExpansionSelect` component has been added to the form, using the correct props as specified in the learning.

These changes improve the form's functionality and align with the project's requirements.

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@cohenaj194 cohenaj194 merged commit 2e7497a into master Sep 2, 2024
5 checks passed
@cohenaj194 cohenaj194 deleted the fix/wow-best-expansion-number branch September 2, 2024 02:02
@coderabbitai coderabbitai bot mentioned this pull request Sep 12, 2024
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