Skip to content

Feature/share biomarker #76

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

Merged
merged 8 commits into from
May 30, 2025
Merged

Feature/share biomarker #76

merged 8 commits into from
May 30, 2025

Conversation

juanNH
Copy link
Contributor

@juanNH juanNH commented May 23, 2025

No description provided.

@juanNH juanNH requested a review from Genarito May 23, 2025 16:06
@@ -418,7 +429,7 @@ def get_queryset(self):

class UsersExperimentsSharedListView(generics.ListAPIView):
"""
REST endpoint: Get all users associated with a specific experiment.
REST endpoint: Get all institution associated with a specific experiment.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Estaba bien el comentario anterior! Terminás devolviendo una QuerySet de Users, así que acá debería volver a decir "users"

try:
experiment: Experiment = Experiment.objects.get(
pk=experiment_id, user=self.request.user)
#Todo: modificar Query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. El filter devuelve muchos resultados, para obtener uno sol se puede simplemente hacer un .get en vez de .filter.
  2. Eliminar el .distinct().get() ya que ahora es solo un resultado
  3. Eliminar ese comentario con el TODO

@@ -57,6 +58,11 @@ class Meta:
model = MethylationIdentifier
exclude = ['biomarker']

class LimitedUserSerializer(serializers.ModelSerializer):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este serializer ya existe en api_service/serializers.py importar ese!

@@ -70,7 +77,17 @@ class BiomarkerDetail(generics.RetrieveUpdateDestroyAPIView):
"""REST endpoint: get, modify and delete for Biomarker model."""

def get_queryset(self):
return Biomarker.objects.filter(user=self.request.user)
user = self.request.user
Copy link
Member

@Genarito Genarito May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si solo lo estás haciendo para hacer un retrieve en el frontend chocando contra una URL del estilo biomarkers/<pk>/ no hace falta agarrar la PK y filtrar por eso en la vista. Alcanza con devolver un QuerySet (filtrando por is_public, y todos los filtros que pusiste, excepto por la PK). Y listo! Django REST Framework va a filtrar después por la PK automáticamente para obtener un solo resultado.

  1. Borrar filtro por PK
  2. Sacar el distinct


biomarker.is_public = not biomarker.is_public
biomarker.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimizar poniendo como parámetro el update_fields con una lista con el nombre del único campo que se está actualizando (en este caso is_public)

isAdding: boolean,
user: { id: number, username: string }
}
interface Props extends SharedInstitutionsBiomarkerProps {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En lo posible siempre poner el nombre del componente del cual son las props! Si no vamos a estar lleno de interfaces llamadas "Props"! De paso, documentar los componentes de este archivo indicando qué es lo que renderizan

isAdding: boolean,
user: { id: number, username: string }
}
interface Props extends SharedUsersBiomarkerProps {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combinar ambos, quedaron dos interfaces separadas y solo se utiliza Props. Dejar el nombre SharedUsersBiomarkerProps con todos los campos. No exportar nada que no se use en otro archivo, así no agregamos ruido al proyecto!

handleChangeConfirmModalState: (setOption: boolean, headerText: string, contentText: string, onConfirm: () => void) => void,
}

export const SharedUsersBiomarker = (props: Props) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentar componente

@@ -88,7 +88,12 @@ interface BiomarkerSimple {
origin: BiomarkerOrigin,
state: BiomarkerState,
contains_nan_values: boolean,
column_used_as_index: string
column_used_as_index: string,
user: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entré a buscar a ver si existía la interface y se llama DjangoUserSimple. Hay un montón de ocurrencias en el proyecto del tipo { id: number, username: string }. Reemplazar todas por DjangoUserSimple

ky.get(editUrl, { headers: myHeaders, signal: abortController.current.signal }).then((response) => {
response.json().then((jsonResponse: { id: number, username: string }[]) => {
console.log(jsonResponse)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Borrar

isOpen: boolean,
institutions: { id: number, name: string }[],
biomarkerId: number,
isAdding: boolean,
user: { id: number, username: string }
}
interface Props extends SharedInstitutionsBiomarkerProps {
interface SharedInstitutionsBiomarkerProps extends SharedInstitutionsBiomarkerPropsExtend {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No entiendo por qué estás extendiendo de la prop de arriba, no es más fácil dejar una sola unificada? Además se está exportando, pero no veo que se use en ningún otro lado en el PR

isOpen: boolean,
users: { id: number, name: string }[],
biomarkerId: number,
isAdding: boolean,
user: { id: number, username: string }
}
interface Props extends SharedUsersBiomarkerProps {
interface SharedUsersBiomarkerProps extends SharedUsersBiomarkerPropsExtend {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem comentario anterior

export const SharedUsersBiomarker = (props: Props) => {
/**
* Modal that shows user shared to a biomarker
* @param {SharedUsersBiomarkerProps} props Component props.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evitar estas anotaciones, esto es tipado para JS, nosotros usamos Typescript, así que no hace falta duplicar todos los tipos en la documentación!

@Genarito Genarito merged commit 0aea3c1 into v5.0.0 May 30, 2025
1 check failed
@Genarito Genarito deleted the feature/share-biomarker branch May 30, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants