Skip to content

Commit

Permalink
fix(Organizations): Handle error on projects fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
itupix committed Jun 2, 2020
1 parent a1d07db commit 90fbe94
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/components/Settings/Settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
top: 0;
visibility: hidden;

&:disabled,
&:disabled + label {
opacity: 0.5;
}

&:before {
visibility: visible;
content: '';
Expand Down
4 changes: 3 additions & 1 deletion src/components/Settings/SettingsOrganizations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
export let init;
import { updateOrganization, isOffline } from '../../shared/store';
const getIsDisabled = organization => $isOffline || organization.isBroken;
const getIsChecked = organization => organization.checked && !organization.isBroken;
</script>

<style src="./Settings.scss"></style>
Expand All @@ -13,7 +15,7 @@
<ul class="skz-organizations__list">
{#each $organizations as organization}
<li>
<input disabled={$isOffline} type="checkbox" id={organization.accountName} on:change={e => updateOrganization(e, organization)} checked={organization.checked} />
<input disabled={getIsDisabled(organization)} type="checkbox" id={organization.accountName} on:change={e => updateOrganization(e, organization)} checked={getIsChecked(organization)} />
<label for={organization.accountName}>{organization.accountName}</label>
</li>
{/each}
Expand Down
47 changes: 28 additions & 19 deletions src/shared/requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let data = [];
let loadedRepositories = 0;
let loadedOrganizations = 0;
let loadedPullRequests = [];
let brokenOrganizations = [];
let refreshing = false;

export const getHeader = () => {
Expand Down Expand Up @@ -203,37 +204,44 @@ export const getProjects = async ({ organization, numberOfOrganizations }) => {
`https://dev.azure.com/${organization.accountName}/_apis/projects?$top=1000&api-version=5.1`,
);

let result = {
value: [],
};

if (res.ok) {
const result = await res.json();
result = await res.json();
} else {
brokenOrganizations.push(organization.accountName);
}

data = data.map(organizationItem => ({
...organizationItem,
projects:
organizationItem.accountId === organization.accountId
? result.value
: organizationItem.projects,
}));
loadedOrganizations += 1;

loadedOrganizations += 1;
data = data.map(organizationItem => ({
...organizationItem,
isBroken: brokenOrganizations.includes(organizationItem.accountName),
projects:
organizationItem.accountId === organization.accountId
? result.value
: organizationItem.projects,
}));

if (loadedOrganizations === numberOfOrganizations) {
const numberOfProjects = data.reduce((acc, curr) => {
acc += curr.projects.length;
return acc;
}, 0);
if (loadedOrganizations === numberOfOrganizations) {
const numberOfProjects = data.reduce((acc, curr) => {
acc += curr.projects ? curr.projects.length : 0;
return acc;
}, 0);

data.forEach(organizationItem => {
data.forEach(organizationItem => {
if (organizationItem.projects) {
organizationItem.projects.forEach(({ id: projectId }) =>
getRepositories({
projectId,
organizationName: organizationItem.accountName,
numberOfProjects,
}),
);
});
}
} else {
throw new Error(res);
}
});
}
};

Expand All @@ -242,6 +250,7 @@ export const getRepositories = async ({
organizationName,
numberOfProjects,
}) => {
console.log('Im fetching repos !');
const res = await customFetch(
`https://dev.azure.com/${organizationName}/${projectId}/_apis/git/repositories?includeLinks=true&api-version=5.0`,
);
Expand Down

0 comments on commit 90fbe94

Please sign in to comment.