Skip to content

Commit

Permalink
Fix: Mobile - Fix links to organization tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Sep 1, 2022
1 parent 96993bd commit f2175eb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@

<script setup lang="ts">
import { TicketState } from '@shared/entities/ticket/types'
import { replaceTags } from '@shared/utils/formatter'
import CommonSectionMenu from '../CommonSectionMenu/CommonSectionMenu.vue'
import CommonSectionMenuLink from '../CommonSectionMenu/CommonSectionMenuLink.vue'

interface Props {
createLink?: string
createLabel?: string
counts: Record<TicketState.Closed | TicketState.Open, number>
ticketsLink(state: TicketState.Closed | TicketState.Open): string
ticketsLinkQuery: string
}

defineProps<Props>()
const props = defineProps<Props>()

const getTicketsLink = (stateIds: number[]) => {
const states = stateIds
.map((stateId) => `state.state_type_id: ${stateId}`)
.join(' OR ')
return replaceTags(`/search/ticket?search=(${states}) AND #{query}`, {
query: props.ticketsLinkQuery,
})
}
</script>

<template>
<CommonSectionMenu header-label="Tickets">
<CommonSectionMenuLink
:icon="{ name: 'state-open', size: 'base', class: 'text-yellow' }"
:information="counts[TicketState.Open]"
:link="ticketsLink(TicketState.Open)"
:link="getTicketsLink([1, 2, 3, 4])"
>
{{ $t('open') }}
</CommonSectionMenuLink>
<CommonSectionMenuLink
:icon="{ name: 'state-closed', size: 'base', class: 'text-green' }"
:information="counts[TicketState.Closed]"
:link="ticketsLink(TicketState.Closed)"
:link="getTicketsLink([5])"
>
{{ $t('closed') }}
</CommonSectionMenuLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ describe('show tickets', () => {
[TicketState.Closed]: 1,
[TicketState.Open]: 3,
},
ticketsLink: (state: TicketState) => `/tickets?state=${state}`,
ticketsLinkQuery: `organization.name: "name"`,
},
router: true,
store: true,
})

const links = view.getAllByRole('link')

expect(links[0]).toHaveAttribute('href', '/tickets?state=open')
expect(links[0]).toHaveAttribute(
'href',
'/search/ticket?search=(state.state_type_id: 1 OR state.state_type_id: 2 OR state.state_type_id: 3 OR state.state_type_id: 4) AND organization.name: "name"',
)
expect(links[0]).toHaveTextContent('open')
expect(links[0]).toHaveTextContent('3')

expect(links[1]).toHaveAttribute('href', '/tickets?state=closed')
expect(links[1]).toHaveAttribute(
'href',
'/search/ticket?search=(state.state_type_id: 5) AND organization.name: "name"',
)
expect(links[1]).toHaveTextContent('closed')
expect(links[1]).toHaveTextContent('1')
})
Expand All @@ -36,7 +42,7 @@ describe('show tickets', () => {
[TicketState.Closed]: 1,
[TicketState.Open]: 3,
},
ticketsLink: (state: TicketState) => `/tickets?state=${state}`,
ticketsLinkQuery: `organization.name: "name"`,
createLabel: 'Create ticket',
createLink: '/tickets/create',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('static organization', () => {

expect(openTickets).toHaveAttribute(
'href',
'/search/ticket?state=open&organization_id=1vs2dr3041dsa9',
expect.stringContaining('organization.name: "Some Organization"'),
)
expect(closedTickets).toHaveAttribute(
'href',
'/search/ticket?state=closed&organization_id=1vs2dr3041dsa9',
expect.stringContaining('organization.name: "Some Organization"'),
)

await mockSubscription.next({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ const loadAllMembers = () => {
membersCount: null,
})
}

const ticketsLinkQuery = computed(() => {
return `organization.name: "${organization.value?.name}"`
})
</script>

<template>
Expand Down Expand Up @@ -116,10 +120,7 @@ const loadAllMembers = () => {
:create-link="`/tickets/create?organization_id=${organization.id}`"
:create-label="__('Create new ticket for this organization')"
:counts="organization.ticketsCount"
:tickets-link="
(state) =>
`/search/ticket?state=${state}&organization_id=${organization?.id}`
"
:tickets-link-query="ticketsLinkQuery"
/>
</div>
<CommonLoader
Expand Down

0 comments on commit f2175eb

Please sign in to comment.