-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(FiltersPanel): estimate as JSON at search URL
- Loading branch information
1 parent
5355b76
commit d8ef40e
Showing
4 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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,8 +1,25 @@ | ||
import { Estimate } from '@prisma/client'; | ||
import { Estimate as EstimateType } from '@prisma/client'; | ||
|
||
export const estimateToString = (estimate: { q: Estimate['q']; y: Estimate['y'] }) => { | ||
export type Estimate = { q: EstimateType['q']; y: EstimateType['y'] }; | ||
|
||
export const estimateToString = (estimate: Estimate) => { | ||
if (!estimate.q) { | ||
return estimate.y; | ||
} | ||
return `${estimate.q}/${estimate.y}`; | ||
}; | ||
|
||
export const encodeEstimateFilterValue = ({ y, q }: Estimate) => encodeURIComponent(JSON.stringify({ q, y })); | ||
export const decodeEstimateFilterValue = (data: string): null | Estimate => { | ||
try { | ||
const { q = null, y } = JSON.parse(decodeURIComponent(data)); | ||
|
||
if (y) { | ||
return { q, y }; | ||
} | ||
|
||
return null; | ||
} catch (e) { | ||
return null; | ||
} | ||
}; |
This file contains 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