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

Add a team link component to simplify routing #4942

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions frontend/src/components/DevicesBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@
You can deploy <router-link class="ff-link" :to="{name: 'instance-snapshots', params: {id: instance.id}}">Snapshots</router-link> of this Instance to your connected Devices.
</p>
<p>
A full list of your Team's Devices are available <router-link
A full list of your Team's Devices are available <ff-team-link
class="ff-link"
:to="{name: 'TeamDevices', params: {team_slug: team.slug}}"
>
here
</router-link>.
</ff-team-link>.
</p>
</template>
<template #actions>
Expand Down Expand Up @@ -192,12 +192,12 @@
You can deploy <router-link class="ff-link" :to="{name: 'ApplicationSnapshots'}">Snapshots</router-link> of this Application to your connected Devices.
</p>
<p>
A full list of your Team's Devices are available <router-link
A full list of your Team's Devices are available <ff-team-link
class="ff-link"
:to="{name: 'TeamDevices', params: {team_slug: team.slug}}"
>
here
</router-link>.
</ff-team-link>.
</p>
</template>
<template #actions>
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/components/router-links/TeamLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<router-link
v-slot="{ href, navigate }"
v-bind="extendedProps"
custom
>
<a
v-bind="$attrs"
:href="href"
@click="navigate"
>
<slot />
</a>
</router-link>
</template>

<script>
import { RouterLink as DefaultRouterLink } from 'vue-router'
import { mapState } from 'vuex'

export default {
name: 'TeamLink',
inheritAttrs: false,
props: {
...DefaultRouterLink.props
},
computed: {
...mapState('account', ['team']),
extendedProps () {
const props = { ...this.$props }
if (!props.to.params.team_slug) {
props.to.params.team_slug = this.team.slug
Copy link
Contributor

@joepavitt joepavitt Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and in a circumstance where this.team is undefined? I appreciate our use case here is for when we do have a team, but new users wont' have a this.team, so technically we should handle this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a valid point, will have to go through the sign-up procedure and check but from the top of my head users shouldn't encounter team-links only after being assigned to a team and have the full ui at their disposal.

I'll have a look over it later after this current release when i'll have some spare time on my hands, this is not an important task

}
return props
}
}
}
</script>
2 changes: 2 additions & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import VueShepherdPlugin from 'vue-shepherd'
import App from './App.vue'
import Loading from './components/Loading.vue'
import SectionNavigationHeader from './components/SectionNavigationHeader.vue'
import TeamLink from './components/router-links/TeamLink.vue'
import PageLayout from './layouts/Page.vue'
import router from './routes.js'
import Alerts from './services/alerts.js'
Expand All @@ -38,6 +39,7 @@ app.component('lottie-animation', LottieAnimation)
app.component('ff-page', PageLayout)
app.component('ff-page-header', SectionNavigationHeader)
app.component('ff-loading', Loading)
app.component('ff-team-link', TeamLink)

app.config.errorHandler = function (err, vm, info) {
// Uncaught XHR errors bubble to here
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/device/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<template #content>
<InfoCardRow property="Application:">
<template #value>
<router-link v-if="device?.application" :to="{name: 'Application', params: { id: device.application.id, team_slug: team.slug }}">
<ff-team-link v-if="device?.application" :to="{name: 'Application', params: { id: device.application.id }}">
{{ device.application?.name }}
</router-link>
</ff-team-link>
<span v-else>None</span>
</template>
</InfoCardRow>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/device/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<template #context>
<div v-if="device?.ownerType === 'application' && device.application" data-el="device-assigned-application">
Application:
<router-link :to="{name: 'Application', params: {team_slug: team.slug, id: device.application?.id}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">{{ device.application?.name }}</router-link>
<ff-team-link :to="{name: 'Application', params: {id: device.application?.id}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">{{ device.application?.name }}</ff-team-link>
</div>
<div v-else-if="device?.ownerType === 'instance' && device.instance" data-el="device-assigned-instance">
Instance:
<router-link :to="{name: 'Instance', params: {id: device.instance.id}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">{{ device.instance.name }}</router-link>
<ff-team-link :to="{name: 'Instance', params: {id: device.instance.id}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">{{ device.instance.name }}</ff-team-link>
</div>
<div v-else data-el="device-assigned-none">
<span class="italic">No Application or Instance Assigned</span> - <a class="ff-link" data-action="assign-device" @click="openAssignmentDialog">Assign</a>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pages/instance/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
</template>
<template #context>
Application:
<router-link :to="{name: 'Application', params: {id: instance.application.id, team_slug: team.slug}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">{{ instance.application.name }}</router-link>
<ff-team-link :to="{name: 'Application', params: {id: instance.application.id}}" class="text-blue-600 cursor-pointer hover:text-blue-700 hover:underline">
{{ instance.application.name }}
</ff-team-link>
</template>
<template #tools>
<div class="space-x-2 flex align-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</p>
<p class="my-4">
If you want your device to be automatically registered to an instance, in order to remotely deploy flows, you can use provisioning tokens
in your <router-link :to="{'name': 'TeamSettingsDevices', 'params': {team_slug: team.slug}}">Team Settings</router-link>
in your <ff-team-link :to="{'name': 'TeamSettingsDevices', 'params': {team_slug: team.slug}}">Team Settings</ff-team-link>
</p>
<p class="my-4">
Further info on Devices can be found
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/team/Instances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
<template #header>Get Started with your First Node-RED Instance</template>
<template #message>
<p>
Instances are managed in FlowFuse via <router-link
Instances are managed in FlowFuse via <ff-team-link
class="ff-link"
:to="{name:'Applications', params: {team_slug: team.slug}}"
>
Applications
</router-link>.
</ff-team-link>.
</p>
<p>
You can create your first Instance when creating your first Application, or add an Instance to an existing Application if you have one.
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/team/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default [
backTo: ({ team }) => {
return {
label: 'Back to Dashboard',
to: { name: 'Team', params: { team_slug: team.slug } }
to: { name: 'Team', params: { team_slug: team?.slug } }
}
}
}
Expand Down
Loading