Skip to content
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
26 changes: 26 additions & 0 deletions app/NativeComponents/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Devnull\Data\Mention;
use App\Devnull\Data\Organization as OrganizationData;
use App\Devnull\Data\Page;
use App\Devnull\Exceptions\ApiException;
use App\Devnull\RowCache;
use App\Devnull\SiteLink;
use App\Devnull\Stash;
Expand Down Expand Up @@ -88,6 +89,13 @@ class Organization extends NativeComponent
*/
public bool $commitsFailed = false;

/**
* devnull has no organization by this handle, nor a member, since a profile hands a handle no member has over to
* this screen. It's someone on GitHub who isn't on /dev/null yet, so the page says that rather than that it
* didn't load, and offers the web's page for them, where you can follow them for when they join.
*/
public bool $isNotOnDevnull = false;

/**
* Each tab's rows from the last frame, so a render only builds the rows that changed, as on a profile.
*
Expand Down Expand Up @@ -272,6 +280,23 @@ protected function showsContent(): bool
return $this->organization !== null;
}

/**
* devnull has nothing by this handle, so the page says it isn't on /dev/null yet (see $isNotOnDevnull). Anything
* else that stops it loading, the page says didn't load. Only a page with no organization on it yet says so: once
* one is showing, what else devnull refuses, such as a thread's replies or its stargazers, keeps it showing.
*/
protected function refused(ApiException $exception): bool
{
if ($exception->status !== 404 || $this->organization !== null) {
return false;
}

$this->isNotOnDevnull = true;
$this->error = null;

return true;
}

/**
* @return iterable<Commit>
*/
Expand Down Expand Up @@ -358,6 +383,7 @@ private function takeOrganization(array $json): void
// An answer with no organization in it, like a maintenance page, leaves what's showing alone.
if ($organization->organization->username !== '') {
$this->organization = $organization;
$this->isNotOnDevnull = false;
}
}

Expand Down
17 changes: 14 additions & 3 deletions resources/views/native/organization.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ class="w-full flex-1 bg-theme-surface"
</native:pager-overlay>
</native:pager>
@else
{{-- devnull's error isn't printed: the page says itself when it didn't load, and offers the page on the web. --}}
{{--
devnull's error isn't printed: the page says itself when it didn't load, and offers the page on the web. A
handle devnull has nothing by is someone who isn't on /dev/null yet, and you can follow them on the web's page
for when they join.
--}}
<native:list native:key="organization-{{ $listKey }}" class="w-full flex-1 bg-theme-surface" on-refresh="load">
@if ($error)
@if ($isNotOnDevnull)
@include('native.partials.empty', [
'command' => '$ git log --grep=@'.$handle,
'message' => "@{$handle} isn't on /dev/null yet.",
'link' => 'Follow them on the web for when they join',
'press' => 'openOnWeb',
])
@elseif ($error)
@include('native.partials.empty', [
'command' => '$ git log --grep=@'.$handle,
'message' => "This organization's page didn't load here.",
'link' => 'Open it on dev/null',
'link' => 'Open it on /dev/null',
'press' => 'openOnWeb',
])
@else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class="w-full flex-1 bg-theme-surface"
@include('native.partials.empty', [
'command' => $page['tab'] === 'mentions' ? '$ git log --grep='.$user->handle() : '$ git log --author='.$user->handle(),
'message' => $page['tab'] === 'mentions' ? "Its mentions didn't load here." : "Its commits didn't load here.",
'link' => 'Open it on dev/null',
'link' => 'Open it on /dev/null',
'press' => 'openOnWeb',
])
@elseif (! $page['loaded'])
Expand Down
40 changes: 38 additions & 2 deletions tests/Feature/Screens/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,48 @@ function tapOrganizationTab(TestableComponent $screen, string $tab): TestableCom
->assertNavigatedTo('/log/users/nunomaduro');
});

it("says a handle that's neither a member nor an organization isn't on /dev/null yet, and offers its page on the web, which looks it up", function () {
// A mention of someone who never joined lands here: their profile was missing too, so the profile handed over.
Http::fake(['devnull.test/api/v1/organizations/*' => Http::response(['message' => 'Not Found'], 404)]);

$screen = finishRefreshes(Native::visit('/log/organizations/karpathy'))->assertNavTitle('karpathy');

$screen->assertSee("@karpathy isn't on /dev/null yet.")
->assertSee('Follow them on the web for when they join')
->assertDontSee("didn't load")
->assertDontSee('Not Found');
expect(findNode($screen->tree(), fn (array $node): bool => in_array($node['ref'] ?? null, ['error', 'organization-header'], true)))->toBeNull();

$screen->tap('empty-link')
->assertNativeCalled('Browser.OpenInApp', fn (array $params): bool => $params['url'] === 'http://devnull.test/@karpathy');
});

it("keeps an organization that's showing when devnull later has nothing by its handle", function () {
serveApi([
'GET /api/v1/organizations/laravel' => [organizationJson()],
'GET /api/v1/organizations/laravel/commits' => [pageJson([])],
]);

$screen = finishRefreshes(Native::visit('/log/organizations/laravel'));

serveApi([
'GET /api/v1/organizations/laravel' => [['message' => 'Not Found'], 404],
'GET /api/v1/organizations/laravel/commits' => [pageJson([])],
]);

$screen = finishRefreshes($screen->call('load'))
->assertSee('The PHP framework for web artisans.')
->assertDontSee("isn't on /dev/null yet");

expect($screen->instance()->isNotOnDevnull)->toBeFalse();
});

it("says the page didn't load when devnull can't send the organization, and offers its page on the web", function () {
Http::fake(['devnull.test/api/v1/organizations/*' => Http::response(['message' => 'Not Found.'], 404)]);
Http::fake(['devnull.test/api/v1/organizations/*' => Http::response(['message' => 'Server Error'], 500)]);

$screen = finishRefreshes(Native::visit('/log/organizations/nobody'))->assertNavTitle('nobody');

$screen->assertSee("This organization's page didn't load here.");
$screen->assertSee("This organization's page didn't load here.")->assertSee('Open it on /dev/null')->assertDontSee('Server Error');
expect(findNode($screen->tree(), fn (array $node): bool => in_array($node['ref'] ?? null, ['error', 'organization-header'], true)))->toBeNull();

$screen->tap('empty-link')
Expand Down
Loading