From d039db0371ab8638648898b4357c1532a63417c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maaria=20Wahlstr=C3=B6m?= Date: Fri, 24 Nov 2023 16:36:30 +0200 Subject: [PATCH] MSCR-244 Change schema detail localizing back and clean up code --- mscr-ui/src/modules/schema-view/index.tsx | 11 +++-- .../schema-view/metadata-and-files/index.tsx | 47 +++++++++---------- .../schema-view/version-history/index.tsx | 26 +--------- mscr-ui/src/pages/schema/[...pid].tsx | 8 +--- 4 files changed, 30 insertions(+), 62 deletions(-) diff --git a/mscr-ui/src/modules/schema-view/index.tsx b/mscr-ui/src/modules/schema-view/index.tsx index 0a37bf967..d829d8908 100644 --- a/mscr-ui/src/modules/schema-view/index.tsx +++ b/mscr-ui/src/modules/schema-view/index.tsx @@ -2,10 +2,10 @@ import Box from '@mui/material/Box'; import Tabs from '@mui/material/Tabs'; import Tab from '@mui/material/Tab'; import { SyntheticEvent, useState } from 'react'; -import MetadataAndFiles from '@app/modules/schema-view/metadata-and-files'; import VersionHistory from '@app/modules/schema-view/version-history'; import { useTranslation } from 'next-i18next'; import { useGetSchemaWithRevisionsQuery } from '@app/common/components/schema/schema.slice'; +import MetadataAndFiles from './metadata-and-files'; export default function SchemaView({ schemaId }: { schemaId: string }) { const { t } = useTranslation('common'); @@ -14,8 +14,9 @@ export default function SchemaView({ schemaId }: { schemaId: string }) { data: schemaDetails, isLoading, isSuccess, - isError, - error, + // Add these in when adding error handling + // isError, + // error, } = useGetSchemaWithRevisionsQuery(schemaId); const [selectedTab, setSelectedTab] = useState(0); @@ -53,7 +54,9 @@ export default function SchemaView({ schemaId }: { schemaId: string }) { {selectedTab === 0 && ( )} - {selectedTab === 1 && } + {selectedTab === 1 && ( + + )} ); } diff --git a/mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx b/mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx index 15f8bc0e0..d275df845 100644 --- a/mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx +++ b/mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx @@ -40,32 +40,27 @@ export default function MetadataAndFiles({ schemaNamespace: '', }; } - function languageFinder(langTaggedData: { [key: string]: string }) { - const primaryOption = Object.entries(langTaggedData).find( - (t) => t[0] === lang - )?.[1]; - const englishOption = Object.entries(langTaggedData).find( - (t) => t[0] === 'en' - )?.[1]; - return primaryOption ?? englishOption; - } - return { - schemaPid: schemaDetails?.pid ?? '', - schemaLabel: schemaDetails?.label - ? languageFinder(schemaDetails.label) ?? '' - : '', - schemaDescription: schemaDetails?.description - ? languageFinder(schemaDetails.description) ?? '' - : '', - schemaCreated: schemaDetails?.created ?? '', - schemaModified: schemaDetails?.modified ?? '', - schemaState: schemaDetails?.state ?? '', - schemaOrganizations: schemaDetails?.organizations.toString() ?? '', - schemaVisibility: schemaDetails?.visibility ?? '', - schemaFormat: schemaDetails?.format ?? '', - schemaVersionLabel: schemaDetails?.versionLabel ?? '', - schemaNamespace: schemaDetails?.namespace ?? '', - }; + const organizations = getOrganizations(schemaDetails.organizations, lang) + .map((org) => org.label).join(', '); + return ( + { + schemaPid: schemaDetails?.pid ?? '', + schemaLabel: schemaDetails?.label + ? getLanguageVersion({ data: schemaDetails.label, lang, appendLocale: true }) + : '', + schemaDescription: schemaDetails?.description + ? getLanguageVersion({ data: schemaDetails.description, lang, appendLocale: true }) ?? '' + : '', + schemaCreated: schemaDetails?.created ?? '', + schemaModified: schemaDetails?.modified ?? '', + schemaState: schemaDetails?.state ?? '', + schemaOrganizations: organizations, + schemaVisibility: schemaDetails?.visibility ?? '', + schemaFormat: schemaDetails?.format ?? '', + schemaVersionLabel: schemaDetails?.versionLabel ?? '', + schemaNamespace: schemaDetails?.namespace ?? '' + } + ); }, [schemaDetails, lang]); return ( diff --git a/mscr-ui/src/modules/schema-view/version-history/index.tsx b/mscr-ui/src/modules/schema-view/version-history/index.tsx index 6552dc807..d963b008b 100644 --- a/mscr-ui/src/modules/schema-view/version-history/index.tsx +++ b/mscr-ui/src/modules/schema-view/version-history/index.tsx @@ -16,34 +16,10 @@ export default function VersionHistory({ t('schema.state'), ]; - const revisions = schemaDetails.revisions; - // Temporarily mock data, really should be schemaDetails.revisions or something - // const revisions = - // [ - // { - // 'pid': 'urn:IAMNOTAPID:9f02b4da-1766-4f3a-aa61-270c0bd3e460', - // 'label': { - // 'en': 'string' - // }, - // 'versionLabel': '1', - // 'created': '2023-11-21', - // 'state': 'PUBLISHED' - // }, - // { - // 'pid': 'urn:IAMNOTAPID:4faa61a3-1de9-451d-80f2-cce179e82084', - // 'label': { - // 'en': 'string' - // }, - // 'versionLabel': '1.1', - // 'created': '2023-11-21', - // 'state': 'DRAFT' - // } - // ]; - return ( ); diff --git a/mscr-ui/src/pages/schema/[...pid].tsx b/mscr-ui/src/pages/schema/[...pid].tsx index 61ba98613..44e1c069d 100644 --- a/mscr-ui/src/pages/schema/[...pid].tsx +++ b/mscr-ui/src/pages/schema/[...pid].tsx @@ -16,11 +16,6 @@ import { import { getRunningQueriesThunk as getInternalResourcesRunningQueriesThunk } from '@app/common/components/search-internal-resources/search-internal-resources.slice'; import { getRunningQueriesThunk as getVisualizationRunningQueriesThunk } from '@app/common/components/visualization/visualization.slice'; import { useRouter } from 'next/router'; -import { useGetSchemaQuery } from '@app/common/components/schema/schema.slice'; -import { Schema } from '@app/common/interfaces/schema.interface'; -import UpdateWithFileModal from '@app/common/components/update-with-file-modal'; -import Separator from 'yti-common-ui/components/separator'; -import { BasicBlock, BasicBlockExtraWrapper } from 'yti-common-ui/block'; import { MscrUser } from '@app/common/interfaces/mscr-user.interface'; import SchemaView from '@app/modules/schema-view'; @@ -31,7 +26,7 @@ interface IndexPageProps extends CommonContextState { } export default function SchemaPage(props: IndexPageProps) { - const { query, asPath } = useRouter(); + const { query, } = useRouter(); const schemaId = (query?.pid ?? '') as string; return ( @@ -40,7 +35,6 @@ export default function SchemaPage(props: IndexPageProps) { user={props.user ?? undefined} fakeableUsers={props.fakeableUsers} > - {/*{renderSchema()}*/}