Skip to content

Commit

Permalink
Correctly map card references in series
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed Aug 1, 2018
1 parent dcca4c8 commit 02bf717
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
32 changes: 31 additions & 1 deletion metabase-exporter/ApiObjects.cs
Expand Up @@ -210,7 +210,37 @@ public class DashboardCard
public JObject VisualizationSettings { get; set; }

[JsonProperty("series")]
public object[] Series { get; set; }
public DashboardSeriesCard[] Series { get; set; }
}

/// <summary>
/// A reference to a <see cref="Card"/> in a series (i.e. 2 or more overlapped graphs) in a dashboard.
/// </summary>
public class DashboardSeriesCard
{
/// <summary>
/// References <see cref="Card.Id"/>
/// </summary>
[JsonProperty("id")]
public int Id { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

[JsonProperty("collection_id")]
public int? CollectionId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("display")]
public string Display { get; set; }

[JsonProperty("dataset_query")]
public DatasetQuery DatasetQuery { get; set; }

[JsonProperty("visualization_settings")]
public JObject VisualizationSettings { get; set; } // ?
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions metabase-exporter/MetabaseApiExport.cs
Expand Up @@ -45,6 +45,11 @@ public static async Task<MetabaseState> Export(this MetabaseApi api)
{
parameter.CardId = cardMapping[parameter.CardId];
}

foreach (var seriesCard in card.Series)
{
seriesCard.Id = cardMapping[seriesCard.Id];
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions metabase-exporter/MetabaseApiImport.cs
Expand Up @@ -126,6 +126,14 @@ static IEnumerable<DashboardCard> MapDashboardCards(IEnumerable<DashboardCard> s
.Select(x => x.Target)
.First();
}

foreach (var s in card.Series)
{
s.Id = cardMapping
.Where(x => x.Source == s.Id)
.Select(x => x.Target)
.First();
}
yield return card;
}
}
Expand Down

0 comments on commit 02bf717

Please sign in to comment.