Skip to content

Commit a979bc6

Browse files
authored
Merge pull request #13 from CSCfi/CSCFC4EMSCR-244_Create-schema-detail-page
CSCFC4EMSCR-244 Get revisions from API with schema.slice
2 parents 69ff88c + a0c8dc5 commit a979bc6

File tree

7 files changed

+66
-53
lines changed

7 files changed

+66
-53
lines changed

mscr-ui/src/common/components/history-table/index.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ import TableHead from '@mui/material/TableHead';
44
import TableRow from '@mui/material/TableRow';
55
import TableCell from '@mui/material/TableCell';
66
import TableBody from '@mui/material/TableBody';
7+
import { Revision } from '@app/common/interfaces/schema.interface';
78

8-
export interface Revision {
9-
pid: string;
10-
label: {
11-
[key: string]: string;
12-
};
13-
versionLabel: string;
14-
state: string;
15-
created: string;
16-
}
179
export default function HistoryTable({ headers, revisions, ariaLabel }: { headers: Array<string>; revisions: Revision[]; ariaLabel: string }) {
1810
return (
1911
<TableContainer>

mscr-ui/src/common/components/schema/schema.slice.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import isHydrate from '@app/store/isHydrate';
77
import {
88
Schema,
99
SchemaFormType,
10+
SchemaWithVersionInfo
1011
} from '@app/common/interfaces/schema.interface';
1112

1213
export const schemaApi = createApi({
@@ -35,6 +36,12 @@ export const schemaApi = createApi({
3536
method: 'GET',
3637
}),
3738
}),
39+
getSchemaWithRevisions: builder.query<SchemaWithVersionInfo, string>({
40+
query: (pid: string) => ({
41+
url: `/schema/${pid}?includeVersionInfo=true`,
42+
method: 'GET'
43+
})
44+
}),
3845
postSchema: builder.mutation<
3946
string,
4047
{
@@ -67,6 +74,7 @@ export const schemaApi = createApi({
6774
export const {
6875
usePutSchemaMutation,
6976
useGetSchemaQuery,
77+
useGetSchemaWithRevisionsQuery,
7078
usePostSchemaMutation,
7179
useDeleteSchemaMutation,
7280
useGetSchemasQuery,

mscr-ui/src/common/interfaces/schema.interface.ts

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ export interface Schema {
2222
uri?: string;
2323
versionLabel?: string;
2424
}
25+
26+
export interface Revision {
27+
pid: string;
28+
label: {
29+
[key: string]: string;
30+
};
31+
versionLabel: string;
32+
state?: string;
33+
created?: string;
34+
}
35+
36+
export interface SchemaWithVersionInfo extends Schema {
37+
revisions: Revision[];
38+
}
39+
2540
export interface Organization {
2641
id: string;
2742
parentOrganization?: string;

mscr-ui/src/modules/schema-view/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { SyntheticEvent, useState } from 'react';
55
import MetadataAndFiles from '@app/modules/schema-view/metadata-and-files';
66
import VersionHistory from '@app/modules/schema-view/version-history';
77
import {useTranslation} from 'next-i18next';
8-
import {useGetSchemaQuery} from '@app/common/components/schema/schema.slice';
8+
import { useGetSchemaWithRevisionsQuery } from '@app/common/components/schema/schema.slice';
99

1010
export default function SchemaView({ schemaId }: { schemaId: string }) {
1111
const { t } = useTranslation('common');
1212

1313
const { data: schemaDetails, isLoading, isSuccess, isError, error } =
14-
useGetSchemaQuery(schemaId);
14+
useGetSchemaWithRevisionsQuery(schemaId);
1515
const [selectedTab, setSelectedTab] = useState(0);
1616

1717

mscr-ui/src/modules/schema-view/metadata-and-files/index.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import {useTranslation} from 'next-i18next';
2-
import {useMemo} from 'react';
3-
import {Schema} from '@app/common/interfaces/schema.interface';
1+
import { useTranslation } from 'next-i18next';
2+
import { useMemo } from 'react';
3+
import { Schema } from '@app/common/interfaces/schema.interface';
44
import router from 'next/router';
55
import {
66
DescriptionList,
77
DescriptionListTitle
88
} from '@app/modules/schema-view/metadata-and-files/metadata-and-files.styles';
9-
import {Grid} from '@mui/material';
10-
import {Heading} from 'suomifi-ui-components';
9+
import { Grid } from '@mui/material';
10+
import { Heading } from 'suomifi-ui-components';
11+
import { getLanguageVersion } from '@app/common/utils/get-language-version';
12+
import getOrganizations from '@app/common/utils/get-organizations';
1113

1214
export default function MetadataAndFiles({ schemaDetails }: { schemaDetails?: Schema }) {
1315
const { t } = useTranslation('common');
14-
const lang = router.locale;
16+
const lang = router.locale ?? '';
17+
18+
// TODO: Editing -> Only edit with permission, we have util has-permission
1519

16-
// TODO: Only edit with permission, we have util has-permission
17-
// TODO: Get organization names neatly
18-
// Locale: Object.entries(schemaDetails.label).find((t) => t[0] === lang)?.[1] ?? ''
19-
// Organization: see datamodel-ui/src/modules/model/model-info-view.tsx
2020
interface SchemaDisplay {
2121
[key:string]: string;
2222
}
@@ -38,24 +38,21 @@ export default function MetadataAndFiles({ schemaDetails }: { schemaDetails?: Sc
3838
}
3939
);
4040
}
41-
function languageFinder(langTaggedData: { [key:string]: string }) {
42-
const primaryOption = Object.entries(langTaggedData).find((t) => t[0] === lang)?.[1];
43-
const englishOption = Object.entries(langTaggedData).find((t) => t[0] === 'en')?.[1];
44-
return primaryOption ?? englishOption;
45-
}
41+
const organizations = getOrganizations(schemaDetails.organizations, lang)
42+
.map((org) => org.label).join(', ');
4643
return (
4744
{
4845
schemaPid: schemaDetails?.pid ?? '',
4946
schemaLabel: schemaDetails?.label
50-
? languageFinder(schemaDetails.label) ?? ''
47+
? getLanguageVersion({ data: schemaDetails.label, lang, appendLocale: true })
5148
: '',
5249
schemaDescription: schemaDetails?.description
53-
? languageFinder(schemaDetails.description) ?? ''
50+
? getLanguageVersion({ data: schemaDetails.description, lang, appendLocale: true }) ?? ''
5451
: '',
5552
schemaCreated: schemaDetails?.created ?? '',
5653
schemaModified: schemaDetails?.modified ?? '',
5754
schemaState: schemaDetails?.state ?? '',
58-
schemaOrganizations: schemaDetails?.organizations.toString() ?? '',
55+
schemaOrganizations: organizations,
5956
schemaVisibility: schemaDetails?.visibility ?? '',
6057
schemaFormat: schemaDetails?.format ?? '',
6158
schemaVersionLabel: schemaDetails?.versionLabel ?? '',

mscr-ui/src/modules/schema-view/metadata-and-files/metadata-and-files.styles.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { styled } from 'styled-components';
1+
import styled from 'styled-components';
22

33
export const DescriptionListTitle = styled.dt`
44
font-weight: 400;

mscr-ui/src/modules/schema-view/version-history/index.tsx

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {useTranslation} from 'next-i18next';
2-
import {Schema} from '@app/common/interfaces/schema.interface';
2+
import { SchemaWithVersionInfo } from '@app/common/interfaces/schema.interface';
33
import HistoryTable from '@app/common/components/history-table';
44

5-
export default function VersionHistory({ schemaDetails }: {schemaDetails: Schema}) {
5+
export default function VersionHistory({ schemaDetails }: {schemaDetails: SchemaWithVersionInfo}) {
66
const { t } = useTranslation('common');
77

88

@@ -13,28 +13,29 @@ export default function VersionHistory({ schemaDetails }: {schemaDetails: Schema
1313
t('schema.state')
1414
];
1515

16+
const revisions = schemaDetails.revisions;
1617
// Temporarily mock data, really should be schemaDetails.revisions or something
17-
const revisions =
18-
[
19-
{
20-
'pid': 'urn:IAMNOTAPID:9f02b4da-1766-4f3a-aa61-270c0bd3e460',
21-
'label': {
22-
'en': 'string'
23-
},
24-
'versionLabel': '1',
25-
'created': '2023-11-21',
26-
'state': 'PUBLISHED'
27-
},
28-
{
29-
'pid': 'urn:IAMNOTAPID:4faa61a3-1de9-451d-80f2-cce179e82084',
30-
'label': {
31-
'en': 'string'
32-
},
33-
'versionLabel': '1.1',
34-
'created': '2023-11-21',
35-
'state': 'DRAFT'
36-
}
37-
];
18+
// const revisions =
19+
// [
20+
// {
21+
// 'pid': 'urn:IAMNOTAPID:9f02b4da-1766-4f3a-aa61-270c0bd3e460',
22+
// 'label': {
23+
// 'en': 'string'
24+
// },
25+
// 'versionLabel': '1',
26+
// 'created': '2023-11-21',
27+
// 'state': 'PUBLISHED'
28+
// },
29+
// {
30+
// 'pid': 'urn:IAMNOTAPID:4faa61a3-1de9-451d-80f2-cce179e82084',
31+
// 'label': {
32+
// 'en': 'string'
33+
// },
34+
// 'versionLabel': '1.1',
35+
// 'created': '2023-11-21',
36+
// 'state': 'DRAFT'
37+
// }
38+
// ];
3839

3940
return (
4041
<HistoryTable headers={headers} revisions={revisions} ariaLabel={t('schema.versions')}/>

0 commit comments

Comments
 (0)