Skip to content

Commit

Permalink
feat: link actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed Sep 24, 2024
1 parent 73d651d commit 5b73642
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/adomin/routes/actions/model_global_action_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const modelGlobalActionRoute = async (ctx: HttpContext) => {
}
const found = modelConfig.globalActions?.find(({ name }) => name === params.action)

if (!found) {
if (!found || found.type !== 'backend-action') {
return response.notFound({ error: `Action '${params.action}' not found` })
}

Expand Down
2 changes: 1 addition & 1 deletion app/adomin/routes/actions/model_instance_action_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const modelInstanceActionRoute = async (ctx: HttpContext) => {
}
const found = modelConfig.instanceActions?.find(({ name }) => name === params.action)

if (!found) {
if (!found || found.type !== 'backend-action') {
return response.notFound({ error: `Action '${params.action}' not found` })
}

Expand Down
14 changes: 14 additions & 0 deletions app/adomin/routes/adomin_routes_overrides_and_rights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ export type AdominActionConfig = {
iconColor?: string
/** Tooltip shown on the frontend, when hovering the button */
tooltip: string
} & AdominActionTypes

type AdominActionTypes = AdominActionLink | AdominActionBackend

export interface AdominActionBackend {
type: 'backend-action'
/** Your action function */
action: AdominActionFunction
}

export interface AdominActionLink {
type: 'link'
/** Link to open */
href: string
/** Open the link in a new tab @default false */
openInNewTab?: boolean
}
20 changes: 20 additions & 0 deletions app/test_adomin_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const IDEA_CONFIG = createModelViewConfig(() => Idea, {
icon: 'bulb',
globalActions: [
{
type: 'backend-action',
name: 'add-random-idea',
tooltip: 'Ajouter une idée random',
icon: 'arrows-shuffle',
Expand All @@ -199,6 +200,7 @@ export const IDEA_CONFIG = createModelViewConfig(() => Idea, {
},
},
{
type: 'backend-action',
name: 'delete-ideas-not-linked-to-user',
tooltip: 'Supprimer les idées non liées à un utilisateur',
icon: 'trash',
Expand All @@ -209,9 +211,27 @@ export const IDEA_CONFIG = createModelViewConfig(() => Idea, {
return { message: 'Suppression effectuée' }
},
},
{
type: 'link',
name: 'link-to-filtered-ideas',
tooltip: 'Voir les idées filtrées',
icon: 'link',
iconColor: 'blue',
href: '/backoffice/models/Idea?filters=%255B%257B%2522id%2522%253A%2522title%2522%252C%2522value%2522%253A%2522test%2522%257D%255D&sorting=%255B%257B%2522id%2522%253A%2522id%2522%252C%2522desc%2522%253Atrue%257D%255D',
},
{
type: 'link',
name: 'link-to-google',
tooltip: 'Voir Google',
icon: 'brand-google',
iconColor: 'green',
href: 'https://www.google.com',
openInNewTab: true,
},
],
instanceActions: [
{
type: 'backend-action',
name: 'duplicate-idea',
tooltip: "Dupliquer l'idée",
icon: 'copy',
Expand Down

0 comments on commit 5b73642

Please sign in to comment.