Skip to content

Commit

Permalink
Merge pull request #15 from CSCfi/CSCFC4EMSCR-244_Fix-merge-errors-an…
Browse files Browse the repository at this point in the history
…d-clean-up

MSCR-244 Change schema detail localizing back and clean up code
  • Loading branch information
maariaw authored Nov 24, 2023
2 parents b937c28 + d039db0 commit 3dc5147
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 62 deletions.
11 changes: 7 additions & 4 deletions mscr-ui/src/modules/schema-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -53,7 +54,9 @@ export default function SchemaView({ schemaId }: { schemaId: string }) {
{selectedTab === 0 && (
<MetadataAndFiles schemaDetails={schemaDetails} />
)}
{selectedTab === 1 && <VersionHistory schemaDetails={schemaDetails} />}
{selectedTab === 1 && (
<VersionHistory schemaDetails={schemaDetails} />
)}
</>
);
}
Expand Down
47 changes: 21 additions & 26 deletions mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
26 changes: 1 addition & 25 deletions mscr-ui/src/modules/schema-view/version-history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<HistoryTable
headers={headers}
revisions={revisions}
revisions={schemaDetails.revisions}
ariaLabel={t('schema.versions')}
/>
);
Expand Down
8 changes: 1 addition & 7 deletions mscr-ui/src/pages/schema/[...pid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 (
Expand All @@ -40,7 +35,6 @@ export default function SchemaPage(props: IndexPageProps) {
user={props.user ?? undefined}
fakeableUsers={props.fakeableUsers}
>
{/*{renderSchema()}*/}
<SchemaView schemaId={schemaId} />
</Layout>
</CommonContextProvider>
Expand Down

0 comments on commit 3dc5147

Please sign in to comment.