Complete starred support for rest

This commit is contained in:
Paulo Gustavo Veiga 2021-02-04 14:34:13 -08:00
parent 0d7cf3e5b1
commit 858050096f
14 changed files with 47 additions and 66 deletions

View File

@ -1,3 +0,0 @@
{
"apiBaseUrl": "http://localhost:8080"
}

View File

@ -17,6 +17,12 @@ export type MapInfo = {
isPublic: boolean;
}
export type HistoryChange = {
id: number;
creator: string;
modified: string;
}
export type BasicMapInfo = {
title: string;
description?: string;
@ -44,8 +50,7 @@ interface Client {
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>;
duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number>;
loadMapInfo(id: number): Promise<BasicMapInfo>;
changeStarred(id: number): Promise<void>;
changeStarred(id: number, starred: boolean): Promise<void>;
}

View File

@ -47,7 +47,7 @@ class MockClient implements Client {
return Promise.resolve(this.labels);
}
changeStarred(id: number): Promise<void> {
changeStarred(id: number, starred: boolean): Promise<void> {
const mapInfo = this.maps.find(m => m.id == id);
if (!mapInfo) {
console.log(`Could not find the map iwth id ${id}`);

View File

@ -56,6 +56,10 @@ export default class RestClient extends MockClient {
return result;
}
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void> {
throw "Method not implemented yet";
}
createMap(model: BasicMapInfo): Promise<number> {
const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => {
axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`,
@ -73,7 +77,6 @@ export default class RestClient extends MockClient {
return new Promise(handler);
}
fetchAllMaps(): Promise<MapInfo[]> {
const handler = (success: (mapsInfo: MapInfo[]) => void, reject: (error: ErrorInfo) => void) => {
axios.get(
@ -142,7 +145,6 @@ export default class RestClient extends MockClient {
return new Promise(handler);
}
resetPassword(email: string): Promise<void> {
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
@ -178,5 +180,21 @@ export default class RestClient extends MockClient {
}
return new Promise(handler);
}
changeStarred(id: number, starred: boolean): Promise<void> {
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`,
starred,
{ headers: { 'Content-Type': 'text/plain' } }
).then(() => {
success();
}).catch(error => {
const response = error.response;
const errorInfo = this.parseResponseOnError(response);
reject(errorInfo);
});
}
return new Promise(handler);
}
}

View File

@ -8,7 +8,7 @@ import { FormControl } from '@material-ui/core';
import Client, { BasicMapInfo, ErrorInfo } from '../../../../client';
import { activeInstance } from '../../../../reducers/serviceSlice';
import Input from '../../../form/input';
import BaseDialog from '../action-dialog';
import BaseDialog from '../base-dialog';
export type CreateModel = {
title: string;

View File

@ -6,7 +6,7 @@ import { useSelector } from "react-redux";
import Client from "../../../../client";
import { activeInstance } from '../../../../reducers/serviceSlice';
import { DialogProps, fetchMapById, handleOnMutationSuccess } from "..";
import BaseDialog from "../action-dialog";
import BaseDialog from "../base-dialog";
const DeleteDialog = (props: DialogProps) => {

View File

@ -1,14 +1,14 @@
import React, { useEffect } from "react";
import { useIntl } from "react-intl";
import { useMutation, useQueryClient } from "react-query";
import { useSelector } from "react-redux";
import { FormControl } from "@material-ui/core";
import { useSelector } from "react-redux";
import Client, { BasicMapInfo, ErrorInfo } from "../../../../client";
import { activeInstance } from '../../../../reducers/serviceSlice';
import Input from "../../../form/input";
import { DialogProps, fetchMapById, handleOnMutationSuccess } from "..";
import BaseDialog from "../action-dialog";
import { DialogProps, fetchMapById } from "..";
import BaseDialog from "../base-dialog";
export type DuplicateModel = {
id: number;

View File

@ -1,17 +1,15 @@
import React from 'react';
import RenameDialog from './rename';
import DeleteDialog from './delete';
import DeleteDialog from './delete-dialog';
import { ActionType } from '../action-chooser';
import { ErrorInfo, MapInfo } from '../../../client';
import Client from '../../../client';
import { useSelector } from 'react-redux';
import { useSelector } from "react-redux";
import { QueryClient, useQuery } from 'react-query';
import { activeInstance } from '../../../reducers/serviceSlice';
import DuplicateDialog from './duplicate';
import DuplicateDialog from './duplicate-dialog';
import { useHistory } from 'react-router-dom';
import InfoDialog from './info';
import CreateDialog from './create';
import CreateDialog from './create-dialog';
export type BasicMapInfo = {
name: string;
@ -35,10 +33,10 @@ const ActionDispatcher = (props: ActionDialogProps) => {
switch (action) {
case 'open':
history.push(`/c/maps/${mapId}/edit`);
window.location.href = `/c/maps/${mapId}/edit`;
break;
case 'print':
history.push(`/c/maps/${mapId}/print`);
window.open(`/c/maps/${mapId}/print`,'print');
break;
}
@ -48,7 +46,6 @@ const ActionDispatcher = (props: ActionDialogProps) => {
<DeleteDialog open={action === 'delete'} onClose={handleOnClose} mapId={mapId} />
<RenameDialog open={action === 'rename'} onClose={handleOnClose} mapId={mapId} />
<DuplicateDialog open={action === 'duplicate'} onClose={handleOnClose} mapId={mapId} />
<InfoDialog open={action === 'info'} onClose={handleOnClose} mapId={mapId} />
</span >
);
}

View File

@ -1,37 +0,0 @@
import React from "react";
import { useQueryClient } from "react-query";
import { useSelector } from "react-redux";
import Client from "../../../../client";
import { activeInstance } from '../../../../reducers/serviceSlice';
import { DialogProps, fetchMapById } from "..";
import BaseDialog from "../action-dialog";
import { useIntl } from "react-intl";
const InfoDialog = (props: DialogProps) => {
const service: Client = useSelector(activeInstance);
const queryClient = useQueryClient();
const intl = useIntl();
const mapId = props.mapId;
const handleOnClose = (): void => {
props.onClose();
};
const { map } = fetchMapById(mapId);
return (
<div>
<BaseDialog
open={props.open} onClose={handleOnClose}
title={intl.formatMessage({ id: "action.info-title", defaultMessage: "Info" })}>
<iframe src="http://www.clarin.com" style={{ width: '100%', height: '400px' }} />
</BaseDialog>
</div>
);
}
export default InfoDialog;

View File

@ -7,7 +7,7 @@ import { activeInstance } from '../../../../reducers/serviceSlice';
import { DialogProps, fetchMapById, handleOnMutationSuccess } from "..";
import Input from "../../../form/input";
import { FormControl } from "@material-ui/core";
import BaseDialog from "../action-dialog";
import BaseDialog from "../base-dialog";
export type RenameModel = {
id: number;

View File

@ -317,7 +317,7 @@ const HelpToobarButton = () => {
}}>
<MenuItem onClick={handleClose}>
<Link color="textSecondary" href="https://www.wisemapping.com/termsofuse.html">
<Link color="textSecondary" href="https://www.wisemapping.com/termsofuse.html" target="help">
<ListItemIcon>
<PolicyOutlined fontSize="small" />
</ListItemIcon>
@ -335,7 +335,7 @@ const HelpToobarButton = () => {
</MenuItem>
<MenuItem onClick={handleClose}>
<Link color="textSecondary" href="feedback@wisemapping.com">
<Link color="textSecondary" href="mailto:feedback@wisemapping.com">
<ListItemIcon>
<FeedbackOutlined fontSize="small" />
</ListItemIcon>
@ -344,7 +344,7 @@ const HelpToobarButton = () => {
</MenuItem>
<MenuItem onClick={handleClose}>
<Link color="textSecondary" href="https://www.wisemapping.com/aboutus.html">
<Link color="textSecondary" href="https://www.wisemapping.com/aboutus.html" target="help">
<ListItemIcon>
<EmojiPeopleOutlined fontSize="small" />
</ListItemIcon>

View File

@ -276,7 +276,8 @@ export const MapsList = (props: MapsListProps) => {
const queryClient = useQueryClient();
const starredMultation = useMutation<void, ErrorInfo, number>((id: number) => {
return client.changeStarred(id);
const map = mapsInfo.find(m => m.id == id);
return client.changeStarred(id, !Boolean(map?.starred));
},
{
onSuccess: () => {
@ -395,7 +396,7 @@ export const MapsList = (props: MapsListProps) => {
{isLoading ? (
<TableRow><TableCell colSpan={6}>Loading ...</TableCell></TableRow>) :
(mapsInfo.length == 0 ?
(<TableRow><TableCell colSpan={6} style={{textAlign:'center'}}><FormattedMessage id="maps.emptyresult" defaultMessage="No matching record found with the current filter criteria." /></TableCell></TableRow>) :
(<TableRow><TableCell colSpan={6} style={{ textAlign: 'center' }}><FormattedMessage id="maps.emptyresult" defaultMessage="No matching record found with the current filter criteria." /></TableCell></TableRow>) :
stableSort(mapsInfo, getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row: MapInfo) => {
@ -434,7 +435,7 @@ export const MapsList = (props: MapsListProps) => {
<TableCell className={classes.bodyCell}>
<Tooltip title="Open for edition" placement="bottom-start">
<Link href={`/c/maps/${row.id}/edit`} color="textPrimary" underline="always" onClick={(e)=>e.stopPropagation()}>
<Link href={`/c/maps/${row.id}/edit`} color="textPrimary" underline="always" onClick={(e) => e.stopPropagation()}>
{row.title}
</Link>
</Tooltip>