Skip to content

Commit

Permalink
client release version (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
lowtorola authored Dec 23, 2024
1 parent 2ab108d commit c3271e2
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 39 deletions.
1 change: 1 addition & 0 deletions backend/siarnaq/api/episodes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EpisodeAdmin(admin.ModelAdmin):
"fields": (
"scaffold",
"artifact_name",
"release_version_client",
"release_version_public",
"release_version_saturn",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.2 on 2024-12-23 20:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("episodes", "0007_remove_episode_pass_requirement_out_of_and_more"),
]

operations = [
migrations.AddField(
model_name="episode",
name="release_version_client",
field=models.CharField(blank=True, max_length=32),
),
]
3 changes: 3 additions & 0 deletions backend/siarnaq/api/episodes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Episode(models.Model):
artifact_name = models.CharField(max_length=32, blank=True)
"""The name of the artifact generated by deploy systems."""

release_version_client = models.CharField(max_length=32, blank=True)
"""The code release version for the client."""

release_version_public = models.CharField(max_length=32, blank=True)
"""The code release available for public use."""

Expand Down
1 change: 1 addition & 0 deletions backend/siarnaq/api/episodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Meta:
"language",
"scaffold",
"artifact_name",
"release_version_client",
"release_version_public",
"release_version_saturn",
"eligibility_criteria",
Expand Down
3 changes: 3 additions & 0 deletions frontend/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,9 @@ components:
artifact_name:
type: string
maxLength: 32
release_version_client:
type: string
maxLength: 32
release_version_public:
type: string
maxLength: 32
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/api/_autogen/models/Episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export interface Episode {
* @memberof Episode
*/
artifact_name?: string;
/**
*
* @type {string}
* @memberof Episode
*/
release_version_client?: string;
/**
*
* @type {string}
Expand Down Expand Up @@ -132,6 +138,7 @@ export function EpisodeFromJSONTyped(json: any, ignoreDiscriminator: boolean): E
'language': LanguageEnumFromJSON(json['language']),
'scaffold': !exists(json, 'scaffold') ? undefined : json['scaffold'],
'artifact_name': !exists(json, 'artifact_name') ? undefined : json['artifact_name'],
'release_version_client': !exists(json, 'release_version_client') ? undefined : json['release_version_client'],
'release_version_public': !exists(json, 'release_version_public') ? undefined : json['release_version_public'],
'release_version_saturn': !exists(json, 'release_version_saturn') ? undefined : json['release_version_saturn'],
'eligibility_criteria': ((json['eligibility_criteria'] as Array<any>).map(EligibilityCriterionFromJSON)),
Expand All @@ -155,6 +162,7 @@ export function EpisodeToJSON(value?: Episode | null): any {
'language': LanguageEnumToJSON(value.language),
'scaffold': value.scaffold,
'artifact_name': value.artifact_name,
'release_version_client': value.release_version_client,
'release_version_public': value.release_version_public,
'release_version_saturn': value.release_version_saturn,
'eligibility_criteria': ((value.eligibility_criteria as Array<any>).map(EligibilityCriterionToJSON)),
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/api/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Cookies from "js-cookie";
import { Configuration, type ResponseError } from "./_autogen";
import {
Configuration,
type EligibilityCriterion,
type ResponseError,
} from "./_autogen";
import type {
PaginatedQueryFactory,
PaginatedRequestMinimal,
Expand Down Expand Up @@ -117,3 +121,9 @@ export const safeEnsureQueryData = <T, K>(

export const isNilOrEmptyStr = (str: string | undefined | null): boolean =>
isNil(str) || str === "";

export const getEligibilities = (
criteria: EligibilityCriterion[],
eligibilityIds: number[],
): EligibilityCriterion[] =>
eligibilityIds.flatMap((id) => criteria.find((ec) => ec.id === id) ?? []);
6 changes: 5 additions & 1 deletion frontend/src/api/team/useTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
TeamTMeRetrieveRequest,
TeamTRetrieveRequest,
} from "../_autogen";
import { teamMutationKeys } from "./teamKeys";
import { teamMutationKeys, teamQueryKeys } from "./teamKeys";
import {
createTeam,
joinTeam,
Expand Down Expand Up @@ -208,6 +208,10 @@ export const useUpdateTeam = (
buildKey(myTeamFactory.queryKey, { episodeId }),
data,
);

void queryClient.refetchQueries({
queryKey: teamQueryKeys.teamBase.key({ episodeId }),
});
},
});

Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/tables/RankingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Table from "../Table";
import TableBottom from "../TableBottom";
import { NavLink } from "react-router-dom";
import EligibilityIcon from "../EligibilityIcon";
import { isPresent } from "../../utils/utilTypes";
import { useEpisodeId } from "../../contexts/EpisodeContext";
import { useEpisodeInfo } from "api/episode/useEpisode";
import { getEligibilities } from "api/helpers";

interface RankingsTableProps {
data: Maybe<PaginatedTeamPublicList>;
loading: boolean;
page: number;
eligibilityMap: Map<number, EligibilityCriterion>;
handlePage: (page: number) => void;
}

Expand All @@ -30,10 +30,10 @@ const RankingsTable: React.FC<RankingsTableProps> = ({
data,
loading,
page,
eligibilityMap,
handlePage,
}) => {
const { episodeId } = useEpisodeId();
const episode = useEpisodeInfo({ id: episodeId });

const MAX_NAME_LENGTH = 13;

Expand Down Expand Up @@ -96,10 +96,10 @@ const RankingsTable: React.FC<RankingsTableProps> = ({
header: "Eligibility",
key: "eligibility",
value: (team) => {
const icons: EligibilityCriterion[] =
team.profile?.eligible_for
?.map((el) => eligibilityMap.get(el))
.filter(isPresent) ?? [];
const icons: EligibilityCriterion[] = getEligibilities(
episode.data?.eligibility_criteria ?? [],
team.profile?.eligible_for ?? [],
);
return (
<div className="flex flex-row items-center gap-2">
{icons.map((el) => (
Expand Down
16 changes: 0 additions & 16 deletions frontend/src/views/Rankings.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type React from "react";
import { useMemo, useState } from "react";
import { useEpisodeId } from "../contexts/EpisodeContext";
import type { EligibilityCriterion } from "../api/_autogen";
import { useSearchParams } from "react-router-dom";
import Input from "../components/elements/Input";
import Button from "../components/elements/Button";
import { PageTitle } from "../components/elements/BattlecodeStyle";
import RankingsTable from "../components/tables/RankingsTable";
import { getParamEntries, parsePageParam } from "../utils/searchParamHelpers";
import { useEpisodeInfo } from "../api/episode/useEpisode";
import { useSearchTeams } from "../api/team/useTeam";
import { useQueryClient } from "@tanstack/react-query";

Expand All @@ -32,7 +30,6 @@ const Rankings: React.FC = () => {
[searchParams],
);

const episodeData = useEpisodeInfo({ id: episodeId });
const rankingsData = useSearchTeams(
{
episodeId,
Expand All @@ -42,18 +39,6 @@ const Rankings: React.FC = () => {
queryClient,
);

/**
* This enables us to look up eligibility criteria by index in the table component.
*/
const eligibilityMap: Map<number, EligibilityCriterion> = useMemo(() => {
if (!episodeData.isSuccess) {
return new Map<number, EligibilityCriterion>();
}
return new Map(
episodeData.data.eligibility_criteria.map((crit, idx) => [idx, crit]),
);
}, [episodeData]);

function handlePage(page: number): void {
if (!rankingsData.isLoading) {
setSearchParams({ ...queryParams, page: page.toString() });
Expand Down Expand Up @@ -104,7 +89,6 @@ const Rankings: React.FC = () => {
data={rankingsData.data}
loading={rankingsData.isLoading}
page={queryParams.page}
eligibilityMap={eligibilityMap}
handlePage={handlePage}
/>
</div>
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/views/TeamProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PageNotFound from "./PageNotFound";
// import TeamChart from "components/compete/chart/TeamChart";
// import { useTeamRatingHistory } from "api/compete/useCompete";
import ScrimmagingRecord from "components/compete/ScrimmagingRecord";
import { getEligibilities } from "api/helpers";

const isNilOrEmptyStr = (str: string | undefined | null): boolean =>
isNil(str) || str === "";
Expand Down Expand Up @@ -40,12 +41,10 @@ const TeamProfile: React.FC = () => {

const eligibles = useMemo(
() =>
episode.data?.eligibility_criteria.filter(
(criterion) =>
team.data?.profile?.eligible_for?.find(
(id) => id === criterion.id,
) !== undefined,
) ?? [],
getEligibilities(
episode.data?.eligibility_criteria ?? [],
team.data?.profile?.eligible_for ?? [],
),
[episode, team],
);

Expand Down
20 changes: 12 additions & 8 deletions frontend/src/views/Tournament.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useEpisodeInfo, useTournamentInfo } from "../api/episode/useEpisode";
import { useTournamentMatchList } from "../api/compete/useCompete";
import { useQueryClient } from "@tanstack/react-query";
import SearchTeamsMenu from "../components/team/SearchTeamsMenu";
import { getEligibilities } from "api/helpers";

interface QueryParams {
page: number;
Expand Down Expand Up @@ -68,14 +69,17 @@ const TournamentPage: React.FC = () => {
if (episode === undefined || tourneyData.data === undefined) {
return { includes: [], excludes: [], isEligible: false };
}
const includes =
tourneyData.data.eligibility_includes?.flatMap(
(inc) => episode.eligibility_criteria.find((ec) => ec.id === inc) ?? [],
) ?? [];
const excludes =
tourneyData.data.eligibility_excludes?.flatMap(
(exc) => episode.eligibility_criteria.find((ec) => ec.id === exc) ?? [],
) ?? [];

const includes = getEligibilities(
episode.eligibility_criteria,
tourneyData.data.eligibility_includes ?? [],
);

const excludes = getEligibilities(
episode.eligibility_criteria,
tourneyData.data.eligibility_excludes ?? [],
);

const isEligible = tourneyData.data.is_eligible;

return { includes, excludes, isEligible };
Expand Down

0 comments on commit c3271e2

Please sign in to comment.