Skip to content

Commit

Permalink
Merge branch 'fix-merge-alias' of 'https://github.com/evamillan/grimo…
Browse files Browse the repository at this point in the history
  • Loading branch information
sduenas authored Sep 18, 2024
2 parents 887c62c + 3cc4cc9 commit 23087a7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
10 changes: 10 additions & 0 deletions releases/unreleased/merge-organizations-when-adding-an-alias.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Merge organizations when adding an alias
category: added
author: Eva Millán <evamillan@bitergia.com>
issue: null
notes: >
Users now have the option to merge the organizations
when adding an alias that already exists on the
"Edit organization" dialog. That option was only
previously available at the organization's detail page.
71 changes: 61 additions & 10 deletions ui/src/components/OrganizationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,30 @@
</v-btn>
</v-col>
</v-row>
<v-row class="pl-3 mt-2">
<v-row class="pl-3 my-2">
<v-btn size="small" color="primary" @click="form.aliases.push('')">
<v-icon size="small" color="primary" start
>> mdi-plus-circle-outline
<v-icon size="small" color="primary" start>
mdi-plus-circle-outline
</v-icon>
Add alias
</v-btn>
</v-row>
<v-alert v-if="errorMessage" text type="error" class="mt-3">
{{ errorMessage }}
<v-alert
v-if="errorMessage"
:type="mergeAlias ? 'warning' : 'error'"
class="mt-4"
>
<p>{{ errorMessage }}</p>

<v-btn
v-if="mergeAlias"
class="mt-2 bg-surface-secondary"
variant="outlined"
size="small"
@click="mergeOrgs(mergeAlias, organization)"
>
Merge
</v-btn>
</v-alert>
</v-card-text>
<v-card-actions>
Expand Down Expand Up @@ -170,6 +184,10 @@ export default {
type: Function,
required: true,
},
merge: {
type: Function,
required: true,
},
},
data() {
return {
Expand All @@ -183,6 +201,7 @@ export default {
name: undefined,
domains: [],
},
mergeAlias: null,
};
},
methods: {
Expand All @@ -191,6 +210,7 @@ export default {
},
async onSave() {
this.errorMessage = "";
this.mergeAlias = null;
if (!this.savedData.name) {
try {
const response = await this.addOrganization(this.form.name);
Expand Down Expand Up @@ -326,17 +346,26 @@ export default {
},
async addOrganizationAlias(alias, organization) {
const response = await this.addAlias(alias, organization);
if (response && !response.error) {
if (response && !response.errors) {
this.savedData.aliases.push(alias);
this.$logger.debug(
`Added alias ${alias} to organization ${organization}`
);
return response;
} else if (response.errors) {
this.$logger.error(
`Error adding alias: ${response.errors[0].message}`,
{ alias, organization }
);
let error = response.errors[0].message;
const orgAlreadyExists = response.errors.find((error) => {
return (
error.extensions.code === 2 &&
error.message.includes("Organization")
);
});
if (orgAlreadyExists) {
this.mergeAlias = alias;
error += `. Click 'merge' to turn it into an alias of '${this.organization}'.`;
}
throw new Error(error);
}
},
async deleteOrganizationAlias(alias) {
Expand All @@ -346,6 +375,19 @@ export default {
return response;
}
},
async mergeOrgs(fromOrg, toOrg) {
try {
const response = await this.merge(fromOrg, toOrg);
if (response && !response.errors) {
this.$logger.debug(`Merged ${fromOrg} into organization ${toOrg}`);
this.$emit("updateOrganizations");
this.closeModal();
}
} catch (error) {
this.errorMessage = this.$getErrorMessage(error);
this.$logger.error(`Error merging organizations: ${error}`);
}
},
},
watch: {
isOpen(value) {
Expand Down Expand Up @@ -376,3 +418,12 @@ export default {
},
};
</script>
<style lang="scss" scoped>
.text-warning {
border: thin solid;
:deep(.v-alert__content) {
color: rgb(var(--v-theme-on-surface));
}
}
</style>
1 change: 1 addition & 0 deletions ui/src/components/OrganizationsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
:aliases="modal.aliases"
:add-alias="addAlias"
:delete-alias="deleteAlias"
:merge="mergeItems"
@updateOrganizations="getTableItems(page)"
/>

Expand Down

0 comments on commit 23087a7

Please sign in to comment.