Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App / M2O: Add option to navigate to related item #23997

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-bulldogs-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@directus/app": patch
---

Added "Item Link" option to M2O interface
14 changes: 14 additions & 0 deletions app/src/interfaces/select-dropdown-m2o/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ export default defineInterface({
},
},
},
{
field: 'enableLink',
name: '$t:item_link',
schema: {
default_value: false,
},
meta: {
interface: 'boolean',
options: {
label: '$t:show_link_to_item',
},
width: 'half',
},
},
];
},
recommendedDisplays: ['related-values'],
Expand Down
33 changes: 26 additions & 7 deletions app/src/interfaces/select-dropdown-m2o/select-dropdown-m2o.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { render } from 'micromustache';
import { computed, inject, ref, toRefs } from 'vue';
import { useI18n } from 'vue-i18n';
import { getItemRoute } from '@/utils/get-route';

const props = withDefaults(
defineProps<{
Expand All @@ -26,6 +27,7 @@
enableCreate?: boolean;
enableSelect?: boolean;
loading?: boolean;
enableLink?: boolean;
}>(),
{
value: null,
Expand All @@ -35,6 +37,7 @@
filter: null,
enableCreate: true,
enableSelect: true,
enableLink: false,
},
);

Expand Down Expand Up @@ -158,6 +161,11 @@

selectModalActive.value = false;
}

function getLinkForItem() {
if (!collection.value || !currentPrimaryKey.value || !relationInfo.value) return '';
return getItemRoute(relationInfo.value.relatedCollection.collection, currentPrimaryKey.value);
}
</script>

<template>
Expand Down Expand Up @@ -194,7 +202,16 @@

<template #append>
<template v-if="displayItem">
<v-icon v-tooltip="t('edit')" name="open_in_new" class="edit" @click="editModalActive = true" />
<router-link
v-if="enableLink"
v-tooltip="t('navigate_to_item')"
@click.stop
:to="getLinkForItem()"

Check warning on line 209 in app/src/interfaces/select-dropdown-m2o/select-dropdown-m2o.vue

View workflow job for this annotation

GitHub Actions / Lint

Attribute ":to" should go before "@click.stop"
class="item-link"

Check warning on line 210 in app/src/interfaces/select-dropdown-m2o/select-dropdown-m2o.vue

View workflow job for this annotation

GitHub Actions / Lint

Attribute "class" should go before "@click.stop"
>
<v-icon name="launch" />
</router-link>
<v-icon v-if="!disabled" v-tooltip="t('edit')" name="edit" class="edit" @click="editModalActive = true" />
<v-icon
v-if="!disabled"
v-tooltip="t('deselect')"
Expand Down Expand Up @@ -243,6 +260,7 @@

:deep(.v-input .append) {
display: flex;
gap: 4px;
}
}

Expand All @@ -266,16 +284,17 @@
}
}

.edit {
margin-right: 4px;

.item-link,
.add {
&:hover {
--v-icon-color: var(--theme--form--field--input--foreground);
--v-icon-color: var(--theme--primary);
}
}

.add:hover {
--v-icon-color: var(--theme--primary);
.edit {
&:hover {
--v-icon-color: var(--theme--form--field--input--foreground);
}
}

.deselect:hover {
Expand Down
Loading