Skip to content

Commit

Permalink
Create a Fishbowl without introduction (#159)
Browse files Browse the repository at this point in the history
* Create hasIntroduction field

* Run no intro mutation created

* Add unit test

* unitest changes

* Refactor mutation resolver tests

* wip

* Introduce fishbowl functional test

* Add more functional tests

* Add no intro fishbowl mutation in Fishbowls.js

* wip

* fix creation fishwbol

* wip

* fix button behaviour

* work in progress

* wip

* wip

* fix

* space removed

* wip

* wip

* Remove introduction sliders in onboarding

* finish Fishbowl button loading fixed

* unused import removed

* no host users work with no introduction fishbowls

* Fix refresh case

* Fix stooamanager

* Fishbowl type updated

* New component

* New Component File

* Fishbowl interface prettier applied

* wip
to pull

* add errors

* Add formik field plus styles

* Add value to api call

* Add translations and styling

* add license to fishbow.ts

* Prettify

* Apply prettify

* wip

* wip

* The host user is the only one that can change the status of a fishbowl

* wip

* new eventsubscriber added

* Add more tests

* Add tooltip

* Tooltip styles

* Add unit tests

* style fixed

* New tooltip

* add translations

* Fix props usage

* Refactor fishbowl workflow

* refactor transitions

* Add has introduction to sonata edit form

* Tooltip for mobile

* Remove run without introduction from StooaManager

* Remove unused import

* Add on click in tooltip

* fix mobile tooltip and improve switch a11x

* Fix pointer cursor

Co-authored-by: Jose <jesauraoller@gmail.com>
  • Loading branch information
aerrasti and eddsaura committed Feb 2, 2022
1 parent 22fb478 commit 00f3791
Show file tree
Hide file tree
Showing 33 changed files with 905 additions and 115 deletions.
3 changes: 3 additions & 0 deletions backend/config/packages/workflow.yaml
Expand Up @@ -29,6 +29,9 @@ framework:
run:
from: introduction
to: running
no_intro_run:
from: not_started
to: running
finish:
from: running
to: finished
43 changes: 43 additions & 0 deletions backend/migrations/Version20220120123411.php
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Stooa codebase.
*
* (c) 2020 - present Runroom SL
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220120123411 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE fishbowl ADD has_introduction TINYINT(1) NOT NULL');

// All the Fishbowls we have created before have had and introduction.
$this->addSql('UPDATE fishbowl SET has_introduction = 1');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE fishbowl DROP has_introduction');
}
}
8 changes: 7 additions & 1 deletion backend/src/Admin/FishbowlAdmin.php
Expand Up @@ -23,6 +23,7 @@
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
use Sonata\DoctrineORMAdminBundle\Filter\ModelAutocompleteFilter;
use Sonata\Form\Type\BooleanType;
use Sonata\Form\Type\DateTimePickerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
Expand Down Expand Up @@ -78,7 +79,8 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
])
->add('currentStatus', null, [], ChoiceType::class, [
'choices' => Fishbowl::$statusChoices,
]);
])
->add('hasIntroduction');
}

