-
Notifications
You must be signed in to change notification settings - Fork 197
Fix : more messaging flow issues #2497
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
base: main
Are you sure you want to change the base?
Changes from all commits
6f32afb
2952234
120487f
6fc0360
1f262be
8abd63c
c70de39
5ab3311
64687a7
5859efb
7bf20dd
839363c
45b2dfb
c6a25dc
6685320
10aafb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
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. why was this moved from svelte5 to 4? |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,29 +16,19 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getProviderText } from './helper'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { page } from '$app/state'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providerType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| show = $bindable(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| topicsById = $bindable(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title = 'Select topics' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = $props<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providerType: MessagingProviderType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| show: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| topicsById: Record<string, Models.Topic>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export let providerType: MessagingProviderType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export let show: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export let topicsById: Record<string, Models.Topic>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export let title: string = 'Select topics'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dispatch = createEventDispatcher(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let search = $state(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let offset = $state(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let totalResults = $state(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let topicResultsById = $state<Record<string, Models.Topic>>({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let selected = $state<Record<string, Models.Topic>>({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let emptyTopicsExists = $state(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let previousSearch = $state(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let wasOpen = $state(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let search = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let offset = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let totalResults = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let topicResultsById: Record<string, Models.Topic> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let selected: Record<string, Models.Topic> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let emptyTopicsExists = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function getTopicTotal(topic: Models.Topic): number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (providerType) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,44 +86,38 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function onTopicSelection(event: CustomEvent<boolean>, topic: Models.Topic) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updatedSelected = { ...selected }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (event.detail) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...selected, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [topic.$id]: topic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updatedSelected[topic.$id] = topic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { [topic.$id]: _, ...rest } = selected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delete updatedSelected[topic.$id]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $effect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (search !== previousSearch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| previousSearch = search; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offset = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = updatedSelected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $effect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!show) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offset ?? null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| search ?? null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: if (show) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $effect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (show && !wasOpen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = topicsById; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wasOpen = show; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: if (offset !== null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: if (search !== null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offset = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+100
to
+109
Contributor
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. Fix reactive blocks to prevent duplicate API calls. The current reactive blocks have several issues:
This leads to wasted API calls, potential race conditions, and unpredictable results. Consider refactoring to a single reactive block with proper dependency tracking: - $: if (show) {
- request();
- }
- $: if (offset !== null) {
- request();
- }
- $: if (search !== null) {
- offset = 0;
- request();
- }
+ $: if (show) {
+ offset = 0;
+ search = '';
+ }
+
+ $: if (show || offset >= 0 || search !== undefined) {
+ request();
+ }Alternatively, use separate reactive blocks with proper guards: - $: if (show) {
- request();
- }
- $: if (offset !== null) {
- request();
- }
- $: if (search !== null) {
+ let prevSearch = search;
+ $: if (search !== prevSearch) {
+ prevSearch = search;
offset = 0;
- request();
}
+
+ $: show, offset, search, request();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let selectedSize = $derived(Object.keys(selected).length); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let hasSelection = $derived(selectedSize > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: selectedSize = Object.keys(selected).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: hasSelection = selectedSize > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let topicSelectionStates = $derived( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.fromEntries(Object.keys(topicResultsById).map((id) => [id, !!selected[id]])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: topicSelectionStates = Object.fromEntries( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.keys(topicResultsById).map((id) => [id, !!selected[id]]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $: if (show) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = topicsById; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Modal {title} bind:show onSubmit={submit} on:close={reset}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -185,7 +169,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type="secondary" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title={`You have no topics${ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| emptyTopicsExists ? ` with ${providerType.toUpperCase()} targets` : '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| emptyTopicsExists ? ` with ${providerType.toLowerCase()} targets` : '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description={`Create a topic to see them here.`}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
Verify the hardcoded
query="[]"value.The
Filterscomponent is being passed a hardcodedquery="[]", which means it won't reflect any existing query state from URL parameters. In contrast, in filesrc/routes/(console)/project-[region]-[project]/messaging/topics/topic-[topic]/+page.svelte(line 93), theFilterscomponent receivesquery={data.query}from server data.This could lead to a UX issue where active filters from URL params aren't displayed in the UI when using
hasCustomFiltersOnlymode.Consider whether the query should be:
ResponsiveContainerHeader(similar to other props likecolumns,analyticsSource)"[]"(please confirm if this is the expected behavior)Run the following script to check how Filters component is used elsewhere in the codebase:
🏁 Script executed:
Length of output: 30
🏁 Script executed:
Length of output: 3402
🏁 Script executed:
Length of output: 1116
🏁 Script executed:
Length of output: 1045
🏁 Script executed:
Length of output: 5835
🏁 Script executed:
Length of output: 1915
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 419
🏁 Script executed:
Length of output: 1653
🏁 Script executed:
Length of output: 2251
🏁 Script executed:
Length of output: 3933
🏁 Script executed:
Length of output: 2505
🏁 Script executed:
Length of output: 931
🏁 Script executed:
Length of output: 1841
🏁 Script executed:
Length of output: 3357
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1184
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 184
🏁 Script executed:
Length of output: 962
Add
queryprop toResponsiveContainerHeaderand pass it to theFilterscomponent.The hardcoded
query="[]"on line 120 prevents custom filters from displaying saved filter state. Both pages usinghasCustomFiltersOnly=true(messaging/topics and messaging/providers) havedata.queryavailable from their page loaders, but cannot pass it to the component since thequeryprop doesn't exist.This breaks the established pattern: all other direct
Filtersusages in the codebase receivequery={data.query}.Required changes:
query?: stringto the component's prop definition{query}instead ofquery="[]"query={data.query}when settinghasCustomFiltersOnly🤖 Prompt for AI Agents