Skip to content

Commit

Permalink
chore(heureka): adds checks for detailsFor and improve filter prop ha…
Browse files Browse the repository at this point in the history
…ndling
  • Loading branch information
hodanoori committed Nov 14, 2024
1 parent 1024761 commit 60d0e2b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
25 changes: 21 additions & 4 deletions apps/heureka/src/hooks/useUrlState.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
useGlobalsShowPanel,
useGlobalsActiveView,
useGlobalsActions,
useGlobalsShowServiceDetail,
useGlobalsShowIssueDetail,
useServiceActiveFilters,
useIssueMatchesActiveFilters,
useComponentActiveFilters,
Expand All @@ -24,6 +26,8 @@ const useUrlState = () => {

const activeView = useGlobalsActiveView()
const detailsFor = useGlobalsShowPanel()
const showServiceDetail = useGlobalsShowServiceDetail()
const showIssueDetail = useGlobalsShowIssueDetail()
const { setShowPanel, setActiveView, setServiceDetail, setIssueDetail, syncDetailsWithURL } = useGlobalsActions()
const serviceActiveFilters = useServiceActiveFilters()
const issueMatchesActiveFilters = useIssueMatchesActiveFilters()
Expand Down Expand Up @@ -69,8 +73,19 @@ const useUrlState = () => {

const updatedState = {
[constants.ACTIVE_VIEW]: activeView, // Include active view
...syncFiltersWithURL(),
...syncDetailsWithURL(),
...syncFiltersWithURL(serviceActiveFilters, issueMatchesActiveFilters, componentActiveFilters),
...(detailsFor
? syncDetailsWithURL(
showServiceDetail,
showIssueDetail,
detailsFor === constants.PANEL_SERVICE ? constants.PANEL_SERVICE : constants.PANEL_ISSUE
)
: {
// Remove detailsFor from URL when details Panel is closed
[constants.DETAILS_FOR]: undefined,
[constants.SERVICE_NAME]: undefined,
[constants.ISSUE_ID]: undefined,
}),
}

// Construct the URL state
Expand All @@ -79,12 +94,14 @@ const useUrlState = () => {
urlStateManager.push(updatedState)
}
}, [
detailsFor,
activeView,
isURLRead,
detailsFor,
showServiceDetail,
showIssueDetail,
serviceActiveFilters,
issueMatchesActiveFilters,
componentActiveFilters,
isURLRead,
syncFiltersWithURL,
syncDetailsWithURL,
])
Expand Down
8 changes: 4 additions & 4 deletions apps/heureka/src/lib/slices/createFiltersSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const createFiltersSlice = (set, get) => ({
`filters.setFiltersFromURL`
),

syncFiltersWithURL: () => {
syncFiltersWithURL: (serviceFilters, issueFilters, componentFilters) => {
const encodedSearchTerm = btoa(
JSON.stringify({
[ISSUEMATCHES]: get().filters[ISSUEMATCHES].search,
Expand All @@ -167,9 +167,9 @@ const createFiltersSlice = (set, get) => ({
)

const activeFilters = {
[ISSUEMATCHES]: get().filters[ISSUEMATCHES].activeFilters,
[SERVICES]: get().filters[SERVICES].activeFilters,
[COMPONENTS]: get().filters[COMPONENTS].activeFilters,
[ISSUEMATCHES]: issueFilters,
[SERVICES]: serviceFilters,
[COMPONENTS]: componentFilters,
}

return {
Expand Down
10 changes: 4 additions & 6 deletions apps/heureka/src/lib/slices/createGlobalsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ const createGlobalsSlice = (set, get, options) => ({
),

// Sync details state with the URL
syncDetailsWithURL: () => {
const state = get().globals
syncDetailsWithURL: (serviceDetail, issueDetail, panelType) => {
const updatedState = {
[constants.DETAILS_FOR]: state.showPanel,
// Include `iid` or `svn` immediately after `d:issue/service`
[state.showPanel === constants.PANEL_SERVICE ? constants.SERVICE_NAME : constants.ISSUE_ID]:
state.showPanel === constants.PANEL_SERVICE ? state.showServiceDetail : state.showIssueDetail,
[constants.DETAILS_FOR]: panelType,
[panelType === constants.PANEL_SERVICE ? constants.SERVICE_NAME : constants.ISSUE_ID]:
panelType === constants.PANEL_SERVICE ? serviceDetail : issueDetail,
}
return updatedState
},
Expand Down

0 comments on commit 60d0e2b

Please sign in to comment.