Skip to content

Commit 7ecb79c

Browse files
committed
refactor(api): Resolve breaking changes in DM API 0.7
This is missing updates to dataset schema editing
1 parent e050101 commit 7ecb79c

38 files changed

+265
-282
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NEXT_PUBLIC_AUTH0_LOGIN=$BASE_PATH/api/auth/login
99
# or the other being used. Not combined.
1010
AUTH0_BASE_URL=$BASE_URL$VERCEL_URL$BASE_PATH
1111

12-
AUTH0_ISSUER_BASE_URL=$KEYCLOAK_URL/realms/squonk
12+
AUTH0_ISSUER_BASE_URL=$KEYCLOAK_URL
1313
AUTH0_ENABLE_TELEMETRY=False
1414

1515
# MB

.env.local.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ ACCOUNT_SERVER_API_SERVER='https://squonk.informaticsmatters.org/account-server-
2525
# For multiple NextJS apps on the same domain, the secret must be the same on each!
2626
AUTH0_SECRET='LONG_RANDOM_VALUE'
2727
# Auth Issuer Location
28-
KEYCLOAK_URL='https://squonk.informaticsmatters.org/auth'
28+
KEYCLOAK_URL='https://squonk.informaticsmatters.org/auth/realms/squonk'
29+
KEYCLOAK_REALM=squonk
2930
# Client ID and Secret of confidential Keycloak client
3031
AUTH0_CLIENT_ID='data-manager-ui-staging'
3132
AUTH0_CLIENT_SECRET='e32...daaa2d'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env.local
30+
.env.squonk.local
3031
.env.development.local
3132
.env.test.local
3233
.env.production.local

components/DatasetsTable/DatasetDetails/DatasetDetails.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { useState } from 'react';
44

55
import type { DatasetSummary, DatasetVersionSummary } from '@squonk/data-manager-client';
66

7-
import { Container, Link, List } from '@material-ui/core';
7+
import { Container, Link, List, Typography } from '@material-ui/core';
88

