From a63876c56c8750eeb20c4906d464038735a406fd Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Tue, 12 Oct 2021 16:12:48 +0100 Subject: [PATCH 1/3] fix(server): fixes branch author resolver - was broken before --- packages/server/modules/core/graph/resolvers/branches.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/modules/core/graph/resolvers/branches.js b/packages/server/modules/core/graph/resolvers/branches.js index ead662b44..f170f1699 100644 --- a/packages/server/modules/core/graph/resolvers/branches.js +++ b/packages/server/modules/core/graph/resolvers/branches.js @@ -41,7 +41,7 @@ module.exports = { Branch: { async author( parent, args, context, info ) { - if ( parent.userId ) + if ( parent.authorId && context.auth ) return await getUserById( { userId: parent.authorId } ) else return null } From f57ac6ea3c5af9ca18830e7a28514a7bb7ed1aeb Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Tue, 12 Oct 2021 16:17:58 +0100 Subject: [PATCH 2/3] feat(frontend): implements hierarchical branch display in sidebar --- .../components/dialogs/BranchEditDialog.vue | 28 ++- .../components/dialogs/BranchNewDialog.vue | 6 +- packages/frontend/src/views/stream/Branch.vue | 24 ++- packages/frontend/src/views/stream/Stream.vue | 159 +++++++++++++++++- 4 files changed, 190 insertions(+), 27 deletions(-) diff --git a/packages/frontend/src/components/dialogs/BranchEditDialog.vue b/packages/frontend/src/components/dialogs/BranchEditDialog.vue index 45260a8ef..824646ce0 100644 --- a/packages/frontend/src/components/dialogs/BranchEditDialog.vue +++ b/packages/frontend/src/components/dialogs/BranchEditDialog.vue @@ -14,7 +14,9 @@ mdi-close - + + {{ error }} + +

+ Tip: you can create nested branches by using "/" as a separator in their names. E.g., + "mep/stage-1" or "arch/sketch-design". +

@@ -79,7 +85,8 @@ export default { ], isEdit: false, pendingDelete: false, - allBranchNames: [] + allBranchNames: [], + error: null } }, apollo: { @@ -125,6 +132,7 @@ export default { methods: { async deleteBranch() { this.loading = true + this.error = null this.$matomo && this.$matomo.trackPageView('branch/delete') try { await this.$apollo.mutate({ @@ -141,16 +149,18 @@ export default { } }) } catch (e) { - console.log(e) + this.error = e.message } this.loading = false - - this.resolve({ - result: true, - deleted: true - }) - this.dialog = false + this.showDelete = false + if (!this.error) { + this.resolve({ + result: true, + deleted: true + }) + this.dialog = false + } }, open(branch) { this.dialog = true diff --git a/packages/frontend/src/components/dialogs/BranchNewDialog.vue b/packages/frontend/src/components/dialogs/BranchNewDialog.vue index 8a788c99a..b8ff26519 100644 --- a/packages/frontend/src/components/dialogs/BranchNewDialog.vue +++ b/packages/frontend/src/components/dialogs/BranchNewDialog.vue @@ -22,6 +22,10 @@ required autofocus > +

+ Tip: you can create nested branches by using "/" as a separator in their names. E.g., + "mep/stage-1" or "arch/sketch-design". +

@@ -45,7 +49,7 @@ export default { reservedBranchNames: ['main', 'globals'], valid: false, loading: false, - name: null, + name: '', nameRules: [ (v) => !!v || 'Branches need a name too!', (v) => diff --git a/packages/frontend/src/views/stream/Branch.vue b/packages/frontend/src/views/stream/Branch.vue index 4a0f9df98..6a2d5d3f0 100644 --- a/packages/frontend/src/views/stream/Branch.vue +++ b/packages/frontend/src/views/stream/Branch.vue @@ -6,9 +6,9 @@ {{ stream.branch.name }} {{ stream.branch.description }} mdi-source-commit {{ stream.branch.commits.totalCount }} @@ -17,7 +17,6 @@ mdi-pencil @@ -44,11 +44,11 @@ -
+
- + - -

Branch "{{stream.branch.name}}" has no commits.

+

Branch "{{ stream.branch.name }}" has no commits.

{{ error || `Branch "${$route.params.branchName}" does not exist.` }}

@@ -162,6 +161,10 @@ export default { else return null } }, + mounted() { + if (this.$route.params.branchName === 'globals') + this.$router.push(`/streams/${this.$route.params.streamId}/globals`) + }, methods: { editBranch() { this.$refs.editBranchDialog.open(this.stream.branch).then((dialog) => { @@ -181,11 +184,6 @@ export default { } }) } - }, - mounted() { - console.log(this.$route.params) - if (this.$route.params.branchName === 'globals') - this.$router.push(`/streams/${this.$route.params.streamId}/globals`) } } diff --git a/packages/frontend/src/views/stream/Stream.vue b/packages/frontend/src/views/stream/Stream.vue index 334efd162..da3ead37b 100644 --- a/packages/frontend/src/views/stream/Stream.vue +++ b/packages/frontend/src/views/stream/Stream.vue @@ -106,7 +106,7 @@ - + mdi-home @@ -118,7 +118,7 @@ - + + + + + + + + mdi-plus-box + + + New Branch + + Create a new branch to help categorise your commits. + + + + + +
+ +
+
@@ -539,6 +639,10 @@ export default { items { name description + author { + id + name + } commits { totalCount } @@ -551,6 +655,10 @@ export default { return { id: this.$route.params.streamId } + }, + update: (data) => { + // console.log(data.branchQuery.branches.items) + return data.branchQuery } }, $subscribe: { @@ -598,6 +706,43 @@ export default { } }, computed: { + groupedBranches() { + if (!this.branchQuery) return + let branches = this.branchQuery.branches.items + let items = [] + for (let b of branches) { + if (b.name === 'globals') continue + let parts = b.name.split('/') + if (parts.length === 1) { + items.push({ ...b, displayName: b.name, type: 'item', children: [] }) + } else { + let existing = items.find((i) => i.name === parts[0] && i.type === 'group') + if (!existing) { + existing = { name: parts[0], type: 'group', children: [], expand: false } + items.push(existing) + } + existing.children.push({ + ...b, + displayName: parts.slice(1).join('/'), + type: 'item' + }) + if (this.$route.path.includes(b.name)) existing.expand = true + } + } + let sorted = items.sort((a, b) => { + const nameA = a.name.toLowerCase() + const nameB = b.name.toLowerCase() + if (nameA < nameB) return -1 + if (nameA > nameB) return 1 + return 0 + }) + + return [ + ...sorted.filter((it) => it.name === 'main'), + ...sorted.filter((it) => it.name !== 'main') + ] + // return items + }, streamUrl() { return `${window.location.origin}/streams/${this.$route.params.streamId}` }, @@ -631,14 +776,20 @@ export default { } }, watch: { - $route() { + $route(to) { // Ensures branch menu is open when navigating to a branch url - if (this.$route.name.toLowerCase().includes('branch') && !this.branchMenuOpen) + if (to.name.toLowerCase().includes('branch') && !this.branchMenuOpen) this.branchMenuOpen = true // closes any share dialog this.shareStream = false this.snackbar = false } + // branchMenuOpen(val) { + // if (this.$route.name.toLowerCase().includes('branch') && !val) + // this.$nextTick(() => { + // this.branchMenuOpen = true + // }) + // } }, mounted() { setTimeout( From a3eea734fc9baaad42915caab2c0e1272c2be9b4 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Tue, 12 Oct 2021 16:24:36 +0100 Subject: [PATCH 3/3] chore(frontend): cleanup of stale code --- packages/frontend/src/views/stream/Stream.vue | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/packages/frontend/src/views/stream/Stream.vue b/packages/frontend/src/views/stream/Stream.vue index da3ead37b..37b7c15ce 100644 --- a/packages/frontend/src/views/stream/Stream.vue +++ b/packages/frontend/src/views/stream/Stream.vue @@ -117,58 +117,6 @@
- - -