-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#281 select vertions #310
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
base: dev
Are you sure you want to change the base?
Changes from 8 commits
f6a526e
115d504
aa71f76
bdc6a8d
90badbd
da4ff84
483c523
42189d0
53881b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { UseGetProductVersions } from "@repo/apis/core/shop/product-version/flat/get/use-get-product-versions"; | ||
| import { Select } from "@repo/ui/components"; | ||
|
|
||
| const SelectVersion = ({ productId }: { productId: string }) => { | ||
| const { data, isLoading } = UseGetProductVersions({ | ||
| params: { | ||
| productId, | ||
| }, | ||
| }); | ||
|
|
||
| const handleChange = (value: string) => { | ||
| console.log(value) | ||
| } | ||
|
|
||
| return ( | ||
| <Select | ||
| id="version-select" | ||
| onValueChange={handleChange} | ||
| placeholder="Select a version" | ||
| size="lg" | ||
| loading={isLoading} | ||
| options={data?.data?.data?.map((item) => ({ | ||
| label: item.version, | ||
| value: item.id.toString() | ||
| })) || []} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export { SelectVersion }; |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
| "prettier": "^3.3.2", | ||
| "turbo": "2.0.6" | ||
| }, | ||
| "packageManager": "yarn@1.22.22", | ||
| "packageManager": "bun@1.1.19", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainPackage manager changed from Yarn to Bun The package manager has been switched from Yarn 1.22.22 to Bun 1.1.19, which is a significant change that could affect development workflows and CI/CD pipelines. 🏁 Script executed: #!/bin/bash
# Check if there are any remaining Yarn-specific files or configurations
find . -name "yarn.lock" -o -name ".yarnrc" -o -name ".yarn" -type d
# Check if lockfile has been properly updated to Bun format
test -f "bun.lockb" && echo "Bun lockfile exists" || echo "Bun lockfile missing"
# Check CI configuration for Yarn references
find .github -type f -name "*.yml" -o -name "*.yaml" | xargs grep -l "yarn" || echo "No Yarn references in GitHub workflows"Length of output: 291 Address remaining Yarn artifacts and update CI workflows There are residual Yarn configurations that need to be cleaned up now that you’ve switched to Bun:
Please remove or replace all Yarn-specific files and commands:
|
||
| "engines": { | ||
| "node": ">=18" | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { apiResponseSchema } from "#schema/api-response-schema"; | ||
| import { z } from "zod"; | ||
|
|
||
| // Request | ||
| export const getProductVersionsRequestSchemaTransformed = z | ||
| .object({ | ||
| productId: z.string(), | ||
| }) | ||
| .transform((data) => ({ | ||
| product_id: data.productId, | ||
| })); | ||
|
|
||
| // Response | ||
| export const getProductVersionsResponseSchemaTransofrmed = apiResponseSchema.extend({ | ||
| data: z.array(z.object({ | ||
| version: z.string(), | ||
| id: z.number(), | ||
| })), | ||
| }).transform((data) => data); | ||
|
|
||
| export const getProductVersionsSchema = { | ||
| response: getProductVersionsResponseSchemaTransofrmed, | ||
| request: getProductVersionsRequestSchemaTransformed, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { coreApi } from "#instance/core-api"; | ||
| import path from "path"; | ||
| import { ApiResponse } from "@repo/apis/types/api.types"; | ||
| import { requestHandler } from "@repo/apis/utils/request-handler"; | ||
| import { getProductVersionsSchema as schema } from "./get-product-versions.schema"; | ||
| import { | ||
| GetProductVersionsRequest, | ||
| GetProductVersionsResponse, | ||
| GetProductVersionsResponseTransformed, | ||
| } from "./get-product-versions.types"; | ||
|
|
||
| const getProductVersionsURL = () => path.join("/shop/product-version/flat/"); | ||
|
|
||
| export const getProductVersions = async ( | ||
| props: GetProductVersionsRequest, | ||
| ): Promise<ApiResponse<GetProductVersionsResponseTransformed>> => { | ||
| const payloadParsed = schema.request.parse(props); | ||
| const URL = getProductVersionsURL(); | ||
|
|
||
| const response = await requestHandler( | ||
| () => coreApi.get<GetProductVersionsResponse>(URL, { params: payloadParsed }), | ||
| schema.response._def.schema, | ||
| { | ||
| isMock: true, | ||
| }, | ||
| ); | ||
|
Comment on lines
+20
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainHardcoded mock flag may prevent real API calls The 🏁 Script executed: #!/bin/bash
# Check if there are any environment variables configured for controlling mock mode
grep -r "NEXT_PUBLIC_MOCK" --include="*.{ts,js,tsx,jsx,json}" .
# Also check if other API functions use this pattern
grep -r "isMock:" --include="*.{ts,js,tsx,jsx}" --after-context=1 packages/apis/src/services/Length of output: 157 I want to inspect how 🏁 Script executed: #!/bin/bash
# Find where requestHandler is imported
grep -R "import .*requestHandler" -n packages/apis/src
# Locate requestHandler’s implementation
grep -R "export function requestHandler" -n packages/apis/src || grep -R "const requestHandler" -n packages/apis/srcLength of output: 2170 To confirm how the 🏁 Script executed: #!/bin/bash
# Show how many lines we have and preview the implementation of requestHandler
wc -l packages/apis/src/utils/request-handler.ts
sed -n '1,200p' packages/apis/src/utils/request-handler.tsLength of output: 1148 Remove hardcoded mock flag in The • File: const response = await requestHandler(
() => coreApi.get<GetProductVersionsResponse>(URL, { params: payloadParsed }),
schema.response._def.schema,
{ isMock: true },
);to something like: const response = await requestHandler(
() => coreApi.get<GetProductVersionsResponse>(URL, { params: payloadParsed }),
schema.response._def.schema,
{ isMock: process.env.NEXT_PUBLIC_MOCK === 'true' },
);or guard by environment: { isMock: process.env.NODE_ENV === 'development' } |
||
|
|
||
|
|
||
| const dataParsed = schema.response.parse(response.data); | ||
|
|
||
| return { ...response, data: dataParsed }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { z } from "zod"; | ||
| import { getProductVersionsSchema } from "./get-product-versions.schema"; | ||
|
|
||
| // Response | ||
| export type GetProductVersionsRequest = z.input<typeof getProductVersionsSchema.request>; | ||
|
|
||
| export type GetProductVersionsRequestTransofrmed = z.infer< | ||
| typeof getProductVersionsSchema.request | ||
| >; | ||
|
|
||
| // Request | ||
| export type GetProductVersionsResponse = z.input<typeof getProductVersionsSchema.response>; | ||
|
|
||
| export type GetProductVersionsResponseTransformed = z.infer< | ||
| typeof getProductVersionsSchema.response | ||
| >; |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||||||
| import { | ||||||||||||||
| ApiError, | ||||||||||||||
| ApiResponse, | ||||||||||||||
| UseQueryProps, | ||||||||||||||
| WithParams, | ||||||||||||||
| } from "@repo/apis/types/api.types"; | ||||||||||||||
| import { useQuery } from "@tanstack/react-query"; | ||||||||||||||
| import { getProductVersions } from "./get-product-versions"; | ||||||||||||||
| import { | ||||||||||||||
| GetProductVersionsRequest, | ||||||||||||||
| GetProductVersionsResponseTransformed, | ||||||||||||||
| } from "./get-product-versions.types"; | ||||||||||||||
|
|
||||||||||||||
| export type UseGetProductVersionsProps = UseQueryProps< | ||||||||||||||
| ApiResponse<GetProductVersionsResponseTransformed>, | ||||||||||||||
| WithParams<GetProductVersionsRequest> | ||||||||||||||
| >; | ||||||||||||||
|
|
||||||||||||||
| export const getProductVersionsQueryKey = () => ["getProductVersions"]; | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Query key should include dependency parameters The query key doesn't include any parameters that the API depends on, such as the product ID. This could lead to cache collisions if multiple components fetch versions for different products. -export const getProductVersionsQueryKey = () => ["getProductVersions"];
+export const getProductVersionsQueryKey = (params: GetProductVersionsRequest) => ["getProductVersions", params];Then update the queryKey usage: - queryKey: getProductVersionsQueryKey(),
+ queryKey: getProductVersionsQueryKey(params),📝 Committable suggestion
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| export const UseGetProductVersions = (props: UseGetProductVersionsProps) => { | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Hook naming should follow React conventions React hook names should use camelCase and start with 'use', not uppercase 'Use'. This convention helps tools like ESLint identify hooks properly. -export const UseGetProductVersions = (props: UseGetProductVersionsProps) => {
+export const useGetProductVersions = (props: UseGetProductVersionsProps) => {📝 Committable suggestion
Suggested change
|
||||||||||||||
| const { params, ...resProps } = props; | ||||||||||||||
|
|
||||||||||||||
| const query = useQuery<ApiResponse<GetProductVersionsResponseTransformed>, ApiError>({ | ||||||||||||||
| queryKey: getProductVersionsQueryKey(), | ||||||||||||||
| queryFn: () => getProductVersions(params), | ||||||||||||||
| ...resProps, | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| return query; | ||||||||||||||
| }; | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,11 +58,9 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void { | |||||||||||||||||||||||||||||||||||||||
| default: "core", | ||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||
| type: "list", | ||||||||||||||||||||||||||||||||||||||||
| type: "input", | ||||||||||||||||||||||||||||||||||||||||
| name: "path", | ||||||||||||||||||||||||||||||||||||||||
| message: "Select the API path from Swagger JSON:", | ||||||||||||||||||||||||||||||||||||||||
| choices: swaggerPaths.length > 0 ? swaggerPaths : ["No paths available"], | ||||||||||||||||||||||||||||||||||||||||
| when: () => swaggerPaths.length > 0, | ||||||||||||||||||||||||||||||||||||||||
| message: "Enter the API path:" | ||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improved flexibility but created dead code Changing from a list selection to free text input for API paths provides more flexibility for developers but may lead to inconsistency in path formats. The - const swaggerPaths = loadSwaggerPaths("./swagger.json");Since the Swagger paths are no longer used for providing choices in the prompt, this function call is unnecessary. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||
| actions(data) { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
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.
Hardcoded productId in SelectVersion component
The SelectVersion component is initialized with a fixed
productId="1", which may not be appropriate for a product creation flow where the ID is typically generated after creation. Consider using a more dynamic approach or clarifying why a fixed ID is used here.If this is intentional (e.g., for selecting versions of an existing product template), please add a code comment explaining this design decision.
📝 Committable suggestion