Revise seed config

No longer use `Config` to store the seed config.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-02-09 13:27:12 +01:00
parent 3fcbffe307
commit e6f4441be7
17 changed files with 181 additions and 172 deletions
+5 -7
View File
@@ -23,7 +23,7 @@
export let revision: string;
export let path: string;
let { urn, addressOrName, seed, peer, project, config, branches } = source;
let { urn, addressOrName, seed, peer, project, branches } = source;
// This is reactive to respond to path changes that don't originate from this
// component, eg. when using the browser's "back" button.
@@ -45,8 +45,8 @@
const isMarkdownPath = utils.isMarkdownPath(path);
const promise = path === "/"
? proj.getReadme(urn, commit, config)
: proj.getBlob(urn, commit, path, { highlight: !isMarkdownPath }, config);
? proj.getReadme(urn, commit, source.seed.api)
: proj.getBlob(urn, commit, path, { highlight: !isMarkdownPath }, source.seed.api);
state = { status: Status.Loading, path };
state = { status: Status.Loaded, path, blob: await promise };
@@ -72,15 +72,13 @@
if (addressOrName) {
navigate(proj.path({ peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ peer, urn, seed, revision, path }));
} else {
navigate(proj.path({ peer, urn, revision, path }));
navigate(proj.path({ peer, urn, seed: seed.host, revision, path }));
}
};
const fetchTree = async (path: string) => {
return proj.getTree(urn, commit, path, config);
return proj.getTree(urn, commit, path, seed.api);
};
const toggleMobileFileTree = () => {
+1 -3
View File
@@ -18,10 +18,8 @@
if (addressOrName) {
navigate(proj.path({ content, peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ content, peer, urn, seed, revision, path }));
} else {
navigate(proj.path({ content, peer, urn, revision, path }));
navigate(proj.path({ content, peer, urn, seed: seed.host, revision, path }));
}
};
+6 -6
View File
@@ -18,7 +18,7 @@
// If peerSelector should be showed.
export let peerSelector: boolean;
let { urn, peer, config, project, branches, peers, anchors } = source;
let { urn, peer, project, branches, peers, seed, anchors } = source;
let dropdownState: { [key: string]: boolean } = { clone: false, seed: false, branch: false, peer: false };
function toggleDropdown(input: string) {
@@ -163,7 +163,7 @@
<AnchorBadge {commit} {anchors}
head={project.head} on:click={(event) => updateRevision(event.detail)} />
</div>
{#if config.seed.git.host}
{#if seed.git.host}
<span>
<div class="clone" on:click={() => toggleDropdown("clone")}>
Clone
@@ -175,7 +175,7 @@
<input
readonly
name="clone-url"
value="https://{config.seed.git.host}/{utils.parseRadicleId(urn)}.git"
value="https://{seed.git.host}/{utils.parseRadicleId(urn)}.git"
/>
<label for="clone-url"
>Use Git to clone this repository from the URL above.</label
@@ -184,13 +184,13 @@
</span>
{/if}
<span>
{#if config.seed.api.host}
{#if seed.api.host}
<div
class="stat seed"
on:click={() => navigate(`/seeds/${config.seed.api.host}`)}
on:click={() => navigate(`/seeds/${seed.api.host}`)}
title="Project data is fetched from this seed"
>
<span>{config.seed.api.host}</span>
<span>{seed.api.host}</span>
</div>
{/if}
</span>
+4 -6
View File
@@ -12,7 +12,7 @@
export let revision: string;
export let path: string;
let { urn, seed, addressOrName, peer, config, project, branches } = source;
let { urn, seed, addressOrName, peer, project, branches } = source;
// Bind content to commit history to trigger updates in parent components.
$: [revision_,] = splitPrefixFromPath(locator, branches, project.head);
@@ -21,19 +21,17 @@
const navigateHistory = (revision: string, content?: ProjectContent) => {
// Replaces path with current path if none passed.
if (path === undefined) path = "/";
if (! path) path = "/";
if (addressOrName) {
navigate(proj.path({ content, peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ content, peer, urn, seed, revision, path }));
} else {
navigate(proj.path({ content, peer, urn, revision, path }));
navigate(proj.path({ content, peer, urn, seed: seed.host, revision, path }));
}
};
async function fetchCommits(revision: string): Promise<GroupedCommitsHistory> {
const commitsQuery = await getCommits(urn, getOid(project.head, revision, branches), config);
const commitsQuery = await getCommits(urn, getOid(project.head, revision, branches), seed.api);
return groupCommitHistory(commitsQuery);
}
</script>
+2 -2
View File
@@ -11,11 +11,11 @@
<!-- With an Seed context -->
<Route path="/seeds/:seed/:id/*" let:params>
<View {config} seed={params.seed} id={params.id} />
<View {config} seedHost={params.seed} id={params.id} />
</Route>
<Route path="/seeds/:seed/:id/remotes/:peer/*" let:params>
<View {config} seed={params.seed} peer={params.peer} id={params.id} />
<View {config} seedHost={params.seed} peer={params.peer} id={params.id} />
</Route>
<!-- Explicit user and org context, will at some point be replaced by the generic route -->
+31 -14
View File
@@ -16,7 +16,7 @@
export let id: string; // Project name or URN.
export let addressOrName = "";
export let seed = "";
export let seedHost = "";
export let peer = "";
export let config: Config;
@@ -29,16 +29,24 @@
let getProject = new Promise<{ profile?: Profile | null; seed?: Seed } | null>((resolve, reject) => {
if (addressOrName) {
Profile.get(addressOrName, ProfileType.Project, config).then(p => resolve({ profile: p })).catch(err => reject(err.message));
} else if (seed) {
Seed.get(config.withSeed({ host: seed })).then(s => resolve({ seed: s })).catch(err => reject(err.message));
} else if (seedHost) {
Seed.lookup(seedHost, config).then(s => resolve({ seed: s })).catch(err => reject(err.message));
} else {
resolve(null);
}
}).then(async (result) => {
const profile = result?.profile;
const seedInstance = profile?.seed ?? result?.seed;
const cfg = seedInstance && seedInstance.valid ? config.withSeed(seedInstance) : config;
const info = await proj.getInfo(id, cfg);
if (! result) {
throw new Error("Couldn't load project");
}
const profile = result.profile;
const seed = result.seed || profile?.seed;
if (! seed?.valid) {
throw new Error("Couldn't load project: invalid seed");
}
const info = await proj.getInfo(id, seed.api);
const urn = isRadicleId(id) ? id : info.urn;
const anchors = profile ? await profile.confirmedProjectAnchors(urn, config) : [];
@@ -51,12 +59,12 @@
if (info.delegates) {
// Check for selected peer to override available branches.
if (peer) {
const branchesByPeer = await proj.getBranchesByPeer(urn, peer || info.delegates[0], cfg);
const branchesByPeer = await proj.getBranchesByPeer(urn, peer || info.delegates[0], seed.api);
branches = [...Object.entries(branchesByPeer.heads)];
}
peers = await proj.getPeers(urn, cfg);
peers = await proj.getPeers(urn, seed.api);
}
return { urn, addressOrName, seed, peer, project: info, branches, peers, config: cfg, profile, anchors };
return { urn, addressOrName, seed, peer, project: info, branches, peers, config, profile, anchors };
});
$: if (projectInfo) {
@@ -72,7 +80,16 @@
}
function updateRouteParams({ detail: newParams }: { detail: { urn: string; path: string; revision: string; peer: string; content: proj.ProjectContent } }) {
let newLocation = proj.path({ addressOrName, seed, urn: newParams.urn, content: newParams.content, peer: newParams.peer, revision: newParams.revision, path: newParams.path });
const newLocation = proj.path({
addressOrName,
seed: seedHost,
urn: newParams.urn,
content: newParams.content,
peer: newParams.peer,
revision: newParams.revision,
path: newParams.path
});
if (newLocation !== window.location.pathname) {
navigate(newLocation);
}
@@ -162,7 +179,7 @@
</a>
<span class="divider">/</span>
{/if}
<Link to={proj.path({ urn: result.urn, addressOrName, seed })}>{result.project.name}</Link>
<Link to={proj.path({ urn: result.urn, addressOrName, seed: result.seed.host })}>{result.project.name}</Link>
{#if peer}
<span class="divider" title={peer}>/ {formatSeedId(peer)}</span>
{/if}
@@ -171,10 +188,10 @@
<div class="description">{result.project.description}</div>
</header>
{#await proj.getTree(result.urn, getOid(result.project.head, revision, result.branches), "/", config) then tree}
{#await proj.getTree(result.urn, getOid(result.project.head, revision, result.branches), "/", result.seed.api) then tree}
<Header {tree} {revision} {content} {path}
source={result}
peerSelector={!!seed}
peerSelector={!!seedHost}
on:routeParamsChange={updateRouteParams} />
<ProjectContentRoutes {tree}
source={result}