Skip to content

Commit

Permalink
Merge pull request #145 from cytechmobile/fix/105_patch-list-missing-…
Browse files Browse the repository at this point in the history
…items
  • Loading branch information
maninak authored Jul 16, 2024
2 parents 3acedd1 + 771c77e commit 29d07d7
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@
- **markdown:** make the language tag on (recognised) code blocks not user-selectable
- **patch-detail:** homogenize all tooltips and controls to have their copy in Title Case
- **log:** show the actual output of failed rad commands (which explains _why_ it failed...) instead of sometimes showing the CLI's progress-spinnner characters spammed en masse
- **patch-list:** show all patches again as expected, not only those with status "open". Addresses regression caused due to a breaking change in Radicle HTTP API (httpd) while keeping backwards compatibility for users who haven't yet upgraded to the latest httpd

### 💅 Refactors

2 changes: 1 addition & 1 deletion src/helpers/fetchFromHttpd.ts
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ export async function fetchFromHttpd(
): FetchFromHttpdReturn<Patch>
export async function fetchFromHttpd(
path: `/projects/rad:${string}/patches`,
options?: FetchOptions<'json'> & { query?: { state: PatchStatus }; method?: 'GET' },
options?: FetchOptions<'json'> & { query?: { status: PatchStatus | 'all' }; method?: 'GET' },
): FetchFromHttpdReturn<Patch[]>
export async function fetchFromHttpd<RevBase extends string, RevOid extends string>(
path: `/projects/rad:${string}/diff/${RevBase}/${RevOid}`,
23 changes: 18 additions & 5 deletions src/stores/patchStore.ts
Original file line number Diff line number Diff line change
@@ -98,20 +98,33 @@ export const usePatchStore = defineStore('patch', () => {
}
}

// Backwards compatibility with non-latest httpd versions while users are transitioning.
// Should be removed in a couple of months.
let queryKey = 'status' as const
const httpdApiVersionMajor = (await fetchFromHttpd('/')).data?.apiVersion[0]
if (httpdApiVersionMajor && Number.parseInt(httpdApiVersionMajor) < 3) {
queryKey = 'state' as 'status'
}

const rid = useEnvStore().currentRepoId
if (!rid) {
return false
}
const nowTs = Date.now() / 1000 // we devide to align with the httpd's timestamp format
lastFetchedAllTs.value = nowTs
// TODO: refactor to make only a single request when https://radicle.zulipchat.com/#narrow/stream/369873-support/topic/fetch.20all.20patches.20in.20one.20req is resolved
const promisedResponses = Promise.all([
fetchFromHttpd(`/projects/${rid}/patches`, { query: { state: 'draft', perPage: 500 } }),
fetchFromHttpd(`/projects/${rid}/patches`, { query: { state: 'open', perPage: 500 } }),
fetchFromHttpd(`/projects/${rid}/patches`, {
query: { state: 'archived', perPage: 500 },
query: { [queryKey]: 'draft', perPage: 500 },
}),
fetchFromHttpd(`/projects/${rid}/patches`, {
query: { [queryKey]: 'open', perPage: 500 },
}),
fetchFromHttpd(`/projects/${rid}/patches`, {
query: { [queryKey]: 'archived', perPage: 500 },
}),
fetchFromHttpd(`/projects/${rid}/patches`, {
query: { [queryKey]: 'merged', perPage: 500 },
}),
fetchFromHttpd(`/projects/${rid}/patches`, { query: { state: 'merged', perPage: 500 } }),
]).finally(() => (inProgressRequest = undefined))
inProgressRequest = promisedResponses

3 changes: 2 additions & 1 deletion src/types/httpd.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ export interface HttpdRoot {
message: string
service: string
version: string
node: { id: string } // TODO: maninak handle breaking change https://radicle.zulipchat.com/#narrow/stream/369278-web/topic/breaking.20changes.20in.20HTTPD/near/409172640
apiVersion: string
nid: string
path: string
links: {
href: string

0 comments on commit 29d07d7

Please sign in to comment.