99
import { useKeycloakUser } from '../../../hooks/useKeycloakUser';
10+
import { Labels } from '../../labels/Labels';
11+
import { NewLabelButton } from '../../labels/NewLabelButton';
1012
import { ModalWrapper } from '../../modals/ModalWrapper';
1113
import { PageSection } from '../../PageSection';
1214
import { VersionInfoSection } from './VersionInfoSection/VersionInfoSection';
@@ -41,9 +43,7 @@ export const DatasetDetails: FC<DatasetDetailsProps> = ({ dataset, version, data
4143

4244
const { user } = useKeycloakUser();
4345

44-
const isEditor = !!user.username && dataset.editors.includes(user.username);
45-
const isOwner = dataset.owner === user.username;
46-
const editable = isEditor || isOwner;
46+
const editable = !!user.username && dataset.editors.includes(user.username);
4747

4848
useLayoutEffect(() => {
4949
setSelectedVersion(version);
@@ -73,13 +73,17 @@ export const DatasetDetails: FC<DatasetDetailsProps> = ({ dataset, version, data
7373
<PageSection title="Editors">
7474
<ManageDatasetEditorsSection dataset={dataset} />
7575
</PageSection>
76+
77+
<Typography gutterBottom component="h4" variant="h5">
78+
Labels <NewLabelButton datasetId={dataset.dataset_id} />
79+
</Typography>
80+
<Labels datasetId={dataset.dataset_id} datasetVersion={version} />
7681
</>
7782
)}
7883

7984
<PageSection title="Working Version">
8085
<WorkingVersionSection
8186
dataset={dataset}
82-
editable={editable}
8387
setVersion={setSelectedVersion}
8488
version={selectedVersion}
8589
/>

components/DatasetsTable/DatasetDetails/NewVersionListItem.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ListItem, ListItemSecondaryAction, ListItemText } from '@material-ui/co
1010
import { Typography } from '@material-ui/core';
1111
import BackupRoundedIcon from '@material-ui/icons/BackupRounded';
1212

13-
import { ORG_ID, UNIT_ID } from '../../../utils/ASIdentities';
13+
import { useCurrentOrg, useCurrentUnit } from '../../../context/organisationUnitContext';
1414
import { ModalWrapper } from '../../modals/ModalWrapper';
1515
import { Dropzone } from '../../uploads/Dropzone';
1616
import { FileTypeOptions } from '../../uploads/FileTypeOptions';
@@ -40,6 +40,9 @@ export const NewVersionListItem = ({ dataset, datasetName }: NewVersionListItemP
4040
// State to track per-file-type options for the new dataset version
4141
const [optionsFormData, setOptionsFormData] = useState<FileTypeOptionsState>({});
4242

43+
const unit = useCurrentUnit();
44+
const org = useCurrentOrg();
45+
4346
return (
4447
<>
4548
<ListItem button onClick={() => setOpen(true)}>
@@ -62,21 +65,20 @@ export const NewVersionListItem = ({ dataset, datasetName }: NewVersionListItemP
6265
onSubmit={async () => {
6366
const parentVersion = Math.max(...dataset.versions.map((v) => v.version));
6467
const parent = dataset.versions.find((version) => version.version === parentVersion);
65-
if (file && parent) {
68+
if (file && parent && org && unit) {
6669
// For consistency with the main file upload, I don't use the mutation hook here. This
6770
// allows reliable upload progress tracking.
6871
const response = await uploadDataset(
6972
{
7073
dataset_file: file.file,
7174
dataset_type: parent.type,
7275
as_filename: parent.file_name,
73-
parent_id: dataset.dataset_id,
74-
parent_version: parentVersion,
76+
dataset_id: dataset.dataset_id,
7577
format_extra_variables: optionsFormData[parent.type]
7678
? JSON.stringify(optionsFormData[parent.type])
7779
: undefined,
78-
organisation_id: ORG_ID,
79-
unit_id: UNIT_ID,
80+
organisation_id: org.id,
81+
unit_id: unit.id,
8082
},
8183
{
8284
onUploadProgress: (progressEvent: ProgressEvent) => {

components/DatasetsTable/DatasetDetails/VersionActionsSection/DatasetSchemaListItem/DatasetSchemaViewModal/useDatasetSchema.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { useState } from 'react';
22
import { useQueryClient } from 'react-query';
33

4-
import {
5-
getGetSchemaQueryKey,
6-
useAddAnnotations,
7-
useGetSchema,
8-
useUpdateMetadata,
9-
} from '@squonk/data-manager-client/dataset';
4+
import { getGetSchemaQueryKey, useGetSchema } from '@squonk/data-manager-client/dataset';
5+
import { useAddMetadata, useAddMetadataVersion } from '@squonk/data-manager-client/metadata';
106

117
import type { TypedSchema } from './types';
128
import { useEditableSchemaView } from './useEditableSchema';
@@ -27,15 +23,15 @@ export const useDatasetSchema = (datasetId: string, version: number) => {
2723
isError: isUpdateMetadataError,
2824
error: updateMetadataError,
2925
reset: resetUpdateMetadata,
30-
mutateAsync: mutateUpdateMetadata,
31-
} = useUpdateMetadata();
26+
// mutateAsync: updateMetadata,
27+
} = useAddMetadata();
3228

3329
const {
3430
isError: isAddAnnotationsError,
3531
error: addAnnotationsError,
3632
reset: resetAddAnnotations,
37-
mutateAsync: mutateAddAnnotations,
38-
} = useAddAnnotations();
33+
mutateAsync: addAnnotations,
34+
} = useAddMetadataVersion();
3935

4036
const [isSaving, setIsSaving] = useState(false);
4137

@@ -62,21 +58,21 @@ export const useDatasetSchema = (datasetId: string, version: number) => {
6258

6359
// Only update description if it was changed.
6460
if (description !== undefined) {
65-
const data = { description };
66-
promises.push(
67-
mutateUpdateMetadata({
68-
datasetid: datasetId,
69-
datasetversion: version,
70-
metaparameters: JSON.stringify(data),
71-
}),
72-
);
61+
// const data = { description };
62+
// promises.push(
63+
// updateMetadata({
64+
// datasetid: datasetId,
65+
// datasetversion: version,
66+
// metaparameters: JSON.stringify(data),
67+
// }),
68+
// );
7369
}
7470

7571
// Only update field definitions if they were changed.
7672
if (fields) {
7773
const data = { type: 'FieldsDescriptorAnnotation', origin: 'data-manager-api', fields };
7874
promises.push(
79-
mutateAddAnnotations({
75+
addAnnotations({
8076
datasetid: datasetId,
8177
datasetversion: version,
8278
data: { annotations: JSON.stringify(data) },

components/DatasetsTable/DatasetDetails/WorkingVersionSection.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { css } from '@emotion/react';
44
import { Box, MenuItem, TextField, Typography, useTheme } from '@material-ui/core';
55

66
import { DownloadButton } from '../../DownloadButton';
7-
import { Labels } from '../../labels/Labels';
8-
import { NewLabelButton } from '../../labels/NewLabelButton';
97

108
export interface WorkingVersionSectionProps {
119
/**
@@ -20,10 +18,6 @@ export interface WorkingVersionSectionProps {
2018
* Setter to set the selected version.
2119
*/
2220
setVersion: (version: DatasetVersionSummary) => void;
23-
/**
24-
* Whether the dataset version is editable.
25-
*/
26-
editable: boolean;
2721
}
2822

2923
/**
@@ -33,7 +27,6 @@ export const WorkingVersionSection = ({
3327
dataset,
3428
version,
3529
setVersion,
36-
editable,
3730
}: WorkingVersionSectionProps) => {
3831
const theme = useTheme();
3932

@@ -79,16 +72,6 @@ export const WorkingVersionSection = ({
7972
/>
8073
</div>
8174
</Box>
82-
{/* Top level editing - operations that don't have a "submit" */}
83-
{editable && (
84-
<>
85-
<Typography gutterBottom component="h4" variant="h5">
86-
Labels{' '}
87-
<NewLabelButton datasetId={dataset.dataset_id} datasetVersion={version.version} />
88-
</Typography>
89-
<Labels datasetId={dataset.dataset_id} datasetVersion={version} />
90-
</>
91-
)}
9275
</>
9376
);
9477
};

components/DatasetsTable/DatasetsTable.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,8 @@ export const DatasetsTable = () => {
7878
accessor: 'editors',
7979
Header: 'Editors',
8080
sortType: editorsSorter,
81-
Cell: ({ value: editors, row }) => {
82-
return (
83-
<>
84-
<i>{row.original.owner}</i>
85-
{editors.length > 1 && ', '}
86-
{editors.filter((editor) => editor !== row.original.owner).join(', ')}
87-
</>
88-
);
81+
Cell: ({ value: editors }) => {
82+
return editors.join(', ');
8983
},
9084
},
9185
{
@@ -131,6 +125,7 @@ export const DatasetsTable = () => {
131125
datasetSummary: dataset,
132126
datasetVersion: version,
133127
subRows: [],
128+
owner: version.owner,
134129
})),
135130
};
136131
}) || [],

components/DatasetsTable/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type TableDatasetBase = {
77
labels: Record<string, string | string[]>;
88
dataset_id: string;
99
editors: string[];
10-
owner: string;
1110
version?: number;
1211
subRows: TableDataset[];
1312
// Pointers
@@ -22,6 +21,7 @@ export type TableDatasetRow = TableDatasetBase & {
2221
export type TableDatasetSubRow = TableDatasetBase & {
2322
type: 'subRow';
2423
version: number;
24+
owner?: string;
2525
};
2626

2727
/**

0 commit comments

Comments
 (0)