forked from potsda.mn/mobilizon
fix(participant exports): fix participants by returning the export type as well as the file path
We previously used the Apollo context but that's really unreliable. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
a5a86a5e1b
commit
49b04c9b19
|
@ -482,6 +482,9 @@ export const EXPORT_EVENT_PARTICIPATIONS = gql`
|
||||||
$format: ExportFormatEnum
|
$format: ExportFormatEnum
|
||||||
$roles: [ParticipantRoleEnum]
|
$roles: [ParticipantRoleEnum]
|
||||||
) {
|
) {
|
||||||
exportEventParticipants(eventId: $eventId, format: $format, roles: $roles)
|
exportEventParticipants(eventId: $eventId, format: $format, roles: $roles) {
|
||||||
|
path
|
||||||
|
format
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -55,22 +55,16 @@
|
||||||
:key="format"
|
:key="format"
|
||||||
aria-role="listitem"
|
aria-role="listitem"
|
||||||
@click="
|
@click="
|
||||||
exportParticipants(
|
exportParticipants({
|
||||||
{
|
eventId: event.id ?? '',
|
||||||
eventId: event?.id,
|
|
||||||
format,
|
format,
|
||||||
},
|
})
|
||||||
{ context: { type: format } }
|
|
||||||
)
|
|
||||||
"
|
"
|
||||||
@keyup.enter="
|
@keyup.enter="
|
||||||
exportParticipants(
|
exportParticipants({
|
||||||
{
|
eventId: event.id ?? '',
|
||||||
eventId: event?.id,
|
|
||||||
format,
|
format,
|
||||||
},
|
})
|
||||||
{ context: { type: format } }
|
|
||||||
)
|
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<button class="dropdown-button">
|
<button class="dropdown-button">
|
||||||
|
@ -380,15 +374,15 @@ const {
|
||||||
mutate: exportParticipants,
|
mutate: exportParticipants,
|
||||||
onDone: onExportParticipantsMutationDone,
|
onDone: onExportParticipantsMutationDone,
|
||||||
onError: onExportParticipantsMutationError,
|
onError: onExportParticipantsMutationError,
|
||||||
} = useMutation(EXPORT_EVENT_PARTICIPATIONS);
|
} = useMutation<
|
||||||
|
{ exportEventParticipants: { path: string; format: string } },
|
||||||
|
{ eventId: string; format?: exportFormat; roles?: string[] }
|
||||||
|
>(EXPORT_EVENT_PARTICIPATIONS);
|
||||||
|
|
||||||
onExportParticipantsMutationDone(({ data, context }) => {
|
onExportParticipantsMutationDone(({ data }) => {
|
||||||
const link =
|
const path = data?.exportEventParticipants?.path;
|
||||||
window.origin +
|
const format = data?.exportEventParticipants?.format;
|
||||||
"/exports/" +
|
const link = window.origin + "/exports/" + format?.toLowerCase() + "/" + path;
|
||||||
context?.type.toLowerCase() +
|
|
||||||
"/" +
|
|
||||||
data?.exportEventParticipants;
|
|
||||||
console.debug(link);
|
console.debug(link);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.style.display = "none";
|
a.style.display = "none";
|
||||||
|
|
|
@ -302,7 +302,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||||
if can_event_be_updated_by?(event, moderator_actor) do
|
if can_event_be_updated_by?(event, moderator_actor) do
|
||||||
case export_format(format, event, roles, locale) do
|
case export_format(format, event, roles, locale) do
|
||||||
{:ok, path} ->
|
{:ok, path} ->
|
||||||
{:ok, path}
|
{:ok, %{path: path, format: format}}
|
||||||
|
|
||||||
{:error, :export_dependency_not_installed} ->
|
{:error, :export_dependency_not_installed} ->
|
||||||
{:error,
|
{:error,
|
||||||
|
|
|
@ -61,6 +61,12 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||||
field(:total, :integer, description: "The total number of participants in the list")
|
field(:total, :integer, description: "The total number of participants in the list")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :participant_export do
|
||||||
|
meta(:authorize, :user)
|
||||||
|
field(:path, :string, description: "The path to the exported file")
|
||||||
|
field(:format, :export_format_enum, description: "The path to the exported file")
|
||||||
|
end
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
The possible values for a participant role
|
The possible values for a participant role
|
||||||
"""
|
"""
|
||||||
|
@ -132,7 +138,7 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Export the event participants as a file"
|
@desc "Export the event participants as a file"
|
||||||
field :export_event_participants, :string do
|
field :export_event_participants, :participant_export do
|
||||||
arg(:event_id, non_null(:id),
|
arg(:event_id, non_null(:id),
|
||||||
description: "The ID from the event for which to export participants"
|
description: "The ID from the event for which to export participants"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue