Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve loading speed for updater page #7140

Merged
merged 6 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion resources/js/components/updater/Release.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
</div>
<div class="card-body">
<div v-html="release.body"></div>
<div v-html="body"></div>
</div>

<confirmation-modal
Expand Down Expand Up @@ -66,6 +66,14 @@ export default {
return this.confirmationPrompt.type === 'downgrade'
? __('Are you sure you want to downgrade to :version?', attrs)
: __('Are you sure you want to update to :version?', attrs)
},

body() {
return markdown(this.release.body)
.replaceAll('[new]', '<span class="label" style="background: #5bc0de;">NEW</span>')
.replaceAll('[fix]', '<span class="label" style="background: #5cb85c;">FIX</span>')
.replaceAll('[break]', '<span class="label" style="background: #d9534f;">BREAK</span>')
.replaceAll('[na]', '<span class="label" style="background: #e8e8e8;">N/A</span>')
}
},

Expand Down
9 changes: 3 additions & 6 deletions resources/js/components/updater/Updater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,16 @@
},

latestVersion() {
return this.latestRelease.version;
return this.latestRelease && this.latestRelease.version;
},

canUpdateToLatestVersion() {
return this.latestVersion.canUpdate && this.showActions && ! this.onLatestVersion;
return this.latestVersion && this.latestVersion.canUpdate && this.showActions && ! this.onLatestVersion;
}
},

mounted() {
this.getChangelog();
},

created() {
this.getChangelog();
this.$events.$on('composer-finished', this.composerFinished);
},

Expand Down
11 changes: 7 additions & 4 deletions src/Updater/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\Carbon;
use Facades\Statamic\Marketplace\Marketplace;
use Statamic\Updater\Presenters\GithubReleasePresenter;

abstract class Changelog
{
Expand All @@ -29,14 +28,18 @@ abstract public function item();
*/
public function get()
{
return Marketplace::releases($this->item())->map(function ($release, $index) {
$type = null;

return Marketplace::releases($this->item())->map(function ($release, $index) use (&$type) {
$type = $type === 'downgrade' ? $type : $this->parseReleaseType($release['version'], $index);

return (object) [
'version' => $release['version'],
'type' => $this->parseReleaseType($release['version'], $index),
'type' => $type,
'latest' => $index === 0,
'licensed' => $this->isLicensed($release['version']),
'date' => Carbon::parse($release['date'])->format(config('statamic.cp.date_format')),
'body' => (string) new GithubReleasePresenter($release['changelog']),
'body' => $release['changelog'],
];
});
}
Expand Down
1 change: 1 addition & 0 deletions src/Updater/Presenters/GithubReleasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Statamic\Support\Html;
use Statamic\Support\Str;

/** @deprecated */
class GithubReleasePresenter
{
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/ChangelogTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function it_can_get_changelog_contents()

collect($contents)->each(function ($release) {
$this->assertEquals('2018: November 6th', $release->date);
$this->assertContainsHtml($release->body);
$this->assertIsString($release->body);
});
}

Expand Down