discourse/app/assets/javascripts/admin/addon/templates/dashboard_general.hbs
David Taylor c1f74cd92a
DEV: Update default tagName and connectorTagName for plugin outlets (#13685)
This commit should be a no-op for all existing core outlets. Outlets which are introduced by themes/plugins may see a change in behavior, and should follow the steps below if they want to maintain their previous behavior.

`tagName="" connectorTagName=""` is almost always the correct choice for plugin outlets. 40eba8cd introduced a `noTags=true` shortcut which achieved this, and left a comment saying it should be the future default. This commit does exactly that. To avoid any breaking changes for plugins, all existing plugin outlets have been reviewed and adjusted by following this logic:

1) If `noTags=true`, remove the `noTags` parameter, and do not complete any further steps
2) If `tagName` is not specified, set `tagName="span"` (the previous default)
3) If `connectorTagName` is not specified, set `selectorTagName="div"` (the previous default)
4) If `tagName=""`, remove it
5) If `connectorTagName=""`, remove it

The updates were accomplished with the help of a ruby script:

```ruby
def removeAttr(tag, attribute)
  tag = tag.sub /\s#{attribute}="?\w*"? /, " "
  tag = tag.sub /\s#{attribute}="?\w*"?}}/, "}}"
  tag = tag.sub /^\s*#{attribute}="?\w*"?\n/, ""
  tag
end

files = Dir.glob("app/assets/javascripts/**/*.hbs")

puts "Checking #{files.count} files..."
files.each do |f|
  content = File.read(f)

  count = 0
  edits = 0
  content.gsub!(/{{\s*plugin-outlet.*?}}/m) do |match|
    count += 1

    result = match

    noTags = result.include?("noTags=true")
    tagName = result[/tagName="(\w*)"/, 1]
    connectorTagName = result[/connectorTagName="(\w*)"/, 1]

    if noTags
      result = removeAttr(result, "noTags")
    else
      if connectorTagName == ""
        result = removeAttr(result, "connectorTagName")
      elsif connectorTagName.nil?
        result = result.sub(/name="[\w-]+"/) { |m| "#{m} connectorTagName=\"div\"" }
      end

      if tagName == ""
        result = removeAttr(result, "tagName")
      elsif tagName.nil?
        result = result.sub(/name="[\w-]+"/) { |m| "#{m} tagName=\"span\"" }
      end
    end

    edits += 1 if match != result

    result
  end

  puts "#{count} outlets, #{edits} edited -> #{f}"

  File.write(f, content)
end
```
2022-01-06 20:38:17 +00:00

161 lines
5.3 KiB
Handlebars

{{#conditional-loading-spinner condition=isLoading}}
{{plugin-outlet name="admin-dashboard-general-top" tagName="span" connectorTagName="div"}}
{{#if isCommunityHealthVisible}}
<div class="community-health section">
<div class="period-section">
<div class="section-title">
<h2>
<a href={{get-url "/admin/dashboard/reports"}}>
{{i18n "admin.dashboard.community_health"}}
</a>
</h2>
{{period-chooser
period=period
action=(action "changePeriod")
content=availablePeriods
fullDay=false}}
</div>
<div class="section-body">
<div class="charts">
{{admin-report
dataSourceName="consolidated_page_views"
forcedModes="stacked-chart"
filters=filters}}
{{admin-report
dataSourceName="signups"
showTrend=true
forcedModes="chart"
filters=filters}}
{{admin-report
dataSourceName="topics"
showTrend=true
forcedModes="chart"
filters=filters}}
{{admin-report
dataSourceName="posts"
showTrend=true
forcedModes="chart"
filters=filters}}
{{admin-report
dataSourceName="dau_by_mau"
showTrend=true
forcedModes="chart"
filters=filters}}
{{admin-report
dataSourceName="daily_engaged_users"
showTrend=true
forcedModes="chart"
filters=filters}}
{{admin-report
dataSourceName="new_contributors"
showTrend=true
forcedModes="chart"
filters=filters}}
</div>
</div>
</div>
</div>
{{/if}}
<div class="section-columns">
<div class="section-column">
{{#if isActivityMetricsVisible}}
{{#if activityMetrics.length}}
<div class="admin-report activity-metrics">
<div class="header">
<ul class="breadcrumb">
<li class="item report">
{{#link-to "adminReports" class="report-url"}}
{{i18n "admin.dashboard.activity_metrics"}}
{{/link-to}}
</li>
</ul>
</div>
<div class="report-body">
<div class="counters-list">
<div class="counters-header">
<div class="counters-cell"></div>
<div class="counters-cell">{{i18n "admin.dashboard.reports.today"}}</div>
<div class="counters-cell">{{i18n "admin.dashboard.reports.yesterday"}}</div>
<div class="counters-cell">{{i18n "admin.dashboard.reports.last_7_days"}}</div>
<div class="counters-cell">{{i18n "admin.dashboard.reports.last_30_days"}}</div>
</div>
{{#each activityMetrics as |metric|}}
{{admin-report
showHeader=false
filters=activityMetricsFilters
forcedModes="counters"
dataSourceName=metric}}
{{/each}}
</div>
</div>
</div>
{{/if}}
{{/if}}
<div class="user-metrics">
{{#conditional-loading-section isLoading=isLoading}}
{{admin-report
forcedModes="inline-table"
dataSourceName="users_by_type"}}
{{admin-report
forcedModes="inline-table"
dataSourceName="users_by_trust_level"}}
{{/conditional-loading-section}}
</div>
<div class="misc">
{{admin-report
forcedModes="storage-stats"
dataSourceName="storage_stats"
showHeader=false}}
<div class="last-dashboard-update">
<div>
<h4>{{i18n "admin.dashboard.last_updated"}} </h4>
<p>{{format-date model.attributes.updated_at leaveAgo="true"}}</p>
</div>
{{#if model.attributes.discourse_updated_at}}
<div>
<h4>{{i18n "admin.dashboard.discourse_last_updated"}} </h4>
<p>{{format-date model.attributes.discourse_updated_at leaveAgo="true"}}</p>
<a rel="noopener noreferrer" target="_blank" href={{model.attributes.release_notes_link}} class="btn btn-default">
{{i18n "admin.dashboard.whats_new_in_discourse"}}
</a>
</div>
{{/if}}
</div>
</div>
</div>
{{#if isSearchReportsVisible}}
<div class="section-column">
{{admin-report
filters=topReferredTopicsFilters
dataSourceName="top_referred_topics"
reportOptions=topReferredTopicsOptions}}
{{admin-report
dataSourceName="trending_search"
reportOptions=trendingSearchOptions
filters=trendingSearchFilters
isEnabled=logSearchQueriesEnabled
disabledLabel=trendingSearchDisabledLabel}}
{{html-safe (i18n "admin.dashboard.reports.trending_search.more" basePath=(base-path))}}
</div>
{{/if}}
</div>
{{plugin-outlet name="admin-dashboard-general-bottom" tagName="span" connectorTagName="div"}}
{{/conditional-loading-spinner}}