Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCFC4EMSCR- 261 List files on schema detail page #21

Merged
merged 8 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mscr-ui/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@
"schema": {
"created": "Created",
"description": "Description",
"file": {
"actions": "Actions",
"added": "Added",
"format": "Format",
"label": "Schema files",
"name": "Filename",
"id":"ID",
"size":"Size"
},
"format": "Format",
"metadata": "Metadata",
"metadata-and-files": "Metadata and files",
Expand Down
7 changes: 7 additions & 0 deletions mscr-ui/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
"schema": {
"created": "",
"description": "",
"file": {
"actions": "",
"added": "",
"format": "",
"label": "",
"name": ""
},
"format": "",
"metadata": "",
"metadata-and-files": "",
Expand Down
7 changes: 7 additions & 0 deletions mscr-ui/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
"schema": {
"created": "",
"description": "",
"file": {
"actions": "",
"added": "",
"format": "",
"label": "",
"name": ""
},
"format": "",
"metadata": "",
"metadata-and-files": "",
Expand Down
124 changes: 48 additions & 76 deletions mscr-ui/src/common/components/schema-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { useTranslation } from 'next-i18next';
import { ExternalLink, Button, Text, Label } from 'suomifi-ui-components';
import { List, ListItem } from './schema-list.styles';
import { Schema } from '@app/common/interfaces/schema.interface';
import { Grid, InputLabel } from '@mui/material';
import {
Grid,
InputLabel,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
} from '@mui/material';
import router from 'next/router';
import { getLanguageVersion } from '@app/common/utils/get-language-version';

Expand All @@ -13,13 +22,7 @@ export interface SchemaListProps {
deleteDisabled: string[] | boolean;
}

export default function SchemaList({
items,
handleRemoval,

labelRow,
deleteDisabled,
}: SchemaListProps) {
export default function SchemaList({ items }: SchemaListProps) {
const { t } = useTranslation('admin');
const lang = router.locale ?? '';

Expand All @@ -29,81 +32,50 @@ export default function SchemaList({
}

function handleClick(pid: string): void {
console.log(pid);
// will go the schema detail page
router.push(`/schema/${pid}`);
if (pid) {
router.push(`/schema/${pid}`);
}
}

return (
//Creating Header row

<div>
<List className="header-list">
<ListItem>
<Grid container spacing={2} style={{ fontWeight: 'bold' }}>
<Grid item xs={2}>
{'Name'}
</Grid>
<Grid item xs={2}>
{'Namespace'}
</Grid>
<Grid item xs={2}>
{'Status'}
</Grid>
<Grid item xs={2}>
{'Revision'}
</Grid>
<Grid item xs={2}>
{'PID'}
</Grid>
<Grid item xs={2}></Grid>
</Grid>
</ListItem>
</List>
<List className="inline-list">
{items &&
items.map((item) => (
<ListItem
key={item.pid}
onClick={() => handleClick(item.pid)}
onMouseEnter={() => item.onMouseEnter && item.onMouseEnter()}
onMouseLeave={() => item.onMouseLeave && item.onMouseLeave()}
onKeyDown={(e) => e.key === 'Enter' && item.onClick()}
>
<Grid container spacing={2}>
<Grid item xs={2}>
{getLanguageVersion({ data: item.label, lang })}
</Grid>
<Grid item xs={2}>
{item.namespace}
</Grid>
<Grid item xs={2}>
{item.state}
</Grid>
<Grid item xs={2}>
{item.versionLabel}
</Grid>
<Grid item xs={2}>
{item.pid}
</Grid>
<Grid item xs={2}>
{Array.isArray(deleteDisabled) &&
deleteDisabled.includes(item.pid) ? (
<></>
) : (
<Button
variant="secondaryNoBorder"
icon="remove"
onClick={() => handleRemoval(item.pid)}
>
{t('remove')}
</Button>
)}
</Grid>
</Grid>
</ListItem>
))}
</List>
<TableContainer>
<Table aria-label={'Schemas'}>
<TableHead>
<TableRow>
<TableCell> {'Name'}</TableCell>
<TableCell>{'Namespace'}</TableCell>
<TableCell>{'Status'}</TableCell>
<TableCell>{'Revision'}</TableCell>
<TableCell>{'PID'}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{/*TODO: Use the below template to create lines for files*/}
{items &&
items.map((item) => (
<TableRow
key={item.pid}
hover={true}
onClick={() => handleClick(item.pid)}
sx={{ cursor: 'pointer' }}
>
<TableCell>
{' '}
{getLanguageVersion({ data: item.label, lang })}
</TableCell>
<TableCell>{item.namespace}</TableCell>
<TableCell>{item.state}</TableCell>
<TableCell>{item.versionLabel}</TableCell>
<TableCell>{item.pid}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
);
}
15 changes: 15 additions & 0 deletions mscr-ui/src/common/components/schema-list/schema-list.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from 'styled-components';


export const List = styled.div`
display: flex;
flex-direction: column;
Expand All @@ -12,6 +13,9 @@ export const List = styled.div`
.header-list {
font-weight: bold;
}
.inline-list{

}
`;

export const ListItem = styled.div`
Expand All @@ -33,4 +37,15 @@ export const ListItem = styled.div`
.fi-link--external {
font-size: 16px;
}
&:hover {
background-color: ${(props) => props.theme.suomifi.colors.highlightBase};
color: ${(props) => props.theme.suomifi.colors.whiteBase};
border-radius: 2px;
cursor: pointer;

.fi-text {
color: ${(props) => props.theme.suomifi.colors.whiteBase};
}
}
`;

8 changes: 8 additions & 0 deletions mscr-ui/src/common/components/schema/schema.slice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const schemaApi = createApi({
method: 'GET',
}),
}),
// TODO: What is the return type?
getSchemaOriginal: builder.query<undefined, string>({
query: (pid) => ({
url: `/schema/${pid}/original`,
method: 'GET',
}),
}),
postSchema: builder.mutation<
string,
{
Expand Down Expand Up @@ -86,6 +93,7 @@ export const {
usePutSchemaMutation,
useGetSchemaQuery,
useGetSchemaWithRevisionsQuery,
useGetSchemaOriginalQuery,
usePostSchemaMutation,
useDeleteSchemaMutation,
useGetSchemasQuery,
Expand Down
3 changes: 1 addition & 2 deletions mscr-ui/src/common/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ export default function BasicTable() {
return (
<div>
{'Schemas'}
<Separator isLarge />
<SchemaList
items={schemas ?? []}
handleRemoval={function (value: string): void {
throw new Error('Function not implemented.');
}}
deleteDisabled={false}
></SchemaList>
<Separator isLarge />

{'Crosswalks'}
<Separator isLarge />

Expand Down
11 changes: 11 additions & 0 deletions mscr-ui/src/common/interfaces/schema.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ExposureTwoTone } from "@mui/icons-material";

export interface Schema {
namespace?: string;
pid?: string;
Expand Down Expand Up @@ -35,6 +37,15 @@ export interface Revision {

export interface SchemaWithVersionInfo extends Schema {
revisions: Revision[];
fileMetadata?: SchemaFileData[];
}

export interface SchemaFileData{
id?: string;
contentType?: string,
size?: number;
fileID?: number;
name?: string;
}

export interface Organization {
Expand Down
1 change: 1 addition & 0 deletions mscr-ui/src/modules/schema-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function SchemaForm({
>
<DropdownItem value={'JSONSCHEMA'}>{'JSON'}</DropdownItem>
<DropdownItem value={'CSV'}>{'CSV'}</DropdownItem>
<DropdownItem value={'PDF'}>{'PDF'}</DropdownItem>
</Dropdown>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion mscr-ui/src/modules/schema-form/schema-form-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function SchemaFormModal({ refetch }: SchemaFormModalProps) {
<FileDropArea
setFileData={setFileData}
setIsValid={setIsValid}
validFileTypes={['json', 'csv']}
validFileTypes={['json', 'csv','pdf']}
translateFileUploadError={translateFileUploadError}
/>
<Separator isLarge></Separator>
Expand Down
5 changes: 4 additions & 1 deletion mscr-ui/src/modules/schema-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function SchemaView({
// isError,
// error,
} = useGetSchemaWithRevisionsQuery(schemaId);
// TODO: I can't make sense of the format this returns, and how it would be offered for download

const [selectedTab, setSelectedTab] = useState(0);

function a11yProps(index: number) {
Expand Down Expand Up @@ -71,7 +73,8 @@ export default function SchemaView({


{selectedTab === 0 && (
<MetadataAndFiles schemaDetails={schemaDetails} />
<MetadataAndFiles schemaDetails={schemaDetails} schemaFiles={schemaDetails?.fileMetadata
} />
)}
{selectedTab === 1 && <VersionHistory schemaDetails={schemaDetails} />}
</Grid>
Expand Down
Loading