-
Notifications
You must be signed in to change notification settings - Fork 0
fix: ordering hallucinations and per milestone contributors ordering #362
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
Open
michalges
wants to merge
7
commits into
main
Choose a base branch
from
fix/ordering-hallucinations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14af216
fix: remove sorting from orderable lists
michalges 4cbb48a
fix: update @tanstack/react-query and refactor query client initializ…
michalges fce07b4
fix: orderable query invalidation
michalges 734b707
fix: remove per-milestone contributors ordering
michalges 53d57df
test: adjust tests for new guide-articles ordering
michalges 37b7e5f
feat: contributors per milestone ordering
michalges 466bdf7
chore: remove unused export
michalges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,38 @@ | ||
| "use client"; | ||
|
|
||
| import { ViewTransitions } from "@solvro/next-view-transitions"; | ||
| import { QueryClient } from "@tanstack/react-query"; | ||
| import { QueryClient, environmentManager } from "@tanstack/react-query"; | ||
|
|
||
| import { globalStore } from "@/stores/global"; | ||
| import type { WrapperProps } from "@/types/components"; | ||
|
|
||
| import { InternalProviders } from "./internal-providers"; | ||
|
|
||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| gcTime: 1000 * 60 * 60 * 24, | ||
| // https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr | ||
|
Member
Author
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. Jedynie się obawiam czy te zmiany z query klientem mogą coś jeszcze namieszać? Z tego co przeklikałem to wszystko (na razie) działa. |
||
| function makeQueryClient() { | ||
| return new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| staleTime: 60 * 1000, | ||
| gcTime: 1000 * 60 * 60 * 24, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| let browserQueryClient: QueryClient | undefined; | ||
|
|
||
| function getQueryClient() { | ||
| if (environmentManager.isServer()) { | ||
| return makeQueryClient(); | ||
| } else { | ||
| browserQueryClient ??= makeQueryClient(); | ||
| return browserQueryClient; | ||
| } | ||
| } | ||
|
michalges marked this conversation as resolved.
|
||
|
|
||
| export function RootProviders({ children }: WrapperProps) { | ||
| const queryClient = getQueryClient(); | ||
|
|
||
| return ( | ||
| <ViewTransitions> | ||
| <InternalProviders queryClient={queryClient} jotaiStore={globalStore}> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/features/abstract-resource-form/components/orderable-pivot-multi-select.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| "use client"; | ||
|
|
||
| import { arrayMove } from "@dnd-kit/sortable"; | ||
| import { useEffect, useRef } from "react"; | ||
| import type { ComponentProps } from "react"; | ||
|
|
||
| import { MultiSelect } from "@/components/ui/multi-select"; | ||
| import { calculateNewSortValue } from "@/features/abstract-resource-list"; | ||
| import type { Resource } from "@/features/resources"; | ||
| import type { | ||
| OrderableResource, | ||
| PivotDataDefinition, | ||
| ResourceDataType, | ||
| ResourcePk, | ||
| ResourceRelation, | ||
| } from "@/features/resources/types"; | ||
|
|
||
| import { usePivotRelationOrderMutation } from "../hooks/use-pivot-relation-order-mutation"; | ||
| import { getItemPivotOrder, hasMeta } from "../utils/get-item-pivot-order"; | ||
|
|
||
| export function OrderablePivotMultiSelect< | ||
| T extends Resource, | ||
| L extends ResourceRelation<T>, | ||
| >({ | ||
| resource, | ||
| resourceRelation, | ||
| endpoint, | ||
| pivotData, | ||
| items, | ||
| multiSelectProps, | ||
| }: { | ||
| resource: T; | ||
| resourceRelation: L; | ||
| endpoint: string; | ||
| pivotData: PivotDataDefinition; | ||
| items: ResourceDataType<L>[]; | ||
| multiSelectProps: ComponentProps<typeof MultiSelect>; | ||
| }) { | ||
| const itemsRef = useRef(items); | ||
|
|
||
| useEffect(() => { | ||
| itemsRef.current = items; | ||
| }, [items]); | ||
|
|
||
| const { mutateOrder } = usePivotRelationOrderMutation({ | ||
| resource, | ||
| resourceRelation, | ||
| endpoint, | ||
| }); | ||
|
|
||
| const handleReorder = (id: string, oldIndex: number, newIndex: number) => { | ||
| const mappedItems = itemsRef.current.map((item) => ({ | ||
| ...item, | ||
| order: getItemPivotOrder(item) ?? 0, | ||
| })) as ResourceDataType<OrderableResource>[]; | ||
|
|
||
| const order = calculateNewSortValue(mappedItems, oldIndex, newIndex); | ||
|
|
||
| const originalItem = itemsRef.current.find( | ||
| (item) => String(item.id) === id, | ||
| ); | ||
| if (originalItem == null) { | ||
| return; | ||
| } | ||
|
|
||
| const meta = hasMeta(originalItem) ? originalItem.meta : undefined; | ||
| const pivotKey = `pivot_${pivotData.field}`; | ||
| const pivotValue = meta?.[pivotKey]; | ||
|
|
||
| if (pivotValue == null) { | ||
| return; | ||
| } | ||
|
|
||
| const reorderedItems = arrayMove(itemsRef.current, oldIndex, newIndex); | ||
|
|
||
| itemsRef.current = reorderedItems.map((item) => { | ||
| if (String(item.id) === id) { | ||
| return { | ||
| ...item, | ||
| meta: { | ||
| ...(hasMeta(item) ? item.meta : {}), | ||
| pivot_order: order, | ||
| }, | ||
| }; | ||
| } | ||
| return item; | ||
| }); | ||
|
|
||
| void mutateOrder(id as ResourcePk, order, { | ||
| [pivotData.field]: pivotValue, | ||
| }); | ||
| }; | ||
|
|
||
| return <MultiSelect {...multiSelectProps} onReorder={handleReorder} />; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.