-
Notifications
You must be signed in to change notification settings - Fork 113
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
feat: unified actions selectors #2749
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
102df68
feat: init context sharing
skokenes b636e1e
example
skokenes fcd1589
fix: lint issue
skokenes cff9c93
cleanup
skokenes 142ea5b
Merge branch 'main' of https:/rilldata/rill-developer int…
skokenes 1da06c3
ex refactor wip
skokenes 846e88f
wip refactor
skokenes 3d04e9e
cleanup
skokenes 089d671
type
skokenes be86993
fix: fork sq
skokenes 16dd180
cleanup
skokenes 8edd1ff
cleanup
skokenes adcad2e
move value check to enabled prop
skokenes aa18292
Merge branch 'main' of https:/rilldata/rill-developer int…
skokenes 57f924c
remove business model
skokenes 9030153
remove business model
skokenes 08a076b
fix merge
skokenes 84d06ce
Merge branch 'main' into feat/unified-actions-selectors
skokenes 75e41bf
fix: type error
skokenes 382b923
fix: types
skokenes fcd4e60
feat: consolidate action code
skokenes 454eec6
fix: remove unused
skokenes 2f10e0a
fix: added comment
skokenes c493365
fix: optional search results
skokenes 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 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 |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
"@playwright/test": "^1.25.0", | ||
"@sveltejs/adapter-static": "^1.0.0", | ||
"@sveltejs/kit": "^1.5.0", | ||
"@tanstack/svelte-query": "^4.27.0", | ||
"@rilldata/svelte-query": "^4.29.20-0.0.1", | ||
"@tanstack/svelte-query": "npm:@rilldata/[email protected]", | ||
"@types/cookie": "^0.5.1", | ||
"@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"@typescript-eslint/parser": "^5.27.0", | ||
|
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 |
---|---|---|
|
@@ -30,7 +30,8 @@ | |
"@storybook/svelte": "^7.0.18", | ||
"@storybook/svelte-vite": "^7.0.18", | ||
"@storybook/testing-library": "^0.0.14-next.2", | ||
"@tanstack/svelte-query": "^4.27.0", | ||
"@rilldata/svelte-query": "^4.29.20-0.0.1", | ||
"@tanstack/svelte-query": "npm:@rilldata/[email protected]", | ||
"@testing-library/svelte": "^3.2.2", | ||
"@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"@typescript-eslint/parser": "^5.27.0", | ||
|
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { get } from "svelte/store"; | ||
import type { StateManagers } from "../state-managers/state-managers"; | ||
import { cancelDashboardQueries } from "../dashboard-queries"; | ||
import { removeIfExists } from "@rilldata/web-common/lib/arrayUtils"; | ||
|
||
export function clearFilterForDimension( | ||
ctx: StateManagers, | ||
dimensionId: string, | ||
include: boolean | ||
) { | ||
const metricViewName = get(ctx.metricsViewName); | ||
cancelDashboardQueries(ctx.queryClient, metricViewName); | ||
ctx.updateDashboard((dashboard) => { | ||
if (include) { | ||
removeIfExists( | ||
dashboard.filters.include, | ||
(dimensionValues) => dimensionValues.name === dimensionId | ||
); | ||
} else { | ||
removeIfExists( | ||
dashboard.filters.exclude, | ||
(dimensionValues) => dimensionValues.name === dimensionId | ||
); | ||
} | ||
}); | ||
} | ||
|
||
export function clearAllFilters(ctx: StateManagers) { | ||
const filters = get(ctx.dashboardStore).filters; | ||
const hasFilters = | ||
(filters && filters.include.length > 0) || filters.exclude.length > 0; | ||
const metricViewName = get(ctx.metricsViewName); | ||
if (hasFilters) { | ||
cancelDashboardQueries(ctx.queryClient, metricViewName); | ||
ctx.updateDashboard((dashboard) => { | ||
dashboard.filters.include = []; | ||
dashboard.filters.exclude = []; | ||
dashboard.dimensionFilterExcludeMode.clear(); | ||
}); | ||
} | ||
} | ||
|
||
export function toggleDimensionValue( | ||
ctx: StateManagers, | ||
dimensionName: string, | ||
dimensionValue: string | ||
) { | ||
const metricViewName = get(ctx.metricsViewName); | ||
cancelDashboardQueries(ctx.queryClient, metricViewName); | ||
|
||
ctx.updateDashboard((dashboard) => { | ||
const relevantFilterKey = dashboard.dimensionFilterExcludeMode.get( | ||
dimensionName | ||
) | ||
? "exclude" | ||
: "include"; | ||
|
||
const dimensionEntryIndex = dashboard.filters[relevantFilterKey].findIndex( | ||
(filter) => filter.name === dimensionName | ||
); | ||
|
||
if (dimensionEntryIndex >= 0) { | ||
if ( | ||
removeIfExists( | ||
dashboard.filters[relevantFilterKey][dimensionEntryIndex].in, | ||
(value) => value === dimensionValue | ||
) | ||
) { | ||
if ( | ||
dashboard.filters[relevantFilterKey][dimensionEntryIndex].in | ||
.length === 0 | ||
) { | ||
dashboard.filters[relevantFilterKey].splice(dimensionEntryIndex, 1); | ||
} | ||
return; | ||
} | ||
|
||
dashboard.filters[relevantFilterKey][dimensionEntryIndex].in.push( | ||
dimensionValue | ||
); | ||
} else { | ||
dashboard.filters[relevantFilterKey].push({ | ||
name: dimensionName, | ||
in: [dimensionValue], | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export function toggleFilterMode(ctx: StateManagers, dimensionName: string) { | ||
const metricViewName = get(ctx.metricsViewName); | ||
cancelDashboardQueries(ctx.queryClient, metricViewName); | ||
ctx.updateDashboard((dashboard) => { | ||
const exclude = dashboard.dimensionFilterExcludeMode.get(dimensionName); | ||
dashboard.dimensionFilterExcludeMode.set(dimensionName, !exclude); | ||
|
||
const relevantFilterKey = exclude ? "exclude" : "include"; | ||
const otherFilterKey = exclude ? "include" : "exclude"; | ||
|
||
const otherFilterEntryIndex = dashboard.filters[ | ||
relevantFilterKey | ||
].findIndex((filter) => filter.name === dimensionName); | ||
// if relevant filter is not present then return | ||
if (otherFilterEntryIndex === -1) return; | ||
|
||
// push relevant filters to other filter | ||
dashboard.filters[otherFilterKey].push( | ||
dashboard.filters[relevantFilterKey][otherFilterEntryIndex] | ||
); | ||
// remove entry from relevant filter | ||
dashboard.filters[relevantFilterKey].splice(otherFilterEntryIndex, 1); | ||
}); | ||
} |
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.
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.
I like this!