Skip to content

Commit

Permalink
Merge pull request #967 from MuckRock/allanlasser/issue965
Browse files Browse the repository at this point in the history
Prefill add-on fields from query params
  • Loading branch information
allanlasser authored Dec 10, 2024
2 parents f1ef472 + 2da2885 commit eaed3ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/lib/components/forms/AddOnDispatch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
} from "$lib/api/types";
import { enhance } from "$app/forms";
import { page } from "$app/stores";
import { afterNavigate } from "$app/navigation";
import Ajv from "ajv";
Expand Down Expand Up @@ -60,6 +61,12 @@
event: schedules[event.event],
};
}
// prefill values from search params
new URLSearchParams($page.url.searchParams).forEach((v, k) => {
if (k in properties) {
$values[k] = v;
}
});
});
function objectify(params: any) {
Expand Down
20 changes: 19 additions & 1 deletion src/lib/components/forms/stories/AddOnDispatch.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Flex from "$lib/components/common/Flex.svelte";
import { addonsList } from "@/test/fixtures/addons";
import { APP_URL } from "@/config/config";
const addons = addonsList.results;
Expand All @@ -26,7 +27,7 @@
required={addon.parameters.required}
eventOptions={addon.parameters.eventOptions}
/>
<div class="values" style="max-width: 88ch">
<div class="values" style="max-width: 88ch" data-chromatic="ignore">
<h2><code>$values</code></h2>
<pre><code>{JSON.stringify($values, null, 2)}</code></pre>
</div>
Expand All @@ -46,3 +47,20 @@
<Story name="Bad Redactions" args={addons[5]} />

<Story name="Site Snapshot" args={addons[6]} />

<Story
name="Prefill Fields (Scraper)"
args={addons[1]}
parameters={{
sveltekit_experimental: {
stores: {
page: {
url: new URL(
"/?site=https://example.com&project=123&keywords=foo,bar&notAfield=hahagotya",
APP_URL,
),
},
},
},
}}
/>

0 comments on commit eaed3ef

Please sign in to comment.