-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
ffxiv-export-url-endings #490
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce significant updates to the Changes
Assessment against linked issues
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@@ -1,3 +1,4 @@ | |||
// add url endings to this file https://github.com/ff14-advanced-market-search/saddlebag-with-pockets/issues/489 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai help add url endings to this file
see a past PR for adding url endings here https://github.com/ff14-advanced-market-search/saddlebag-with-pockets/pull/391/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cohenaj194, I've reviewed the past PR and identified the necessary steps to add URL endings to the app/routes/queries.world-comparison.tsx
file. Below are the changes that need to be made:
-
Add a
LoaderFunction
to handle URL parameters:- This function will parse and validate the URL parameters and return them as loader data.
-
Use
useLoaderData
in theIndex
component:- This hook will retrieve the parsed parameters and use them to populate the form fields.
-
Update the form submission to include the URL parameters:
- This ensures that the form submission reflects the current state of the URL parameters.
Here is the updated code:
import { useActionData, useLoaderData, useNavigation } from '@remix-run/react'
import { json } from '@remix-run/cloudflare'
import { z } from 'zod'
import { getUserSessionData } from '~/sessions'
import { getItemNameById } from '~/utils/items'
import { WorldList } from '~/utils/locations/Worlds'
import { getActionUrl, handleSearchParamChange } from '~/utils/urlSeachParamsHelpers'
// Define default form values
const defaultFormValues = {
itemIds: '',
exportServers: '',
hqOnly: 'false'
}
// Define input schema for validation
const inputSchema = z.object({
itemIds: z.string().min(1),
exportServers: z.string().min(1),
hqOnly: z.optional(z.string())
})
// Loader function to handle URL parameters
export const loader: LoaderFunction = async ({ request }) => {
const params = new URL(request.url).searchParams
const values = {
itemIds: params.get('itemIds') || defaultFormValues.itemIds,
exportServers: params.get('exportServers') || defaultFormValues.exportServers,
hqOnly: params.get('hqOnly') || defaultFormValues.hqOnly
}
const validParams = inputSchema.safeParse(values)
if (!validParams.success) {
return json({
exception: `Missing: ${validParams.error.issues
.map(({ path }) => path.join(', '))
.join(', ')}`
})
}
return json(validParams.data)
}
// Action function remains unchanged
export const action: ActionFunction = async ({ request }) => {
const formData = await request.formData()
const session = await getUserSessionData(request)
const homeServer = session.getWorld()
const formPayload = Object.fromEntries(formData)
const validInput = inputSchema.safeParse(formPayload)
if (!validInput.success) {
return json({
exception: `Missing: ${validInput.error.issues
.map(({ path }) => path.join(', '))
.join(', ')}`
})
}
const response = await ItemServerComparison({
homeServer,
...validInput.data
})
if (!response.ok) {
return json({ exception: response.statusText })
}
return json({ ...(await response.json()), homeServer })
}
const Index = () => {
const transition = useNavigation()
const results = useActionData<ItemServerComparisonList | { exception: string } | {}>()
const loaderData = useLoaderData<typeof defaultFormValues>()
const [modal, setModal] = useState<'exportServers' | 'items' | null>(null)
const [state, setState] = useState({
items: loaderData.itemIds.split(','),
exportServers: loaderData.exportServers.split(',')
})
const onSubmit = (e: React.MouseEvent<HTMLButtonElement>) => {
if (transition.state === 'submitting') {
e.preventDefault()
}
}
const error = results && 'exception' in results
? results.exception
: results && 'data' in results && results.data.length === 0
? 'No results found'
: undefined
if (results && 'data' in results && !error) {
if (results.data) {
return <Results results={results} />
}
}
const itemsLength = state.items.length
const serversLength = state.exportServers.length
return (
<PageWrapper>
<SmallFormContainer
title="Compare the minimum price of items across worlds!"
description="Find out the minimum price of different items across multiple servers. Helps you find the best server to sell your items on, if you have alts on many servers."
onClick={onSubmit}
loading={transition.state === 'submitting'}
disabled={transition.state === 'submitting'}
error={error}
action={getActionUrl('/queries/world-comparison', state)}>
{/* Form fields remain unchanged */}
</SmallFormContainer>
</PageWrapper>
)
}
export default Index
This code adds URL endings to the app/routes/queries.world-comparison.tsx
file by implementing a LoaderFunction
, using useLoaderData
, and updating the form submission to include the URL parameters.
Let me know if you need any further adjustments!
Analysis chain
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Fetch the diff from the past PR to understand how URL endings were added.
gh pr diff 391
Length of output: 9128
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#469
File: app/routes/ffxiv.extended-history.tsx:227-227
Timestamp: 2024-07-18T03:24:58.546Z
Learning: In the ff14-advanced-market-search/saddlebag-with-pockets repository, always include `mobileColumnList` in all `app/route` pages to avoid mapping issues.
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#472
File: app/routes/ffxiv.scrip-exchange.tsx:11-11
Timestamp: 2024-07-17T22:15:54.905Z
Learning: User: cohenaj194 prefers using `SmallTable` for displaying data and converting URLs into clickable buttons instead of long strings.
Deploying saddlebag-with-pockets with Cloudflare Pages
|
There was a problem hiding this 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
Files selected for processing (1)
- app/routes/queries.world-comparison.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
- app/routes/queries.world-comparison.tsx
Additional context used
Learnings (1)
Common learnings
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.
There was a problem hiding this 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
Files selected for processing (1)
- app/routes/queries.world-comparison.tsx (5 hunks)
Additional context used
Learnings (1)
Common learnings
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.
Additional comments not posted (6)
app/routes/queries.world-comparison.tsx (6)
1-1
: LGTM!The new imports and constants are necessary for handling URL parameters, generating action URLs, and validating input.
Also applies to: 23-26, 53-66
67-87
: LGTM!The loader function is correctly implemented and handles URL parameters as expected. It retrieves and validates input values against the specified schema using the
z
validation library. If validation fails, it returns a JSON response with an error message detailing the missing parameters.
Line range hint
100-138
:
144-144
: LGTM!The component correctly uses
useLoaderData
to access the loader's output. ThegetActionUrl
function is used to generate the action URL for the form submission button.Also applies to: 181-182
Line range hint
320-339
:
Line range hint
341-403
:
@@ -137,7 +178,8 @@ const Index = () => { | |||
onClick={onSubmit} | |||
loading={transition.state === 'submitting'} | |||
disabled={transition.state === 'submitting'} | |||
error={error}> | |||
error={error} | |||
action={getActionUrl('/queries/world-comparison', state)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai this does change the url of the page but loading something like http://localhost:8788/queries/world-comparison?items=21793&exportServers=Adamantoise%2CHalicarnassus
does not alter the forms in the webpage.
Can you look through other past pull requests to see how we fixed this before and recommend a fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cohenaj194, it seems that there are no past pull requests that directly address the issue of populating form fields based on URL parameters. However, I can recommend a solution based on the current context.
The issue likely stems from the form fields not being initialized with the data returned by the loader
function. To fix this, you can use the useLoaderData
hook to set the initial state of the form fields when the page loads.
Here's an example of how you can implement this:
const Index = () => {
const transition = useNavigation();
const results = useActionData<
ItemServerComparisonList | { exception: string } | {}
>();
const loaderData = useLoaderData<typeof defaultFormValues>();
const [state, setState] = useState({
items: loaderData.itemIds.split(','),
exportServers: loaderData.exportServers.split(','),
hqOnly: loaderData.hqOnly === 'true',
});
// Rest of the component code...
};
In this example, the state
is initialized with the values returned by the loader
function, ensuring that the form fields are populated correctly when the page loads.
Let me know if you need further assistance with this!
Analysis chain
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search through past pull requests for keywords related to URL parameters and form population.
gh pr list --search "URL parameters form population" --json number,title,body --limit 10
Length of output: 93
Script:
#!/bin/bash
# Perform a broader search for past pull requests using more general keywords related to query parameters and form data.
gh pr list --search "query parameters form data" --json number,title,body --limit 10
Length of output: 727
Learnings added
Learnt from: cohenaj194
PR: ff14-advanced-market-search/saddlebag-with-pockets#490
File: app/routes/queries.world-comparison.tsx:182-182
Timestamp: 2024-09-01T16:45:03.690Z
Learning: When dealing with form fields that need to be populated based on URL parameters, ensure that the initial state of the form fields is set using the data returned by the `loader` function via the `useLoaderData` hook.
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.
|
||
const [modal, setModal] = useState<'exportServers' | 'items' | null>(null) | ||
const [state, setState] = useState<{ | ||
items: string[] | ||
exportServers: string[] | ||
}>({ items: [], exportServers: [] }) | ||
|
||
// // One AI recommendation, but it didnt solve the issue. It keeps saying "Error: Cannot read properties of undefined (reading 'split')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI recommendation, this might be right, but it does not solve the whole problem.
There was a problem hiding this 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
Files selected for processing (1)
- app/routes/queries.world-comparison.tsx (5 hunks)
Additional context used
Learnings (2)
Common learnings
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/queries.world-comparison.tsx (1)
Learnt from: cohenaj194 PR: ff14-advanced-market-search/saddlebag-with-pockets#490 File: app/routes/queries.world-comparison.tsx:182-182 Timestamp: 2024-09-01T16:45:03.874Z Learning: When dealing with form fields that need to be populated based on URL parameters, ensure that the initial state of the form fields is set using the data returned by the `loader` function via the `useLoaderData` hook.
Additional comments not posted (6)
app/routes/queries.world-comparison.tsx (6)
1-1
: LGTM!The new imports
useLoaderData
anduseNavigation
from@remix-run/react
are necessary for the changes made in the file.
23-26
: LGTM!The new imports
getActionUrl
andhandleSearchParamChange
from~/utils/urlSeachParamsHelpers
are necessary for the changes made in the file.
53-58
: LGTM!The
defaultFormValues
constant is defined with default values foritemIds
,exportServers
, andhqOnly
. It is used in the loader function to provide default values when the corresponding URL parameters are not present.
60-65
: LGTM!The
inputSchema
constant is defined using thez
validation library to validate the input parameters. It is used in the loader function to validate the input parameters against the defined schema.
67-87
: LGTM!The loader function is correctly implemented and handles the URL parameters as expected. It retrieves the values of
itemIds
,exportServers
, andhqOnly
from the URL parameters, validates them against theinputSchema
, and returns a JSON response with either an error message or the validated data.
Line range hint
144-189
: LGTM!The changes made to the
Index
component ensure that the form fields are populated correctly when the page loads based on the URL parameters. The initial state of the form fields is set using the data returned by theloader
function via theuseLoaderData
hook. Theaction
prop of the form is also set correctly using thegetActionUrl
function to include the URL parameters in the form submission.[learning_used]
Learnt from: cohenaj194 PR: ff14-advanced-market-search/saddlebag-with-pockets#490 File: app/routes/queries.world-comparison.tsx:182-182 Timestamp: 2024-09-01T16:45:03.874Z Learning: When dealing with form fields that need to be populated based on URL parameters, ensure that the initial state of the form fields is set using the data returned by the `loader` function via the `useLoaderData` hook.
Tools
Biome
[error] 142-142: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
@coderabbitai this is a test are you alive? |
Tip For best results, initiate chat on the files or code changes. @cohenaj194: Yes, I'm here and ready to assist you! Learnings used
|
@DarthNerdus any chance you still want to do this one? |
Quality Gate passedIssues Measures |
closes: #489
Summary by CodeRabbit