Skip to content

Conversation

@PondC
Copy link
Contributor

@PondC PondC commented Aug 21, 2025

Why did you create this PR

https://linear.app/metier/issue/TTC-187/genseki-filter

What did you do

  • Add filter to collection view, with relational support ( as of now only single select and date range type )

Screenshots / Recordings

https://github.com/user-attachments/assets/20b4a6fa-83e2-4d45-a860-98f984621604
Screenshot 2568-08-26 at 21 57 10
Screenshot 2568-08-26 at 21 57 15

Checklist

  • Self-reviewed your code
  • Wrote coverage tests
  • Added screenshots or recordings if applicable

@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2025

⚠️ No Changeset found

Latest commit: 615d51e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@PondC PondC requested a review from SupakornNetsuwan August 26, 2025 14:37
@PondC PondC marked this pull request as ready for review August 26, 2025 14:45
@PondC PondC changed the title feat: create filter [WIP] feat: create filter Aug 26, 2025
@PondC
Copy link
Contributor Author

PondC commented Aug 26, 2025

Any comments are welcome

@saenyakorn
Copy link
Member

Do you have any screen record on this feature? Also, please change the head to #162 due to big refactoring

@PondC
Copy link
Contributor Author

PondC commented Aug 26, 2025

screen record link is above image

or here

Screen.Recording.2568-08-26.at.21.55.47.mp4

not sure why preview didnt show up

search: z.string().optional(),
sortBy: z.string().optional(),
sortOrder: z.enum(['asc', 'desc']).optional(),
filter: z.string().optional(),
Copy link
Member

Choose a reason for hiding this comment

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

We can accept object via query params as well. Try to checkout this library https://www.npmjs.com/package/qs

Comment on lines 38 to 48
export function parseFilterStringToKeyValueMap(filterString: string): Record<string, any> {
try {
const parsed = JSON.parse(filterString)
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
return parsed as Record<string, any>
}
} catch {
// Bad input, not an object. Ignore all
}
return {}
}
Copy link
Member

Choose a reason for hiding this comment

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

This function can be removed if we integrated query with qs https://www.npmjs.com/package/qs

return null
}

export const transformFilterToPrismaString = (filters: MinimalFilter[]) => {
Copy link
Member

Choose a reason for hiding this comment

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

This function should not be in this Frontend code.

Also, to constructing Prisma Payload in Frontend-side. Try to create yourown interface for filters

interface ClientFilters {
  // some spec which might look complex
}

// in component
const [filters, setFilters] = useState<ClientFilters | null>(null)

// sending request to server

const response = await fetch("/options", {
  body: {
    search: search,
    filters: filters
  }
})

// in findMany handler

const filters = query.filters
const prismaWhere = transformClientFiltersToPrismaWhere(filters) // You need to write a unit test on this function as well.
const result = await prisma.something.findMany({
  where: prismaWhere
})
}

Disclaimer: The name of the interface is not well. Try to use another name.

label: '',
})

const [chosenFilter, setChosenFilter] = useState<MinimalFilter[]>([])
Copy link
Member

Choose a reason for hiding this comment

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

Try to use useFieldArray or FormFieldArray

@saenyakorn
Copy link
Member

I also have a comment on UX. But I will discuss with you offline.

@PondC
Copy link
Contributor Author

PondC commented Aug 28, 2025

Moved to #166

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.

3 participants