Skip to content

Commit

Permalink
feat(contextBridge): adding context bridge for protect exposed object…
Browse files Browse the repository at this point in the history
… from electron
  • Loading branch information
Debaerdm committed Mar 24, 2021
2 parents 89ff44f + 8e36317 commit 1d40b3b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 28 deletions.
22 changes: 12 additions & 10 deletions src/components/AzureDevOps/AzureDevOps.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { Service } from 'services/Service';
import { clientAuthenticated } from 'shared/stores/authentication.store';
import { isFetchingData, isLoading } from 'shared/stores/default.store';
import { isLoading } from 'shared/stores/default.store';
import { authorize } from 'shared/token';
import { ProviderEnum } from 'models/skizzle/ProviderEnum';
import AccountTitle from 'components/AccountTitle';
Expand All @@ -14,18 +14,22 @@
let search: string = '';
const onSearchSubmit = (profile: ProfileType) => async (
query: string,
) => {
let isLoadingRepositories = false;
const onSearchSubmit = (profile: ProfileType) => async (query: string) => {
search = query;
const result = await Service.getRepositories(ProviderEnum.AzureDevOps, { profile });
isLoadingRepositories = true;
const result = await Service.getRepositories(ProviderEnum.AzureDevOps, {
profile,
});
fetchedAzureDevOpsRepositories = result.filter(
({ projectName, name }) =>
name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) ||
projectName.toLocaleLowerCase().includes(search.toLocaleLowerCase()),
);
isLoadingRepositories = false;
};
const onSearchCancel = (): void => {
Expand All @@ -48,18 +52,16 @@
<div class="content">
<section>
<AccountTitle>Suivre un nouveau repository</AccountTitle>
<p class="intro">
Cherchez le nom de son projet et/ou repository associé.
</p>
<p class="intro">Cherchez le nom de son projet et/ou repository associé.</p>
<Search
onSubmit={onSearchSubmit(profile)}
onCancel={onSearchCancel}
disabled={$isFetchingData}
disabled={isLoadingRepositories}
placeholder="Rechercher un projet ou un repos"
/>

{#if search}
{#if $isFetchingData}
{#if isLoadingRepositories}
<p>Recherche en cours...</p>
{:else}
<SearchResults {search} repos={fetchedAzureDevOpsRepositories} />
Expand Down
44 changes: 42 additions & 2 deletions src/components/CustomListSettings/CustomListSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
export let onDone: () => void;
export let id: string;
let tags: string[] = $customLists.find(list => list.id === id)?.tags ?? [];
let listName: string = $customLists.find(list => list.id === id)
? $customLists.find(list => list.id === id).name
: null;
Expand All @@ -23,6 +25,8 @@
? $customLists.find(list => list.id === id).repositoriesIds
: [];
let tag: string;
const onImport = async () => {
const result: any = await window.remote.invoke('file-import');
Expand Down Expand Up @@ -57,6 +61,7 @@
id,
name: listName,
repositoriesIds,
tags,
};
customLists.update(_list =>
Expand All @@ -73,6 +78,7 @@
id: uuidv4(),
name: listName,
repositoriesIds,
tags,
};
customLists.update(_list => [..._list, list]);
Expand All @@ -88,6 +94,25 @@
}
};
const onAddTag = (event: KeyboardEvent): void => {
event.preventDefault();
if (event.key === ';') {
console.log(tag, tags, event.key);
const result = tag.substring(0, tag.indexOf(';'));
if (result) {
tags = [...tags, result];
}
tag = '';
} else if (event.key === 'Backspace' && !tag) {
const result = tags.slice(0, tags.length - 1);
tags = [...result];
}
};
const deleteRepository = (id: string): void => {
const newRepositoriesIds = repositoriesIds.filter(repo => repo !== id);
repositoriesIds = [...newRepositoriesIds];
Expand All @@ -97,7 +122,7 @@
<!-- svelte-ignore a11y-no-onchange a11y-autofocus -->
<form on:submit={onSubmit}>
<AccountTitle>
{id ? 'Modifier la liste' : 'Nouvelle liste'}
{id ? `Modifier la liste "${listName}"` : 'Nouvelle liste'}
<input
id="import"
on:click={onImport}
Expand Down Expand Up @@ -186,7 +211,9 @@
e.preventDefault();
deleteRepository(repo);
}}
><Icons.Delete /></button>
>
<Icons.Delete />
</button>
</li>
{/each}
</ul>
Expand All @@ -195,6 +222,19 @@
{/if}
</Fieldset>
{/if}

<Fieldset
title="Tags"
intro="Saisissez un ou plusieurs tag, Skizzle affichera uniquement les pull requests comportant les tags sélectionnés."
outro={tag
? `Skizzle n'affichera que les pull requests contenant le tag "${tag}"`
: 'Skizzle affichera toutes les pull requests quelque soit leur tag'}
>
<div class="field">
<input id="list-name" type="text" bind:value={tag} on:keyup={onAddTag} />
</div>
</Fieldset>

<div class="bar">
<input
disabled={!listName}
Expand Down
11 changes: 8 additions & 3 deletions src/components/Github/Github.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { Service } from 'services/Service';
import { clientAuthenticated } from 'shared/stores/authentication.store';
import { isFetchingData, isLoading } from 'shared/stores/default.store';
import { isLoading } from 'shared/stores/default.store';
import { authorize } from 'shared/token';
import { ProviderEnum } from 'models/skizzle/ProviderEnum';
import AccountTitle from 'components/AccountTitle';
Expand All @@ -13,17 +13,22 @@
import type { RepositoryType } from 'models/skizzle';
let search: string = '';
let isLoadingRepositories = false;
$: fetchedGithubRepositories = [] as RepositoryType[];
const onSearchSubmit = async (query: string) => {
isLoadingRepositories = true;
search = query;
fetchedGithubRepositories = await Service.getRepositories(
ProviderEnum.Github,
{
query,
},
);
isLoadingRepositories = false;
};
const onSearchCancel = () => {
Expand All @@ -49,12 +54,12 @@
<Search
onSubmit={onSearchSubmit}
onCancel={onSearchCancel}
disabled={$isFetchingData}
disabled={isLoadingRepositories}
placeholder="Rechercher un repository"
/>

{#if search}
{#if $isFetchingData}
{#if isLoadingRepositories}
<p>Recherche en cours...</p>
{:else}
<SearchResults {search} repos={fetchedGithubRepositories} />
Expand Down
28 changes: 22 additions & 6 deletions src/components/Main/Main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,25 @@
};
const filterList = (customList: CustomListType) => {
return $pullRequests.filter(pullRequest =>
customList.repositoriesIds
.map(String)
.includes(String(pullRequest.repositoryId)),
);
let filteredPullRequests = $pullRequests;
if (customList.repositoriesIds.length) {
filteredPullRequests = filteredPullRequests.filter(pullRequest =>
customList.repositoriesIds
.map(String)
.includes(String(pullRequest.repositoryId)),
);
}
if (customList.tags) {
// filteredPullRequests = filteredPullRequests.filter(pullRequest =>
// pullRequest.labels
// ?.map(label => label.name.toLocaleLowerCase())
// .includes(customList.tags.map(tag => tag.toLocaleLowerCase())),
// );
}
return filteredPullRequests;
};
const getTabs = lists => {
Expand Down Expand Up @@ -106,7 +120,9 @@
on:click={() => {
modifyingListId = currentTab;
}}
>Modifier</button>
>
Modifier
</button>
<button on:click={deleteList}>Supprimer</button>
<button on:click={exportList}>Exporter</button>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Pullrequest/Pullrequest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
<h2 class="author">
{pullRequest.user.name} - {getDateStr(new Date(pullRequest.date))}
</h2>
{#if pullRequest.projectName}
<span class="project">{pullRequest.projectName}</span>
{/if}
</header>
<h3 class="title">
{pullRequest.title}
</h3>
<p class="repo">{pullRequest.repositoryName}</p>
<p class="repo">
{#if pullRequest.projectName}
{pullRequest.projectName}&nbsp;/
{/if}
{pullRequest.repositoryName}
</p>
</div>
<footer>
{#if pullRequest.isAutoComplete}
Expand Down Expand Up @@ -89,8 +91,6 @@
}
header {
display: flex;
align-items: center;
margin-bottom: 0.5rem;
font-size: 0.8rem;
color: #aaa;
Expand Down
2 changes: 1 addition & 1 deletion src/models/skizzle/CustomListType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type CustomListType = {
id: string;
name: string;
tags?: string[];
tags: string[];
projectsIds?: string[];
repositoriesIds?: string[];
hiddenPullRequestsIds?: string[];
Expand Down

0 comments on commit 1d40b3b

Please sign in to comment.