-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sensitivity toggles in filter sidebar and modal (#2672)
Co-authored-by: Zack Krida <[email protected]>
- Loading branch information
Showing
11 changed files
with
183 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
110 changes: 110 additions & 0 deletions
110
frontend/src/components/VSafeBrowsing/VSafeBrowsing.vue
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,110 @@ | ||
<template> | ||
<section id="safe-browsing" aria-labelledby="safe-browsing-heading"> | ||
<header class="relative mb-6 flex items-center justify-between"> | ||
<h4 id="safe-browsing-heading" class="caption-bold uppercase"> | ||
{{ $t("filters.safeBrowsing.title") }} | ||
</h4> | ||
</header> | ||
<i18n tag="p" path="filters.safeBrowsing.desc" class="label-regular"> | ||
<template #sensitive> | ||
<VLink :href="sensitivityPath">{{ | ||
$t("filters.safeBrowsing.sensitive") | ||
}}</VLink> | ||
</template> | ||
</i18n> | ||
<form class="safe-browsing-form"> | ||
<fieldset class="mb-10 mt-8 flex flex-col gap-8"> | ||
<div v-for="toggle in toggles" :key="toggle.name"> | ||
<VCheckbox | ||
:id="toggle.name" | ||
class="flex-row-reverse justify-between" | ||
:value="toggle.name" | ||
:checked="toggle.state.value" | ||
:disabled="isDisabled(toggle.name)" | ||
is-switch | ||
@change="toggle.switchFn" | ||
> | ||
<span class="label-bold">{{ | ||
$t(`filters.safeBrowsing.toggles.${toggle.name}.title`) | ||
}}</span> | ||
</VCheckbox> | ||
<p | ||
class="label-regular mt-2" | ||
:class="{ 'text-dark-charcoal-40': isDisabled(toggle.name) }" | ||
> | ||
{{ $t(`filters.safeBrowsing.toggles.${toggle.name}.desc`) }} | ||
</p> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</section> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent } from "vue" | ||
import { useContext } from "@nuxtjs/composition-api" | ||
import { useFeatureFlagStore } from "~/stores/feature-flag" | ||
import { useUiStore } from "~/stores/ui" | ||
import { ON, OFF } from "~/constants/feature-flag" | ||
import VCheckbox from "~/components/VCheckbox/VCheckbox.vue" | ||
import VLink from "~/components/VLink.vue" | ||
/** | ||
* Contains toggles to determine the users preferences towards fetching results | ||
* that may contain sensitive content and subsequently blurring them to prevent | ||
* accidental exposure or showing them directly. | ||
*/ | ||
export default defineComponent({ | ||
name: "VSafeBrowsing", | ||
components: { VCheckbox, VLink }, | ||
setup() { | ||
const { app } = useContext() | ||
const sensitivityPath = computed(() => app.localePath("/about")) // TODO: Issue#2550 | ||
const featureFlagStore = useFeatureFlagStore() | ||
let fetchSensitive = computed(() => | ||
featureFlagStore.isOn("fetch_sensitive") | ||
) | ||
let setFetchSensitive = ({ checked }: { checked: boolean }) => { | ||
featureFlagStore.toggleFeature("fetch_sensitive", checked ? ON : OFF) | ||
if (!checked) { | ||
// If sensitive content is not fetched, there is nothing to blur/unblur. | ||
// In this case, we reset blurring to its default value. | ||
setBlurSensitive({ checked: true }) | ||
} | ||
} | ||
const uiStore = useUiStore() | ||
let blurSensitive = computed(() => uiStore.shouldBlurSensitive) | ||
let setBlurSensitive = ({ checked }: { checked: boolean }) => { | ||
uiStore.shouldBlurSensitive = checked | ||
} | ||
const toggles = [ | ||
{ | ||
name: "fetchSensitive", | ||
state: fetchSensitive, | ||
switchFn: setFetchSensitive, | ||
}, | ||
{ | ||
name: "blurSensitive", | ||
state: blurSensitive, | ||
switchFn: setBlurSensitive, | ||
}, | ||
] | ||
const isDisabled = (name: string) => | ||
name === "blurSensitive" && !fetchSensitive.value | ||
return { | ||
sensitivityPath, | ||
toggles, | ||
isDisabled, | ||
} | ||
}, | ||
}) | ||
</script> |
28 changes: 28 additions & 0 deletions
28
frontend/src/components/VSafeBrowsing/meta/VSafeBrowsing.stories.mdx
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,28 @@ | ||
import { Canvas, Description, Meta, Story } from "@storybook/addon-docs" | ||
|
||
import VSafeBrowsing from "~/components/VSafeBrowsing/VSafeBrowsing.vue" | ||
|
||
<Meta title="Components/VSafeBrowsing" component={VSafeBrowsing} /> | ||
|
||
export const Template = (args) => ({ | ||
template: `<VSafeBrowsing v-bind="args" />`, | ||
components: { VSafeBrowsing }, | ||
setup() { | ||
return { args } | ||
}, | ||
}) | ||
|
||
# VSafeBrowsing | ||
|
||
<Description of={VSafeBrowsing} /> | ||
|
||
<Canvas> | ||
<Story | ||
name="Default" | ||
parameters={{ | ||
viewport: { defaultViewport: "xs" }, // because it is present in the sidebar | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> |
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
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
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
Binary file modified
BIN
-290 Bytes
(99%)
...n/components/filters.spec.ts-snapshots/filters-sidebar-checked-ltr-lg-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-584 Bytes
(98%)
...n/components/filters.spec.ts-snapshots/filters-sidebar-checked-rtl-lg-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.