protected function configureListFields(ListMapper $list): void
Expand All @@ -91,6 +93,7 @@ protected function configureListFields(ListMapper $list): void
->add('currentStatus', null, [
'template' => 'sonata/fishbowl_status.html.twig',
])
->add('hasIntroduction')
->add('startDateTimeTz', FieldDescriptionInterface::TYPE_DATETIME)
->add('endDateTimeTz', FieldDescriptionInterface::TYPE_DATETIME)
->add('duration', FieldDescriptionInterface::TYPE_TIME)
Expand Down Expand Up @@ -124,6 +127,9 @@ protected function configureFormFields(FormMapper $form): void
'property' => 'email',
'callback' => self::hostCallbackFunction(),
])
->add('hasIntroduction', BooleanType::class, [
'transform' => true,
])
->end()
->with('Disabled')
->add('currentStatus', ChoiceType::class, [
Expand Down
28 changes: 28 additions & 0 deletions backend/src/Entity/Fishbowl.php
Expand Up @@ -20,6 +20,7 @@
use App\Resolver\FishbowlCreatorResolver;
use App\Resolver\FishbowlFinishMutationResolver;
use App\Resolver\FishbowlIntroduceMutationResolver;
use App\Resolver\FishbowlNoIntroRunMutationResolver;
use App\Resolver\FishbowlResolver;
use App\Resolver\FishbowlRunMutationResolver;
use App\Validator\Constraints\FutureFishbowl;
Expand Down Expand Up @@ -74,6 +75,13 @@
* },
* "validation_groups"={"Default"}
* },
* "noIntroRun"={
* "mutation"=FishbowlNoIntroRunMutationResolver::class,
* "args"={
* "slug"={"type"="String!"}
* },
* "validation_groups"={"Default"}
* },
* "finish"={
* "mutation"=FishbowlFinishMutationResolver::class,
* "args"={
Expand Down Expand Up @@ -103,6 +111,7 @@ class Fishbowl

public const TRANSITION_INTRODUCE = 'introduce';
public const TRANSITION_RUN = 'run';
public const TRANSITION_NO_INTRO_RUN = 'no_intro_run';
public const TRANSITION_FINISH = 'finish';

public const STATUS_NOT_STARTED = 'not_started';
Expand Down Expand Up @@ -251,6 +260,13 @@ class Fishbowl
*/
private Collection $participants;

/**
* @Groups({"fishbowl:read", "fishbowl:write"})
*
* @ORM\Column(type="boolean")
*/
private bool $hasIntroduction = false;

public function __construct()
{
$this->participants = new ArrayCollection();
Expand Down Expand Up @@ -525,6 +541,18 @@ public function removeParticipant(Participant $participant): self
return $this;
}

public function getHasIntroduction(): bool
{
return $this->hasIntroduction;
}

public function setHasIntroduction(bool $hasIntroduction): self
{
$this->hasIntroduction = $hasIntroduction;

return $this;
}

public function isFinished(): bool
{
return self::STATUS_FINISHED === $this->getCurrentStatus();
Expand Down
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Stooa codebase.
*
* (c) 2020 - present Runroom SL
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\EventSubscriber;

use App\Entity\Fishbowl;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Webmozart\Assert\Assert;

class FishbowlIntroduceAndNoIntroRunSubscriber implements EventSubscriberInterface
{
public function guardFishbowl(GuardEvent $event): void
{
$fishbowl = $event->getSubject();

Assert::isInstanceOf($fishbowl, Fishbowl::class);

$transition = $event->getTransition();

if ((Fishbowl::TRANSITION_INTRODUCE === $transition->getName() && !$fishbowl->getHasIntroduction()) ||
(Fishbowl::TRANSITION_NO_INTRO_RUN === $transition->getName() && $fishbowl->getHasIntroduction())
) {
$event->setBlocked(true);
}
}

public static function getSubscribedEvents(): array
{
return [
'workflow.fishbowl.guard.' . Fishbowl::TRANSITION_INTRODUCE => ['guardFishbowl'],
'workflow.fishbowl.guard.' . Fishbowl::TRANSITION_NO_INTRO_RUN => ['guardFishbowl'],
];
}
}
1 change: 1 addition & 0 deletions backend/src/Factory/FishbowlFactory.php
Expand Up @@ -31,6 +31,7 @@ protected function getDefaults(): array
'duration' => self::faker()->dateTime(),
'currentStatus' => self::faker()->randomElement(Fishbowl::$statusChoices),
'slug' => self::faker()->slug(),
'hasIntroduction' => false,
];
}

Expand Down
4 changes: 4 additions & 0 deletions backend/src/Resolver/FishbowlCreatorResolver.php
Expand Up @@ -40,6 +40,10 @@ public function __construct(FishbowlRepository $repository, Security $security)
*/
public function __invoke($item, array $context): ?Fishbowl
{
if (!isset($context['args']['slug'])) {
return null;
}

$user = $this->security->getUser();

if (null === $item) {
Expand Down
4 changes: 4 additions & 0 deletions backend/src/Resolver/FishbowlFinishMutationResolver.php
Expand Up @@ -32,6 +32,10 @@ public function __construct(FishbowlRepository $repository, WorkflowInterface $f
/** @param mixed[] $context */
public function __invoke($item, array $context): ?Fishbowl
{
if (!isset($context['args']['input']['slug'])) {
return null;
}

$fishbowl = $this->repository->findBySlug($context['args']['input']['slug']);

if (null === $fishbowl) {
Expand Down
4 changes: 4 additions & 0 deletions backend/src/Resolver/FishbowlIntroduceMutationResolver.php
Expand Up @@ -32,6 +32,10 @@ public function __construct(FishbowlRepository $repository, WorkflowInterface $f
/** @param mixed[] $context */
public function __invoke($item, array $context): ?Fishbowl
{
if (!isset($context['args']['input']['slug'])) {
return null;
}

$fishbowl = $this->repository->findBySlug($context['args']['input']['slug']);

if (null === $fishbowl) {
Expand Down
53 changes: 53 additions & 0 deletions backend/src/Resolver/FishbowlNoIntroRunMutationResolver.php
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Stooa codebase.
*
* (c) 2020 - present Runroom SL
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Resolver;

use ApiPlatform\Core\GraphQl\Resolver\MutationResolverInterface;
use App\Entity\Fishbowl;
use App\Repository\FishbowlRepository;
use Symfony\Component\Workflow\WorkflowInterface;

class FishbowlNoIntroRunMutationResolver implements MutationResolverInterface
{
private FishbowlRepository $repository;
private WorkflowInterface $fishbowlStateMachine;

public function __construct(FishbowlRepository $repository, WorkflowInterface $fishbowlStateMachine)
{
$this->repository = $repository;
$this->fishbowlStateMachine = $fishbowlStateMachine;
}

/** @param mixed[] $context */
public function __invoke($item, array $context): ?Fishbowl
{
if (!isset($context['args']['input']['slug'])) {
return null;
}

$fishbowl = $this->repository->findBySlug($context['args']['input']['slug']);

if (null === $fishbowl) {
return null;
}

if (!$this->fishbowlStateMachine->can($fishbowl, FISHBOWL::TRANSITION_NO_INTRO_RUN)) {
return null;
}

$this->fishbowlStateMachine->apply($fishbowl, FISHBOWL::TRANSITION_NO_INTRO_RUN);

return $fishbowl;
}
}
4 changes: 4 additions & 0 deletions backend/src/Resolver/FishbowlRunMutationResolver.php
Expand Up @@ -32,6 +32,10 @@ public function __construct(FishbowlRepository $repository, WorkflowInterface $f
/** @param mixed[] $context */
public function __invoke($item, array $context): ?Fishbowl
{
if (!isset($context['args']['input']['slug'])) {
return null;
}

$fishbowl = $this->repository->findBySlug($context['args']['input']['slug']);

if (null === $fishbowl) {
Expand Down

0 comments on commit 00f3791

Please sign in to comment.