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

feat: DIA-1815: Add conditional dependencies in product tour #6918

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions label_studio/users/product_tours/serializers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import logging
import pathlib
from functools import cached_property

import yaml
from core.utils.db import fast_first
from rest_framework import serializers

from .models import ProductTourInteractionData, UserProductTour
from .models import ProductTourInteractionData, ProductTourState, UserProductTour

logger = logging.getLogger(__name__)

PRODUCT_TOURS_CONFIGS_DIR = pathlib.Path(__file__).parent / 'configs'


class UserProductTourSerializer(serializers.ModelSerializer):
# steps is a list of steps in the tour loaded from the yaml file
steps = serializers.SerializerMethodField(read_only=True)
# awaiting is a boolean that indicates if the tour is awaiting other tours in the list of "dependencies"
awaiting = serializers.SerializerMethodField(read_only=True)

class Meta:
model = UserProductTour
Expand All @@ -29,14 +36,25 @@

return value

@cached_property
hakan458 marked this conversation as resolved.
Show resolved Hide resolved
def load_tour_config(self):
# TODO: get product tour from yaml file. Later we move it to remote storage, e.g. S3
filepath = PRODUCT_TOURS_CONFIGS_DIR / f'{self.context["name"]}.yml'
with open(filepath, 'r') as f:
return yaml.safe_load(f)

def get_awaiting(self, obj):
config = self.load_tour_config
dependencies = config.get('dependencies', [])
for dependency in dependencies:
tour = fast_first(UserProductTour.objects.filter(user=self.context['request'].user, name=dependency))
if not tour or tour.state != ProductTourState.COMPLETED:
logger.info(f'Tour {dependency} is not completed: skipping tour {self.context["name"]}')
return True
return False

Check warning on line 54 in label_studio/users/product_tours/serializers.py

View check run for this annotation

Codecov / codecov/patch

label_studio/users/product_tours/serializers.py#L47-L54

Added lines #L47 - L54 were not covered by tests

def get_steps(self, obj):
config = self.load_tour_config()
config = self.load_tour_config

Check warning on line 57 in label_studio/users/product_tours/serializers.py

View check run for this annotation

Codecov / codecov/patch

label_studio/users/product_tours/serializers.py#L57

Added line #L57 was not covered by tests
return config.get('steps', [])

def validate_interaction_data(self, value):
Expand Down
5 changes: 5 additions & 0 deletions web/libs/core/src/lib/Tour/TourProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export const TourProvider: React.FC<{
return;
}

if (response.awaiting) {
console.info(`Tour "${name}" is awaiting other tours`);
return;
}

if (!response.steps?.length) {
console.info(`No steps found for tour "${name}"`);
return;
Expand Down
Loading