Skip to content

Commit

Permalink
fix(import/export): check the import content
Browse files Browse the repository at this point in the history
  • Loading branch information
Debaerdm committed Feb 4, 2021
1 parent 8f83758 commit 1e5d64b
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { offline, settings } from 'shared/stores/default.store';
import { onMount } from 'svelte';
import { SkizzleUpdaterEnum } from 'models/skizzle';
import { clientAuthenticated } from 'shared/stores/authentication.store';
const app = require('electron').ipcRenderer;
let update: SkizzleUpdaterEnum;
Expand All @@ -19,7 +20,7 @@
[Views.Settings]: Settings,
};
let currentView: Views = Views.Main;
let currentView: Views = $clientAuthenticated.isGithubAuthenticated || $clientAuthenticated.isAzureDevOpsAuthenticated ? Views.Main : Views.Accounts;
const onViewChange = (view: Views) => (currentView = view);
window.addEventListener('online', () => offline.set(false));
Expand Down
4 changes: 2 additions & 2 deletions src/components/AccountSummary/AccountSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
{#if profile.email}<span class="email">{profile.email}</span>{/if}
</div>
{#if withSettings}
<button on:click={() => (isSettingsDisplayed = !isSettingsDisplayed)}><Icons.AccountSettings /></button>
<button on:click={() => (isSettingsDisplayed = !isSettingsDisplayed)} title="Configuration"><Icons.AccountSettings /></button>
{/if}
<button on:click={() => logout(profile.provider)}><Icons.Delete /></button>
<button on:click={() => logout(profile.provider)} title="Déconnexion"><Icons.Delete /></button>
</div>
{#if isSettingsDisplayed}
<Modale onClose={onModaleClose}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddAccount/AddAccount.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script>
import Icons from 'components/icons';
import { isFetchingData } from 'shared/stores/default.store';
export let onClick: () => void;
export let text: string;
</script>
Expand Down Expand Up @@ -31,5 +33,5 @@
</style>

<div>
<button on:click={onClick}><Icons.AddAccount />{text}</button>
<button on:click={onClick} disabled={$isFetchingData}><Icons.AddAccount />{text}</button>
</div>
5 changes: 3 additions & 2 deletions src/components/AzureDevOps/AzureDevOps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@
<Search
onSubmit={onSearchSubmit}
onCancel={onSearchCancel}
disabled={$isFetchingData} />
disabled={$isFetchingData}
placeholder="Rechercher un projet" />

{#if search}
<SearchResults
provider={ProviderEnum.AzureDevOps}
{search}
projects={fetchedProjects} />
{/if}
Expand Down
2 changes: 0 additions & 2 deletions src/components/CustomListSettings/CustomListSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@
const newRepositoriesIds = repositoriesIds.filter(repo => repo !== id);
repositoriesIds = [...newRepositoriesIds];
};
$: console.log({ selectedRepoId });
</script>

<!-- svelte-ignore a11y-no-onchange a11y-autofocus -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<section>
<AccountTitle>
Vos repositories suivis
<button title="Partager votre liste" on:click={() => shareDisplayed = true}><Icons.Share /></button>
<button title="Partager votre liste" disabled={$isFetchingData} on:click={() => shareDisplayed = true}><Icons.Share /></button>
</AccountTitle>
<p class="intro">
Vous suivez actuellement <b>{followedRepositories.length}</b>
Expand Down Expand Up @@ -57,7 +57,7 @@
</ul>
{#if shareDisplayed}
<Modale onClose={() => shareDisplayed = false} fullHeight={false}>
<ImportExport {followedRepositories} />
<ImportExport {followedRepositories} bind:shareDisplayed={shareDisplayed} provider={profile.provider} />
</Modale>
{/if}
</section>
Expand Down
9 changes: 5 additions & 4 deletions src/components/Github/Github.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import SearchResults from 'components/SearchResults';
import FollowedRepositories from 'components/FollowedRepositories';
import Search from 'components/Search';
import type { RepositoryType } from 'models/skizzle';
let search: string = '';
$: fetchedGithubRepositories = [];
$: fetchedGithubRepositories = [] as RepositoryType[];
const onSearchSubmit = async query => {
const onSearchSubmit = async (query: string) => {
search = query;
fetchedGithubRepositories = await Service.getRepositories(
ProviderEnum.Github,
Expand Down Expand Up @@ -81,11 +82,11 @@
<Search
onSubmit={onSearchSubmit}
onCancel={onSearchCancel}
disabled={$isFetchingData} />
disabled={$isFetchingData}
placeholder="Rechercher un repository" />

{#if search}
<SearchResults
provider={ProviderEnum.Github}
{search}
repos={fetchedGithubRepositories} />
{/if}
Expand Down
53 changes: 46 additions & 7 deletions src/components/ImportExport/ImportExport.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<script lang="ts">
import { isFetchingData, repositories } from 'shared/stores/default.store';
import { isFetchingData, repositories, organizations, projects } from 'shared/stores/default.store';
import { HighlightSvelte } from "svelte-highlight";
import { a11yDark } from "svelte-highlight/styles";
import { json } from "svelte-highlight/languages";
import Tabs from 'components/Tabs';
import AccountTitle from 'components/AccountTitle';
import { copyToClipboard, isJson } from 'shared/utils';
import Icons from 'components/icons';
import type { RepositoryType } from 'models/skizzle';
import type { RepositoryType } from 'models/skizzle';
import { ProviderEnum } from 'models/skizzle';
export let followedRepositories: RepositoryType[];
export let provider: ProviderEnum;
export let shareDisplayed: boolean;
let currentTab: string = 'import';
let code: string = '';
Expand All @@ -18,10 +21,46 @@ import type { RepositoryType } from 'models/skizzle';
const importCode = () => {
let repositoriesImported = JSON.parse(code) as RepositoryType[];
let filteredRepositories = repositoriesImported.filter(y => !$repositories.some(z => z.repositoryId === y.repositoryId));
repositoriesImported = repositoriesImported
.map(x => ({ ...x, checked: true }))
.filter((repository) => {
let result = repository.repositoryId &&
repository.gitUrl &&
repository.name &&
!!repository.provider;
repositories.update(x => [...x, ...filteredRepositories]);
if (provider === ProviderEnum.AzureDevOps) {
result = result && repository.organizationName &&
repository.projectId &&
repository.projectName &&
$projects.some(project => project.projectId === repository.projectId) &&
$organizations.some(organization => organization.organizationName === repository.organizationName);
}
if (provider === ProviderEnum.Github) {
result = result && repository.fullName && !!repository.owner
}
return result;
});
repositories.update(x => {
const values = x.map(repository => ({
...repository,
checked: repository.checked || repositoriesImported.some(z => z.repositoryId === repository.repositoryId)
}));
return ([...values, ...repositoriesImported.filter(y => !x.some(z => z.repositoryId === y.repositoryId))])
});
shareDisplayed = false;
}
const getExportCode = (): RepositoryType[] => {
return followedRepositories.map(repository => ({
...repository,
checked: undefined
}));
}
</script>

<svelte:head>
Expand All @@ -39,18 +78,18 @@ import type { RepositoryType } from 'models/skizzle';
<p class="intro">Copiez le code JSON et importez-le dans une autre instance de Skizzle.</p>
<div class="code">

<HighlightSvelte language={json} code={JSON.stringify(followedRepositories, undefined, 2)} />
<HighlightSvelte language={json} code={JSON.stringify(getExportCode(), undefined, 2)} />
<button
class="copy"
on:click={() => copyToClipboard(JSON.stringify(followedRepositories, undefined, 2), 'Code copié dans le presse-papier.')}
on:click={() => copyToClipboard(JSON.stringify(getExportCode(), undefined, 2), 'Code copié dans le presse-papier.')}
disabled={$isFetchingData}
title="Copier l'url de ce repository"
>
<Icons.Copy />
</button>
</div>
{:else}
<form on:submit={importCode}>
<form on:submit|preventDefault={importCode}>
<p class="intro">Collez le code JSON provenant d'une autre instance de Skizzle. <b>Attention</b> Skizzle remplacera les repositories que vous suivez actuellement.</p>
<textarea bind:value={code} placeholder="Collez ici votre code JSON"></textarea>
<div class="bar">
Expand Down
5 changes: 3 additions & 2 deletions src/components/Reviews/Reviews.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
font-size: 0.8rem;
border-radius: 4px;
background-color: #555;
z-index: 1;
}
div:not(:last-child) {
Expand All @@ -40,8 +41,8 @@
</style>

{#each Object.entries(reviews) as [key, value]}
{#if key !== 'other'}
<div>
{#if key !== 'others'}
<div title={key}>
<svelte:component this={icons[key]} color="#fff" />
<span>{value}</span>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Search/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export let onSubmit: (string) => void;
export let onCancel: () => void;
export let disabled: boolean;
export let placeholder: string = '';
let query: string = '';
Expand Down Expand Up @@ -69,7 +70,7 @@
<div class="search">
<Icons.Search color="#4e4e4e" />
<form on:submit={search}>
<input bind:value={query} {disabled} placeholder="Rechercher un projet" />
<input bind:value={query} {disabled} {placeholder} />
<input type="submit" />
{#if query}
<button on:click={cancel} class="delete">
Expand Down
4 changes: 2 additions & 2 deletions src/mappers/Review.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ReviewMapperType = From<
export class ReviewMapper extends Mapper<ReviewMapperType, ReviewType> {
public to(data: ReviewMapperType[]): ReviewType {
return data.reduce((acc, curr) => {
let key = curr.vote || curr.state;
let key = curr.vote || curr.state || '';

let result = `${key}`;

Expand All @@ -41,7 +41,7 @@ export class ReviewMapper extends Mapper<ReviewMapperType, ReviewType> {
result = 'requestChange';
break;
default:
result = 'other';
result = 'others';
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/skizzle/RepositoryType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export type RepositoryType = {
name: string;
fullName?: string;
owner?: string;
checked: boolean;
checked?: boolean;
gitUrl?: string;
} & CommonType;
1 change: 0 additions & 1 deletion src/shared/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const getToken = async <T extends OAuthConfigType>(
}
isLoading.set(false);
} catch (err) {
console.log(err);
isLoading.set(false);
return;
}
Expand Down

0 comments on commit 1e5d64b

Please sign in to comment.