Skip to content

Commit

Permalink
Housekeeping: Move types from viewmodel to entities
Browse files Browse the repository at this point in the history
Housekeeping: Moved entities from `view-model/page-did.d.ts` to entities

Housekeeping: moved widget types to a new file in entities

Housekeeping: Moved infrastructure types for charts
Moved the infrastructure types for charts in widgets to the
component-library, mirroring the structure of the StreamedTable
`types.d.ts` file.

Housekeeping: Moved RSE Types to Entity from viewmodels.
  • Loading branch information
Anton Schwarz committed Sep 18, 2023
1 parent 2121282 commit 6762900
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 101 deletions.
3 changes: 1 addition & 2 deletions src/component-library/Pages/DID/PageDIDMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { H3 } from "../../Text/Headings/H3";
import { BoolTag } from "../../Tags/BoolTag";
import { AvailabilityTag } from "../../Tags/AvailabilityTag";
import { DIDTypeTag } from "../../Tags/DIDTypeTag";
import { DIDType } from "@/lib/core/entity/rucio";
import { DIDType, DIDKeyValuePair } from "@/lib/core/entity/rucio";
import { NullTag } from "../../Tags/NullTag";

// misc packages, react
Expand All @@ -14,7 +14,6 @@ import { twMerge } from "tailwind-merge"
import { DIDAvailability } from "@/lib/core/entity/rucio"
import { TableFilterString } from "../../StreamedTables/TableFilterString";
import { DIDKeyValuePairsDataViewModel } from "@/lib/infrastructure/data/view-model/did";
import { DIDKeyValuePair } from "@/lib/infrastructure/data/view-model/page-did";
import { NormalTable } from "@/component-library/StreamedTables/NormalTable";

export const PageDIDMetadata = (
Expand Down
2 changes: 1 addition & 1 deletion src/component-library/Pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Checkbox } from "../../Button/Checkbox";
import { WidgetOngoingrules } from "./Widgets/WidgetOngoingrules";
import { RoleTag } from "../../Tags/RoleTag";
import { Role } from "@/lib/core/entity/account";
import { Ongoingrules, Usedquota } from "@/lib/infrastructure/data/view-model/widgets";
import { Ongoingrules, Usedquota } from "@/lib/core/entity/widgets";
import { WidgetUsedquota } from "./Widgets/WidgetUsedquota";
import { useState, useEffect } from "react";
import { Heading } from "../Helpers/Heading";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
Tooltip,
Legend,
} from 'chart.js';
import { ChartData, Ongoingrules } from "@/lib/infrastructure/data/view-model/widgets";
import { ChartData } from "../types";
import { Ongoingrules } from "@/lib/core/entity/widgets";
import {
createColumnHelper, getCoreRowModel, getPaginationRowModel, useReactTable,
Row, Column, getSortedRowModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { H4 } from "@/component-library/Text/Headings/H4";
import { Usedquota } from "@/lib/infrastructure/data/view-model/widgets";
import { Usedquota } from "@/lib/core/entity/widgets";
import { twMerge } from "tailwind-merge";
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
import { Pie } from 'react-chartjs-2';
Expand Down
16 changes: 16 additions & 0 deletions src/component-library/Pages/Dashboard/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/*
* Widget Generics
* These types are used to type a generic widget -> think of them as table column defs.
*/
export type ChartBasicDataset = {
label: string,
data: any[],
backgroundColor?: string, // Hex
}

export type ChartData<T extends ChartBasicDataset> = {
labels: string[],
datasets: T[],
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StoryFn, Meta } from "@storybook/react";
import { createColumnHelper } from "@tanstack/react-table";
import { fixtureDIDKeyValuePair } from "test/fixtures/table-fixtures";
import { NormalTable as N } from "./NormalTable";
import { DIDKeyValuePair } from "@/lib/infrastructure/data/view-model/page-did";
import { DIDKeyValuePair } from "@/lib/core/entity/rucio";
import { TableFilterString } from "./TableFilterString";
import { DIDAvailability, DIDType } from "@/lib/core/entity/rucio";
import { twMerge } from "tailwind-merge";
Expand Down
3 changes: 1 addition & 2 deletions src/lib/core/dto/did-dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BaseDTO, BaseStreamableDTO } from '@/lib/sdk/dto'
import { DID, DIDMeta } from '@/lib/core/entity/rucio'
import { DIDKeyValuePair, DIDRules } from '@/lib/infrastructure/data/view-model/page-did'
import { DID, DIDKeyValuePair, DIDMeta, DIDRules } from '@/lib/core/entity/rucio'

