Skip to content
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

Add vehicle selector and special notes for setup guide #25

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
08fafd4
refactor: fix ids of each step section
TheSecurityDev Mar 1, 2025
c1c5048
refactor: Update HarnessSelector to support being in a card and clear…
TheSecurityDev Mar 2, 2025
eaf9722
feat: increase the limit of harness variants fetched to 250 (max)
TheSecurityDev Mar 2, 2025
9bbee27
refactor: rename harness 'car' property to 'name' for consistency and…
TheSecurityDev Mar 2, 2025
d16baf0
fix: rename one more
TheSecurityDev Mar 2, 2025
8b33090
feat: add ability to hide the package support card in the HarnessSele…
TheSecurityDev Mar 2, 2025
d3f57e2
refactor: prevent overwriting other query params when updating make a…
TheSecurityDev Mar 2, 2025
dbf7ece
fix: close dropdown menu when X is pressed with no selection
TheSecurityDev Mar 2, 2025
fc050ac
fix: fix adding make to harnesses
TheSecurityDev Mar 2, 2025
5e27c4f
feat: add vehicle selection with setup notes on setup guide
TheSecurityDev Mar 2, 2025
47bec38
feat: add placeholder for setup notes in vehicles template
TheSecurityDev Mar 2, 2025
0f0ea64
revert: undo naming harness 'car' property to 'name'
TheSecurityDev Mar 2, 2025
03cc143
refactor: get search params from $page instead of window
TheSecurityDev Mar 2, 2025
f118c86
refactor: change negative prop to positive
TheSecurityDev Mar 2, 2025
68ad160
feat: add support for showing only vehicle or generic harnesses
TheSecurityDev Mar 2, 2025
883c2d1
feat: add support for custom search labels
TheSecurityDev Mar 2, 2025
f37fd96
fix: allow clear button to clear search input instead of closing drop…
TheSecurityDev Mar 2, 2025
490ba28
fix: remove query params when not used
TheSecurityDev Mar 2, 2025
f58213e
feat: only show vehicle specific harnesses in setup guide
TheSecurityDev Mar 2, 2025
1912436
fix: clearing search focuses text like before
TheSecurityDev Mar 2, 2025
8864385
feat: dynamically update harness selector resource labels based on pa…
TheSecurityDev Mar 2, 2025
7d497ef
refactor: revert updating css since we're not using the harness selec…
TheSecurityDev Mar 2, 2025
d656d2b
add todos for updating vehicle specific sections
TheSecurityDev Mar 2, 2025
278d361
Merge branch 'commaai:master' into car-setup-notes
TheSecurityDev Mar 2, 2025
15b6014
Merge branch 'commaai:master' into car-setup-notes
TheSecurityDev Mar 3, 2025
a07385f
Merge branch 'master' of https://github.com/TheSecurityDev/comma-webs…
TheSecurityDev Mar 3, 2025
b1daf27
Merge branch 'car-setup-notes' of https://github.com/TheSecurityDev/c…
TheSecurityDev Mar 3, 2025
5776841
add demo setup notes for first 2 vehicles
TheSecurityDev Mar 3, 2025
d79a0e1
feat: update vehicle setup notes and card styles to support markdown …
TheSecurityDev Mar 4, 2025
4f5ef1a
refactor: merge header margin styles
TheSecurityDev Mar 4, 2025
b0a01d0
Merge branch 'master' into car-setup-notes
TheSecurityDev Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"dependencies": {
"@fontsource/inter": "^5.0.20",
"@fontsource/jetbrains-mono": "^5.0.21"
"@fontsource/jetbrains-mono": "^5.0.21",
"marked": "^15.0.7"
},
"devDependencies": {
"@happy-dom/global-registrator": "^17.3.0",
Expand Down
75 changes: 55 additions & 20 deletions src/lib/components/HarnessSelector/HarnessSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { tick } from 'svelte';
import { clickOutside } from '$lib/utils/clickOutside';
import { harnesses } from '$lib/utils/harnesses';
import { allHarnesses, vehicleHarnesses, genericHarnesses } from '$lib/utils/harnesses';

import NoteCard from '$lib/components/NoteCard.svelte';
import DropdownItem from './HarnessDropdownItem.svelte';
Expand All @@ -16,22 +16,44 @@

export let onChange;

export let label = "Select vehicle";
export let accessoryLabel = null;
export let showPackageSupportCard = true; // If true, shows the note card that shows below with information about how the selected car is supported
export let showVehicleHarnesses = true; // If true, includes the harnesses by each vehicle model
export let showGenericHarnesses = true; // If true, includes the generic/developer harnesses
let showAllHarnesses = showVehicleHarnesses && showGenericHarnesses;

export let accessoryLabel = null; // Used to show the price of the selected harness when browsing accessories

const resourceName = {
singular: showAllHarnesses ? "vehicle or harness" : showVehicleHarnesses ? "vehicle" : "harness",
plural: showAllHarnesses ? "vehicles or harnesses" : showVehicleHarnesses ? "vehicles" : "harnesses",
}
export let label = `Select ${resourceName.singular}`;
export let searchLabel = `Search for a ${resourceName.singular}`;
export let noResultsLabel = `No matching ${resourceName.plural}`;

let selection;

// Load harnesses based on the options
$: harnesses = showAllHarnesses ? allHarnesses : showVehicleHarnesses ? vehicleHarnesses : genericHarnesses;
$: browser && $harnesses.length > 0, setInitialSelection();
$: if (selection) {
onChange(selection);
updateQueryParams(selection);
}

function updateQueryParams(selectedHarness) {
const [make, ...model] = selectedHarness.car.split(' ');
const searchParams = new URLSearchParams();
searchParams.set("make", encodeURIComponent(make));
if (model.length > 0) searchParams.set("model", encodeURIComponent(model.join(' ')));
const searchParams = $page.url.searchParams;
const [make, ...model] = selectedHarness?.car?.split(' ') || [];
if (make) {
searchParams.set("make", encodeURIComponent(make));
} else {
searchParams.delete("make");
}
if (model?.length > 0) {
searchParams.set("model", encodeURIComponent(model.join(' ')));
} else {
searchParams.delete("model");
}
goto(`?${searchParams.toString()}`, { keepfocus: true, replaceState: true, noScroll: true });
}

Expand All @@ -57,13 +79,26 @@

const handleClear = () => {
// clear search input
inputValue = "";
handleInput();
inputRef?.focus();

// clear harness selection
selection = null;
onChange(null);
let clearedInput = false;
if (inputValue) {
inputValue = "";
clearedInput = true;
handleInput();
inputRef?.focus();
}
// clear harness selection and close if we weren't clearing the search input
if (!clearedInput) {
// clear harness selection
if (selection) {
selection = null;
onChange(null);
updateQueryParams(null); // NOTE: Doing this causes a soft reload which removes the focus from the input
}
// close the dropdown if it's open
if (menuOpen) {
menuOpen = false;
}
}
}

/* Dropdown Options */
Expand Down Expand Up @@ -92,7 +127,7 @@
<button class="clear" on:click={handleClear}>{@html CloseIcon}</button>
<input
type="text"
placeholder="Search for a vehicle or harness"
placeholder={searchLabel}
autocomplete="off"
class="search-input"
bind:value={inputValue}
Expand Down Expand Up @@ -128,7 +163,7 @@
<DropdownItem value={item} on:click={() => handleOptionClick(item)} on:keydown={(e) => handleOptionKeyDown(e, item)} />
{/each}
{:else}
<DropdownItem value={{ car: 'No matching vehicles' }} />
<DropdownItem value={{ car: noResultsLabel }} />
{/if}
{:else}
{#each $harnesses as item}
Expand All @@ -138,7 +173,7 @@
</div>
</div>

{#if selection && selection.package}
{#if showPackageSupportCard && selection && selection.package}
<NoteCard title="Support" icon={CarIcon}>
{@html selection.package === 'All' ?
'openpilot will work with <strong>all packages and trims</strong> of this car.' :
Expand All @@ -157,7 +192,7 @@
}

.dropdown-content {
display: none;
display: none; /* hidden by default */
position: absolute;
border: 1px solid #ddd;
z-index: 1;
Expand All @@ -166,8 +201,8 @@
overflow-y: auto;
}

.show {
display:block;
.dropdown-content.show {
display:block
}

.search-input {
Expand Down
42 changes: 40 additions & 2 deletions src/lib/components/NoteCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="card" class:elevated={style == "elevated"}>
<div>{@html icon}</div>
<hgroup>
<span>{title}</span>
<span class="title">{title}</span>
<div>
<slot></slot>
</div>
Expand All @@ -29,7 +29,7 @@
margin-left: 1rem;
display: block !important;

& span {
& .title {
font-family: JetBrains Mono, monospace;
font-size: 0.875rem;
font-weight: 400;
Expand All @@ -54,6 +54,44 @@
opacity: 0.8;
}
}

& h1, & h2, & h3, & h4, & h5, & h6 {
margin-block: 1rem;
}

& h1 {
font-size: 1.5rem;
}

& h2 {
font-size: 1.25rem;
}

& h3 {
font-size: 1.125rem;
}

& h4 {
font-size: 1rem;
}

& h5 {
font-size: 0.875rem;
}

& h6 {
font-size: 0.75rem;
}

& li {
font-size: 0.875rem;
margin-bottom: 0.5rem;
}

& ul, & ol {
padding-left: 1.5rem;
margin: 0.5rem 0;
}
}
}

Expand Down
25 changes: 17 additions & 8 deletions src/lib/utils/harnesses.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ async function fetchHarnessVariants() {
}, {});
}

const harnesses = writable([]);
let initialized = false;
const vehicleHarnesses = writable([]); // List of vehicle model harnesses, excluding developer and generic make harnesses
const genericHarnesses = writable([]); // List of developer and generic make harnesses
const allHarnesses = writable([]); // List of all vehicle model harnesses, including developer and generic make harnesses

async function initializeHarnesses() {
if (initialized) return;

const harnessInfo = await fetchHarnessVariants();

let harnessList = Object.values(Vehicles).flatMap(make => {
return make.map(model => {
// Add harnesses for vehicles
let vehiclesHarnessList = Object.entries(Vehicles).flatMap(([make, models]) => {
return models.map(model => {
if (model.name === 'comma body') return false;
const harness = CarHarnesses.find(harness => harness.title === model.harness_connector);
if (!harness) {
Expand All @@ -34,28 +37,34 @@ async function initializeHarnesses() {
return {
...harnessInfo[harness.id],
...harness,
make,
car: model.name,
package: model.package,
angledMount: model.angled_mount,
backordered: harness?.backordered, // these overrides are only shown if the harness is out of stock in Shopify
};
}).filter(Boolean);
});
vehicleHarnesses.set(vehiclesHarnessList);

// add developer harnesses
harnessList.push(...CarHarnesses.map(harness => {
// Add developer and generic make harnesses
let genericHarnessList = CarHarnesses.map(harness => {
return {
...harnessInfo[harness.id],
car: harness.title,
id: harness.id,
backordered: harness.backordered,
};
}));
});
genericHarnesses.set(genericHarnessList);

// Combine the two lists
let allHarnessList = vehiclesHarnessList.concat(genericHarnessList);
allHarnesses.set(allHarnessList);

harnesses.set(harnessList);
initialized = true;
}

initializeHarnesses();

export { harnesses };
export { allHarnesses, vehicleHarnesses, genericHarnesses };
2 changes: 1 addition & 1 deletion src/lib/utils/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function getProduct(id) {
currencyCode
}
}
variants(first: 100) {
variants(first: 250) {
nodes {
id
title
Expand Down
9 changes: 6 additions & 3 deletions src/lib/vehicles.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"harness_connector": "Honda Nidec",
"detail_sentence": "openpilot upgrades your <strong>Acura ILX</strong> with automated lane centering and adaptive cruise control <strong>while driving above 26 mph</strong>. This car may not be able to take tight turns on its own. Traffic light and stop sign handling is also available in <a href='https://blog.comma.ai/090release/#experimental-mode' target='_blank' class='highlight'>Experimental mode</a>.",
"footnotes": [
]
],
"setup_notes": "<p>Here's an example of an HTML note with some <strong>bold text</strong> and a <a href='https://comma.ai' target='_blank'>link</a> or a <a href='https://comma.ai' target='_blank' class='highlight'>highlighted link</a>.</p><p>We can even include images:</p><img src='https://blog.comma.ai/img/097_release/cover.jpg' alt='comma logo' width='200' height='100' /><ul><li>And we can use</li><li>bullet points</li><li>to show steps</li></ul></p>"
},
{
"name": "Acura RDX 2016-18",
Expand All @@ -24,7 +25,8 @@
"harness_connector": "Honda Nidec",
"detail_sentence": "openpilot upgrades your <strong>Acura RDX</strong> with automated lane centering and adaptive cruise control <strong>while driving above 26 mph</strong>. This car may not be able to take tight turns on its own. Traffic light and stop sign handling is also available in <a href='https://blog.comma.ai/090release/#experimental-mode' target='_blank' class='highlight'>Experimental mode</a>.",
"footnotes": [
]
],
"setup_notes": "## Markdown header\n\nRegular text\n\n- Use **bold text** for emphasis\n- Include [links](https://comma.ai.com)\n- Add bullet points as needed\n\nOr include images:\n\n![comma](https://blog.comma.ai/img/097_release/cover.jpg)"
},
{
"name": "Acura RDX 2019-21",
Expand All @@ -37,7 +39,8 @@
"harness_connector": "Honda Bosch A",
"detail_sentence": "openpilot upgrades your <strong>Acura RDX</strong> with automated lane centering <strong>above 3 mph</strong>, and adaptive cruise control <strong>that automatically resumes from a stop</strong>. This car may not be able to take tight turns on its own.",
"footnotes": [
]
],
"setup_notes": "Here are some shorter demo notes with [a link](https://comma.ai)."
}
],
"Audi": [
Expand Down
2 changes: 1 addition & 1 deletion src/routes/setup/(guides)/comma-3x/+page.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function load() {
],
notes: [
{
title: 'Note: Nissan & GM setup',
title: 'Note: Nissan & GM setup', // TODO: This should probably be moved to vehicle specific notes in vehicles.json ("setup_notes" field)
content: `
See more setup details:
<a href="https://github.com/commaai/openpilot/wiki/nissan" target="_blank">Nissan</a> or
Expand Down
Loading