Skip to content

Commit

Permalink
Render preliminarily dataset list and dataset details pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jernestmyers committed Oct 12, 2023
1 parent 80a7347 commit bd3f1bb
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 62 deletions.
119 changes: 107 additions & 12 deletions packages/libs/user-datasets/src/lib/Actions/UserDatasetsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../Service/UserDatasetWrappers';

import { FILTER_BY_PROJECT_PREF } from '../Utils/project-filter';
import { UserDataset, UserDatasetMeta } from '../Utils/types';
import { UserDataset, UserDatasetMeta, UserDatasetVDI } from '../Utils/types';

export type Action =
| DetailErrorAction
Expand Down Expand Up @@ -107,11 +107,11 @@ export const DETAIL_LOADING = 'user-datasets/detail-loading';
export type DetailLoadingAction = {
type: typeof DETAIL_LOADING;
payload: {
id: number;
id: string;
};
};

export function detailLoading(id: number): DetailLoadingAction {
export function detailLoading(id: string): DetailLoadingAction {
return {
type: DETAIL_LOADING,
payload: {
Expand All @@ -127,13 +127,13 @@ export const DETAIL_RECEIVED = 'user-datasets/detail-received';
export type DetailReceivedAction = {
type: typeof DETAIL_RECEIVED;
payload: {
id: number;
id: string;
userDataset?: UserDataset;
};
};

export function detailReceived(
id: number,
id: string,
userDataset?: UserDataset
): DetailReceivedAction {
return {
Expand Down Expand Up @@ -392,6 +392,7 @@ type SharingAction =
| SharingSuccessAction
| SharingErrorAction;

// replace w/ VDI service
export function loadUserDatasetList() {
return validateUserDatasetCompatibleThunk<ListAction>(({ wdkService }) => [
listLoading(),
Expand All @@ -402,20 +403,68 @@ export function loadUserDatasetList() {
// ignore error and default to false
() => false
),
// @ts-ignore
wdkService.getCurrentUserDatasets(),
]).then(
([filterByProject, userDatasets]) =>
listReceived(userDatasets, filterByProject),
listErrorReceived
),
]).then(([filterByProject, userDatasets]) => {
// console.log({filterByProject, userDatasets})
const vdiToExistingUds = userDatasets.map(
(ud: UserDatasetVDI): UserDataset => {
const {
name,
description,
summary,
owner,
datasetType,
projectIDs,
datasetID,
} = ud;
return {
owner: owner.firstName + ' ' + owner.lastName,
projects: projectIDs,
created: ud.created,
type: {
display: datasetType.displayName ?? datasetType.name,
name: datasetType.name,
version: datasetType.version,
},
meta: {
name,
description: description ?? name,
summary: summary ?? '',
},
ownerUserId: owner.userID,
dependencies: [],
age: 0,
size: ud.fileSizeTotal,
id: datasetID,
isCompatible: false,
isInstalled: false,
sharedWith: [],
questions: [],
uploaded: 1,
modified: 1,
percentQuotaUsed: 0,
datafiles: [],
};
}
);
// return listReceived(userDatasets, filterByProject)
return listReceived(vdiToExistingUds, filterByProject);
}, listErrorReceived),
]);
}

export function loadUserDatasetDetail(id: number) {
export function loadUserDatasetDetail(id: string) {
return validateUserDatasetCompatibleThunk<DetailAction>(({ wdkService }) => [
detailLoading(id),
// @ts-ignore
wdkService.getUserDataset(id).then(
(userDataset) => detailReceived(id, userDataset),
// @ts-ignore
(userDataset) => {
const trasnformedResposne =
transformVdiResponseToLegacyResponse(userDataset);
return detailReceived(id, trasnformedResposne);
},
(error: ServiceError) =>
error.status === 404 ? detailReceived(id) : detailError(error)
),
Expand Down Expand Up @@ -493,3 +542,49 @@ export function updateProjectFilter(filterByProject: boolean) {
projectFilter(filterByProject),
]);
}

// @ts-ignore
function transformVdiResponseToLegacyResponse(ud) {
// (ud: UserDatasetVDI): UserDataset => {
const {
name,
description,
summary,
owner,
datasetType,
projectIDs,
datasetID,
files,
} = ud;
return {
owner: owner.firstName + ' ' + owner.lastName,
projects: projectIDs ?? [],
created: ud.created,
type: {
display: datasetType.displayName ?? datasetType.name,
name: datasetType.name,
version: datasetType.version,
},
meta: {
name,
description: description ?? name,
summary: summary ?? '',
},
ownerUserId: owner.userID,
dependencies: [],
age: 0,
// @ts-ignore
size: ud.fileSizeTotal ?? files.reduce((prev, curr) => prev + curr.size, 0),
id: datasetID,
isCompatible: false,
isInstalled: false,
sharedWith: [],
questions: [],
uploaded: 1,
modified: 1,
percentQuotaUsed: 0,
datafiles: files,
};
// }
// )
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface Props {
}

interface State {
selectedRows: number[];
selectedRows: Array<number | string>;
uiState: { sort: MesaSortObject };
searchTerm: string;
sharingModalOpen: boolean;
Expand Down Expand Up @@ -122,7 +122,7 @@ class UserDatasetList extends React.Component<Props, State> {
}

isRowSelected(row: UserDataset): boolean {
const id: number = row.id;
const id: number | string = row.id;
const { selectedRows } = this.state;
return selectedRows.includes(id);
}
Expand All @@ -137,7 +137,15 @@ class UserDatasetList extends React.Component<Props, State> {
}

onMetaAttributeSaveFactory(dataset: UserDataset, attrKey: string) {
const { meta } = dataset;
// const { meta } = dataset;
const meta = {
// @ts-ignore
description: dataset.description ?? 'none',
// @ts-ignore
name: dataset.name ?? 'none',
// @ts-ignore
summary: dataset.summary ?? 'none',
};
const { updateUserDatasetDetail } = this.props;
return (value: string) =>
updateUserDatasetDetail(dataset, { ...meta, [attrKey]: value });
Expand Down Expand Up @@ -304,18 +312,18 @@ class UserDatasetList extends React.Component<Props, State> {
}

onRowSelect(row: UserDataset): void {
const id: number = row.id;
const id: number | string = row.id;
const { selectedRows } = this.state;
if (selectedRows.includes(id)) return;
const newSelection: number[] = [...selectedRows, id];
const newSelection: Array<number | string> = [...selectedRows, id];
this.setState({ selectedRows: newSelection });
}

onRowDeselect(row: UserDataset): void {
const id: number = row.id;
const id: number | string = row.id;
const { selectedRows } = this.state;
if (!selectedRows.includes(id)) return;
const newSelection: number[] = selectedRows.filter(
const newSelection: Array<number | string> = selectedRows.filter(
(selectedId) => selectedId !== id
);
this.setState({ selectedRows: newSelection });
Expand All @@ -328,14 +336,19 @@ class UserDatasetList extends React.Component<Props, State> {
.filter((dataset: UserDataset) => !selectedRows.includes(dataset.id))
.map((dataset: UserDataset) => dataset.id);
if (!unselectedRows.length) return;
const newSelection: number[] = [...selectedRows, ...unselectedRows];
const newSelection: Array<number | string> = [
...selectedRows,
...unselectedRows,
];
this.setState({ selectedRows: newSelection });
}

onMultipleRowDeselect(rows: UserDataset[]): void {
if (!rows.length) return;
const { selectedRows } = this.state;
const deselectedIds: number[] = rows.map((row: UserDataset) => row.id);
const deselectedIds: Array<number | string> = rows.map(
(row: UserDataset) => row.id
);
const newSelection = selectedRows.filter(
(id) => !deselectedIds.includes(id)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class UserDatasetDetailController extends PageController<MergedProps> {
const idChanged =
prevProps == null || prevProps.ownProps.id !== this.props.ownProps.id;
if (idChanged) {
this.props.dispatchProps.loadUserDatasetDetail(
Number(this.props.ownProps.id)
);
this.props.dispatchProps.loadUserDatasetDetail(this.props.ownProps.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import { DataNoun, UserDataset } from '../Utils/types';

import '../Components/UserDatasets.scss';

import { useConfiguredVdiClient } from '../Hooks/user-datasets';
// const VDI_SERVICE_BASE_URL = 'https://vdi-dev.local.apidb.org:8443'
const VDI_SERVICE_BASE_URL = 'http://localhost:8080';

const ActionCreators = {
showLoginForm,
loadUserDatasetList,
Expand Down Expand Up @@ -179,7 +175,6 @@ class UserDatasetListController extends PageController<Props> {
) : (
<UserDatasetList {...listProps} />
)}
<VDI baseUrl={VDI_SERVICE_BASE_URL} />
</div>
</div>
);
Expand All @@ -200,17 +195,4 @@ const enhance = connect<StateProps, DispatchProps, OwnProps, Props, StateSlice>(
})
);

type VDIProps = {
baseUrl: string;
};

function VDI({ baseUrl }: VDIProps) {
const vdi = useConfiguredVdiClient(baseUrl);
// console.log(vdi);
const uds = vdi.getCurrentUserDatasets();
// const uds = vdi.getCommunityDatasets();
console.log(uds);
return <>Working?</>;
}

export default withRouter(enhance(UserDatasetListController));
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function UserDatasetRouter<T1 extends string, T2 extends string>({
return (
<Switch>
<WdkRoute
path={`${path}/:id(\\d+)`}
path={`${path}/:id`}
requiresLogin
component={(props: RouteComponentProps<{ id: string }>) => {
return (
Expand Down
29 changes: 15 additions & 14 deletions packages/libs/user-datasets/src/lib/Service/UserDatasetWrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ const userIdsByEmailDecoder = record({
});

export const userDatasetsServiceWrappers = {
getCurrentUserDatasets: (wdkService: WdkService) => () =>
wdkService._fetchJson<UserDataset[]>(
'get',
'/users/current/user-datasets?expandDetails=true'
),
getUserDataset: (wdkService: WdkService) => (id: number) =>
wdkService._fetchJson<UserDataset>(
'get',
`/users/current/user-datasets/${id}`
),
// getCurrentUserDatasets: (wdkService: WdkService) => () =>
// wdkService._fetchJson<UserDataset[]>(
// 'get',
// '/users/current/user-datasets?expandDetails=true'
// ),
// getUserDataset: (wdkService: WdkService) => (id: number) =>
// wdkService._fetchJson<UserDataset>(
// 'get',
// `/users/current/user-datasets/${id}`
// ),
updateUserDataset:
(wdkService: WdkService) => (id: number, meta: UserDatasetMeta) =>
(wdkService: WdkService) => (id: number | string, meta: UserDatasetMeta) =>
wdkService._fetchJson<void>(
'put',
`/users/current/user-datasets/${id}/meta`,
JSON.stringify(meta)
),
removeUserDataset: (wdkService: WdkService) => (id: number) =>
removeUserDataset: (wdkService: WdkService) => (id: number | string) =>
wdkService._fetchJson<void>('delete', `/users/current/user-datasets/${id}`),
editUserDatasetSharing:
(wdkService: WdkService) =>
Expand Down Expand Up @@ -79,8 +79,9 @@ export const userDatasetsServiceWrappers = {
);
},
getUserDatasetDownloadUrl:
(wdkService: WdkService) => (datasetId: number, filename: string) => {
if (typeof datasetId !== 'number')
(wdkService: WdkService) =>
(datasetId: number | string, filename: string) => {
if (typeof datasetId !== 'number' && typeof datasetId !== 'string')
throw new TypeError(
`Can't build downloadUrl; invalid datasetId given (${datasetId}) [${typeof datasetId}]`
);
Expand Down
3 changes: 2 additions & 1 deletion packages/libs/user-datasets/src/lib/Service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UserDatasetMeta,
NewUserDatasetRequest,
NewUserDataset,
userDatasetDetail,
} from '../Utils/types';

import { array, type, TypeOf, string } from 'io-ts';
Expand Down Expand Up @@ -95,7 +96,7 @@ export class UserDatasetApi extends FetchClientWithCredentials {
createJsonRequest({
path: `${VDI_SERVICE}/${id}`,
method: 'GET',
transformResponse: ioTransformer(userDataset),
transformResponse: ioTransformer(userDatasetDetail),
})
);
};
Expand Down
Loading

0 comments on commit bd3f1bb

Please sign in to comment.