/**
* Data Transfer Object for ListDIDsEndpoint
Expand Down
74 changes: 74 additions & 0 deletions src/lib/core/entity/rucio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export enum DIDAvailability {
UNKNOWN = "Unknown",
}

export type DIDDatasetReplicas = {
rse: string;
rseblocked: RSEBlockState;
availability: boolean;
available_files: number;
available_bytes: number;
creation_date: DateISO;
last_accessed: DateISO;
}

// these are general key-value pairs including the metadata
export type DIDKeyValuePair = { key: string; value: string | number | boolean | null }
export type DIDKeyValuePairsData = {
data: DIDKeyValuePair[]
}

// copied from deployed rucio UI
export type DIDMeta = {
Expand All @@ -47,6 +62,36 @@ export type DIDMeta = {
filesize: number | null
}

export type DIDRules = {
id: string;
name: string;
state: RuleState;
account: string;
subscription?: {name: string, account: string}; // name and account together are unique for a subscription
last_modified: DateISO;
}

// File replica states for file DIDs
export type FilereplicaState = {
rse: string
state: ReplicaState
}

// File replica states for dataset DIDs
// stores summary information on the file replica states of the files within
// a dataset DID: how many files are in each state
// currently not in use since we only display scopenames
export type FilereplicaStateD = {
scope: string,
name: string,
available: number,
unavailable: number,
copying: number,
being_deleted: number,
bad: number,
temporary_unavailable: number,
}

// results of web::flaskapi:v1::rses::RSEAccountUsageLimit::get
export type RSEAccountUsageLimit = {
rse_id: string;
Expand Down Expand Up @@ -155,6 +200,35 @@ export type RSE = {
staging_area: boolean;
}

export type RSEProtocol = {
rseid: string,
scheme: string,
hostname: string,
port: number,
prefix: string,
impl: string,
priorities_lan: {
read: number,
write: number,
delete: number
},
priorities_wan: {
read: number,
write: number,
delete: number,
tpc: number,
tpcwrite: number,
tpcread: number,
},
updated_at: DateISO,
created_at: DateISO,
}

export type RSEAttribute = {
key: string,
value: string| DateISO | number | boolean | null,
}

/*
================================================================================
========================= ENUMS and DISCRETE TYPES =============================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Widget Generics
* These types are used to type a generic widget -> think of them as table column defs.
*/
export type ChartBasicDataset = {
label: string,
data: any[],
backgroundColor?: string, // Hex
}

export type ChartData<T extends ChartBasicDataset> = {
labels: string[],
datasets: T[],
}

