Skip to content

Commit

Permalink
Ignore specific colors (#114)
Browse files Browse the repository at this point in the history
* Ignore specific colors

* clean up

* presentation tweaks
  • Loading branch information
mcnuttandrew authored Sep 15, 2024
1 parent 57bdc01 commit 672e357
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
28 changes: 28 additions & 0 deletions apps/color-buddy/src/linting/EvalResponse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
(x) => lintProgram.description.toLowerCase().includes(x) && x !== colorSpace
) as any;
$: ignored = !!evalConfig[lintProgram.name]?.ignore;
$: blameData = (
lintResult.kind === "success" ? lintResult.blameData : []
).flat();
</script>

<Tooltip {positionAlongRightEdge}>
Expand Down Expand Up @@ -172,6 +175,31 @@
</button>
{/if}

<div>For just this lint</div>
{#each blameData as index}
<button
class={buttonStyle
.split(" ")
.filter((x) => x !== "opacity-50")
.join(" ")}
on:click={() => {
colorStore.setCurrentPalEvalConfig({
...evalConfig,
[`${palette.colors[index].toHex()}-?-${lintProgram.id}`]: {
ignore: true,
},
});
}}
>
<span class="opacity-50">ignore ({palette.colors[index].toHex()})</span>

<div
class="rounded-full w-3 h-3 ml-1 inline-block opacity-100"
style={`background: ${palette.colors[index].toHex()}`}
/>
</button>
{/each}

{#if requestState === "loading"}
<div>Loading...</div>
{:else if requestState === "failed"}
Expand Down
26 changes: 26 additions & 0 deletions apps/color-buddy/src/linting/LintDisplay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
$: evalConfig = currentPal.evalConfig;
$: lintProgram = lintResult.lintProgram;
$: isCompact = $configStore.evalDisplayMode === "compact";
$: ignoredColors = Object.entries(evalConfig)
.filter(
([name, config]) =>
(name.split("-?-")[1] || "").trim() === lintProgram.id && config.ignore
)
.map(([name]) => name.split("-?-")[0]);
</script>

{#if lintResult.kind === "ignored"}
Expand Down Expand Up @@ -61,6 +67,26 @@
</div>
<EvalResponse {lintResult} />
</div>
{#if ignoredColors.length > 0 && !isCompact}
<div class="text-sm italic">
Ignored colors for this lint:
{#each ignoredColors as color}
<div class="inline-block relative w-3 h-3 mx-1">
<button
on:click={() => {
colorStore.setCurrentPalEvalConfig({
...evalConfig,
[`${color}-?-${lintProgram.id}`]: { ignore: false },
});
}}
class="rounded-full w-3 h-3 bottom-0 absolute inline-block opacity-100"
style={`background: ${color}`}
/>
</div>
{/each}
(click to re-enable)
</div>
{/if}
{#if lintResult.kind === "success" && !lintResult.passes && !isCompact}
<ExplanationViewer {lintResult} />
{/if}
Expand Down
1 change: 0 additions & 1 deletion apps/color-buddy/src/stores/config-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function hydrateStore(): StoreData {
if (str === "undefined") {
str = JSON.stringify(InitialStore);
}
console.log(str, localStorage.getItem(storeName));
const store = addDefaults(JSON.parse(str));
if (store.tempPal) {
store.tempPal = stringPalToColorPal(store.tempPal as any);
Expand Down
8 changes: 7 additions & 1 deletion packages/palette-lint/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ function processLint(
if (!ignored) {
return { kind: "ignored", lintProgram: lint };
}
// ignored colors
let pal = { ...palette };
pal.colors = palette.colors.filter((color) => {
const key = `${color.toHex()}-?-${lint.id}`;
return palette.evalConfig[key]?.ignore !== true;
});

// run the lint
if (prebuiltIdToCustomFunc[lint.id]) {
lint.customProgram = prebuiltIdToCustomFunc[lint.id];
}
let result: LintResult;
try {
result = RunLint(lint, palette, options);
result = RunLint(lint, pal, options);
} catch (e) {
console.error(e);
result = { kind: "invalid", lintProgram: lint };
Expand Down

0 comments on commit 672e357

Please sign in to comment.