diff --git a/src/renderer/api/cadt/v1/organizations/organizations.api.ts b/src/renderer/api/cadt/v1/organizations/organizations.api.ts index 81a546c2..f4037d66 100644 --- a/src/renderer/api/cadt/v1/organizations/organizations.api.ts +++ b/src/renderer/api/cadt/v1/organizations/organizations.api.ts @@ -1,22 +1,28 @@ import {cadtApi, organizationsTag} from "../"; // @ts-ignore import {BaseQueryResult} from "@reduxjs/toolkit/dist/query/baseQueryTypes"; +import {Organization} from "@/schemas/Organization.schema"; const host: string = 'http://localhost:31310' +interface GetOrgnaizationsMapResponse { + [index: string]: Organization +} + const organizationsApi = cadtApi.injectEndpoints({ endpoints: (builder) => ({ - getOrganizationsList: builder.query({ + getOrganizationsList: builder.query({ query: () => ({ url: `${host}/v1/organizations`, method: 'GET', }), providesTags: [organizationsTag], - transformResponse(baseQueryReturnValue: BaseQueryResult): any[]{ + transformResponse(baseQueryReturnValue: BaseQueryResult): Organization[]{ return Object.values(baseQueryReturnValue); } }), - getOrganizationsMap: builder.query({ + + getOrganizationsMap: builder.query({ query: () => ({ url: `${host}/v1/organizations`, method: 'GET', diff --git a/src/renderer/api/cadt/v1/units/units.api.ts b/src/renderer/api/cadt/v1/units/units.api.ts index 5a5e6300..68c46465 100644 --- a/src/renderer/api/cadt/v1/units/units.api.ts +++ b/src/renderer/api/cadt/v1/units/units.api.ts @@ -1,4 +1,5 @@ import {cadtApi, unitsTag} from "../"; +import {Unit} from "@/schemas/Unit.schema"; const host: string = 'http://localhost:31310' @@ -12,7 +13,7 @@ interface GetUnitsParams { interface GetUnitsResponse { page: number, pageCount: number, - data: any[] + data: Unit[] } const unitsApi = cadtApi.injectEndpoints({ diff --git a/src/renderer/components/blocks/widgets/OrganizationSelector.tsx b/src/renderer/components/blocks/widgets/OrganizationSelector.tsx index 2a18ef3b..0bd6b33c 100644 --- a/src/renderer/components/blocks/widgets/OrganizationSelector.tsx +++ b/src/renderer/components/blocks/widgets/OrganizationSelector.tsx @@ -1,6 +1,7 @@ import React, { useState, useEffect } from 'react'; import { useGetOrganizationsListQuery } from '@/api/cadt/v1/organizations'; import { Dropdown, SyncIndicator } from '@/components'; +import {Organization} from "@/schemas/Organization.schema"; interface OrganizationSelectorProps { onSelect: (organization: any | undefined) => void; @@ -8,13 +9,23 @@ interface OrganizationSelectorProps { noSelectionLabel?: string } -const OrganizationSelector: React.FC = ({ onSelect, defaultOrgUid, noSelectionLabel = 'Select Organization' }) => { - const { data: organizations, error, isLoading } = useGetOrganizationsListQuery({}); - const [selectedOrganization, setSelectedOrganization] = useState(undefined); +const OrganizationSelector: React.FC = ({ onSelect, defaultOrgUid, noSelectionLabel = 'Select Organization' }) => { + const { data: organizations, error, isLoading } = useGetOrganizationsListQuery(); + const [selectedOrganization, setSelectedOrganization] = useState(undefined); useEffect(() => { if (defaultOrgUid === null) { - setSelectedOrganization({ name: 'All Organizations' }); + const allOrganizationsPlaceholder: Organization = { + name: 'All Organizations', + id: 0, + orgUid: '', + icon: '', + registryId: '', + registryHash: '', + fileStoreId: '', + prefix: '' + } + setSelectedOrganization(allOrganizationsPlaceholder); } else if (defaultOrgUid !== undefined && organizations) { const defaultOrganization = organizations.find((org) => org.orgUid === defaultOrgUid); if (defaultOrganization) { diff --git a/src/renderer/components/blocks/widgets/SyncIndicator.tsx b/src/renderer/components/blocks/widgets/SyncIndicator.tsx index 6ca73ed5..f6f5e963 100644 --- a/src/renderer/components/blocks/widgets/SyncIndicator.tsx +++ b/src/renderer/components/blocks/widgets/SyncIndicator.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import _ from 'lodash' import { useGetOrganizationsMapQuery, useGetOrganizationsListQuery } from '@/api/cadt/v1/organizations'; interface SyncIndicatorProps { @@ -17,17 +18,19 @@ const SyncIndicator: React.FC = ({ detailed, orgUid }) => { pollingInterval: 10000, }); - let isSynced = false; - let syncRemaining = 0; + let isSynced: boolean; + let syncRemaining: number = 0; if (!orgUid) { isSynced = !organizationList?.some((org) => !org.synced); if (!isSynced) { - syncRemaining = organizationList?.reduce((acc, org) => acc + org.sync_remaining, 0) ?? 0; + syncRemaining = organizationList?.reduce((acc, org) => { + return _.isNil(org.sync_remaining) ? acc : acc + org.sync_remaining; + }, 0) ?? 0; } } else { const orgData = organizationsMap?.[orgUid]; - isSynced = orgData?.synced; + isSynced = Boolean(orgData?.synced); if (!isSynced) { syncRemaining = orgData?.sync_remaining ?? 0; } diff --git a/src/renderer/schemas/Governance.schema.ts b/src/renderer/schemas/Governance.schema.ts new file mode 100644 index 00000000..f0587275 --- /dev/null +++ b/src/renderer/schemas/Governance.schema.ts @@ -0,0 +1,9 @@ +export interface Governance { + // Required fields + id: number; + metaKey: string; + metaValue: string; + + // Optional fields + confirmed?: boolean; +} \ No newline at end of file diff --git a/src/renderer/schemas/Label.schema.ts b/src/renderer/schemas/Label.schema.ts index 5970e90e..e17dca7c 100644 --- a/src/renderer/schemas/Label.schema.ts +++ b/src/renderer/schemas/Label.schema.ts @@ -1,4 +1,4 @@ -import {LabelUnit} from "./LableUnit.schema"; +import {LabelUnit} from "./LabelUnit.schema"; export interface Label { // Optional properties diff --git a/src/renderer/schemas/LableUnit.schema.ts b/src/renderer/schemas/LabelUnit.schema.ts similarity index 100% rename from src/renderer/schemas/LableUnit.schema.ts rename to src/renderer/schemas/LabelUnit.schema.ts diff --git a/src/renderer/schemas/Organization.schema.ts b/src/renderer/schemas/Organization.schema.ts new file mode 100644 index 00000000..35ffafd9 --- /dev/null +++ b/src/renderer/schemas/Organization.schema.ts @@ -0,0 +1,22 @@ +export interface Organization { + // Required fields + id: number; + orgUid: string; + name: string; + icon: string; + registryId: string; + registryHash: string; + fileStoreId: string; + prefix: string; + + // Optional fields + orgHash?: string; + fileStoreSubscribed?: boolean; + subscribed?: boolean; + isHome?: boolean; + metadata?: string; + synced?: boolean; + sync_remaining?: number; + createdAt?: Date; + updatedAt?: Date; +} \ No newline at end of file diff --git a/src/renderer/schemas/Unit.schema.ts b/src/renderer/schemas/Unit.schema.ts new file mode 100644 index 00000000..7af40e6e --- /dev/null +++ b/src/renderer/schemas/Unit.schema.ts @@ -0,0 +1,26 @@ +import {Label} from './Label.schema'; +import {Issuance} from "@/schemas/Issuance.schema"; + +export interface Unit { + // Required properties + countryJurisdictionOfOwner: string; + unitCount: number; + vintageYear: number; + unitType: string; + unitStatus: string; + unitRegistryLink: string; + correspondingAdjustmentDeclaration: string; + correspondingAdjustmentStatus: string; + issuance: Issuance; + labels: Label[]; + + // Optional properties + projectLocationId?: string | null; + unitOwner?: string | null; + inCountryJurisdictionOfOwner?: string | null; + marketplace?: string | null; + marketplaceLink?: string | null; + marketplaceIdentifier?: string | null; + unitTags?: string | null; + unitStatusReason?: string | null; +} \ No newline at end of file