/*
* Widget Types
* These types are used to type a specific widget -> they correspond to a table row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DIDKeyValuePair, DIDKeyValuePairsData } from "@/lib/infrastructure/data/view-model/page-did";
import { DIDKeyValuePair, DIDKeyValuePairsData } from "../entity/rucio";
import { BaseErrorResponseModel, BaseResponseModel } from "@/lib/sdk/usecase-models";

export interface DIDKeyValuePairsDataRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DIDRules } from "@/lib/infrastructure/data/view-model/page-did";
import { DIDRules } from "../entity/rucio";
import { BaseErrorResponseModel, BaseResponseModel } from "@/lib/sdk/usecase-models";

export interface ListDIDRulesRequest {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/infrastructure/data/view-model/did.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DID, DIDLong, DIDMeta, DIDType, ReplicaState, RuleState } from "@/lib/core/entity/rucio";
import {
DID, DIDLong, DIDMeta, DIDType, ReplicaState, RuleState, DIDRules, DIDKeyValuePairsData,
FilereplicaState, FilereplicaStateD, DIDDatasetReplicas
} from "@/lib/core/entity/rucio";
import { BaseViewModel } from "@/lib/sdk/view-models";
import { DIDRules, DIDDatasetReplicas, FilereplicaState, FilereplicaStateD, DIDKeyValuePairsData } from "./page-did";

export interface DIDViewModel extends DID, BaseViewModel {}
export interface DIDLongViewModel extends DIDLong, BaseViewModel {}
Expand Down
42 changes: 0 additions & 42 deletions src/lib/infrastructure/data/view-model/page-did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,5 @@ import { DateISO, ReplicaState, RSEBlockState } from "@/lib/core/entity/rucio"
import { RuleState } from "@/lib/core/entity/rucio"
import { ObjectFlags } from "typescript"

// File replica states for file DIDs
export type FilereplicaState = {
rse: string
state: ReplicaState
}

// File replica states for dataset DIDs
// stores summary information on the file replica states of the files within
// a dataset DID: how many files are in each state
export type FilereplicaStateD = {
scope: string,
name: string,
available: number,
unavailable: number,
copying: number,
being_deleted: number,
bad: number,
temporary_unavailable: number,
}

export type DIDDatasetReplicas = {
rse: string;
rseblocked: RSEBlockState;
availability: boolean;
available_files: number;
available_bytes: number;
creation_date: DateISO;
last_accessed: DateISO;
}

// these are general key-value pairs including the metadata
export type DIDKeyValuePair = { key: string; value: string | number | boolean | null }
export type DIDKeyValuePairsData = {
data: DIDKeyValuePair[]
}

export type DIDRules = {
id: string;
name: string;
state: RuleState;
account: string;
subscription?: {name: string, account: string}; // name and account together are unique for a subscription
last_modified: DateISO;
}
30 changes: 1 addition & 29 deletions src/lib/infrastructure/data/view-model/rse.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import { DateISO } from "@/lib/core/entity/rucio"
import { BaseViewModel } from "@/lib/sdk/view-models"
import { RSE, RSEAccountUsageLimit } from "@/lib/core/entity/rucio"
import { RSE, RSEAttribute, RSEAccountUsageLimit, RSEProtocol } from "@/lib/core/entity/rucio"

export type RSEProtocol = {
rseid: string,
scheme: string,
hostname: string,
port: number,
prefix: string,
impl: string,
priorities_lan: {
read: number,
write: number,
delete: number
},
priorities_wan: {
read: number,
write: number,
delete: number,
tpc: number,
tpcwrite: number,
tpcread: number,
},
updated_at: DateISO,
created_at: DateISO,
}

export type RSEAttribute = {
key: string,
value: string| DateISO | number | boolean | null,
}

export interface RSEViewModel extends RSE, BaseViewModel {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DIDKeyValuePairsDTO } from "@/lib/core/dto/did-dto";
import { DIDKeyValuePair } from "@/lib/infrastructure/data/view-model/page-did";
import { DIDKeyValuePair } from "@/lib/core/entity/rucio";
import { BaseEndpoint } from "@/lib/sdk/gateway-endpoints";
import { HTTPRequest } from "@/lib/sdk/http";
import { Response } from "node-fetch";
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/table-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SubscriptionRuleStatesViewModel, SubscriptionViewModel } from '@/lib/in
import { BaseViewModel } from '@/lib/sdk/view-models';
import { DIDDatasetReplicasViewModel, DIDKeyValuePairsDataViewModel, DIDLongViewModel, DIDMetaViewModel, DIDRulesViewModel, DIDViewModel, FilereplicaStateDViewModel, FilereplicaStateViewModel } from '@/lib/infrastructure/data/view-model/did';
import { RuleMetaViewModel, RulePageLockEntryViewModel, RuleViewModel } from '@/lib/infrastructure/data/view-model/rule';
import { DIDKeyValuePair } from '@/lib/infrastructure/data/view-model/page-did';
import { DIDKeyValuePair } from '@/lib/core/entity/rucio';

export function mockUseComDOM<T extends BaseViewModel>(data: T[]): UseComDOM<T> {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/widget-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ongoingrules, Usedquota } from "@/lib/infrastructure/data/view-model/widgets";
import { Ongoingrules, Usedquota } from "@/lib/core/entity/widgets";
import { faker } from "@faker-js/faker";
import { createRSEName } from "./table-fixtures";

Expand Down

0 comments on commit 6762900

Please sign in to comment.