Complete public map filtering

This commit is contained in:
Paulo Gustavo Veiga 2021-02-05 09:46:16 -08:00
parent 680a679a92
commit 87a12c25b1
4 changed files with 39 additions and 30 deletions

View File

@ -22,6 +22,7 @@ export type MapInfo = {
modified: string;
description: string;
isPublic: boolean;
role: 'owner' | 'editor' | 'viewer'
}
export type HistoryChange = {
@ -56,6 +57,7 @@ interface Client {
changeStarred(id: number, starred: boolean): Promise<void>;
fetchLabels(): Promise<Label[]>;
// createLabel(label: Label): Promise<void>;
deleteLabel(id: number): Promise<void>;
registerNewUser(user: NewUser): Promise<void>;

View File

@ -15,23 +15,24 @@ class MockClient implements Client {
creator: string,
modified: string,
description: string,
isPublic: boolean
isPublic: boolean,
role: 'owner' | 'viewer' | 'editor'
): MapInfo {
return { id, title, labels, creator, modified, starred, description, isPublic };
return { id, title, labels, creator, modified, starred, description, isPublic, role };
}
this.maps = [
createMapInfo(1, true, "El Mapa", [], "Paulo", "2008-06-02T00:00:00Z", "", true),
createMapInfo(2, false, "El Mapa2", [], "Paulo2", "2008-06-02T00:00:00Z", "", false),
createMapInfo(3, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(4, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(5, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(6, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(7, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(8, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(9, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(10, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(11, false, "El Mapa3", [1, 2, 3], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(12, false, "El Mapa3", [1, 2, 3], "Paulo3", "2008-06-02T00:00:00Z", "", false)
createMapInfo(1, true, "El Mapa", [], "Paulo", "2008-06-02T00:00:00Z", "", true, 'owner'),
createMapInfo(2, false, "El Mapa2", [], "Paulo2", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(3, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(4, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(5, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(6, false, "/El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(7, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(8, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(9, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(10, false, "El Mapa3", [], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(11, false, "El Mapa3", [1, 2, 3], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor'),
createMapInfo(12, false, "El Mapa3", [1, 2, 3], "Paulo3", "2008-06-02T00:00:00Z", "", false, 'editor')
];
this.labels = [
@ -104,7 +105,8 @@ class MockClient implements Client {
creator: "current user",
labels: [],
modified: "2008-06-02T00:00:00Z",
isPublic: false
isPublic: false,
role: 'owner'
};
this.maps.push(newMap);
return Promise.resolve(newMap.id);

View File

@ -98,11 +98,12 @@ export default class RestClient implements Client {
id: m.id,
starred: Boolean(m.starred),
title: m.title,
labels: [],
labels: m.labels,
creator: m.creator,
modified: m.lastModificationTime,
description: m.description,
isPublic: false
isPublic: m['public'],
role: m.role
}
})
success(maps);
@ -233,8 +234,15 @@ export default class RestClient implements Client {
}
deleteLabel(id: number): Promise<void> {
console.log("Fetching labels from server")
return Promise.resolve();
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
axios.delete(this.baseUrl + `/c/restful/label/${id}`).then(response => {
success();
}).catch(error => {
const errorInfo = this.parseResponseOnError(error.response);
reject(errorInfo);
});
}
return new Promise(handler);
}
}

View File

@ -75,7 +75,7 @@ const headCells: HeadCell[] = [
{ id: 'title', numeric: false, label: 'Name' },
{ id: 'labels', numeric: false },
{ id: 'creator', numeric: false, label: 'Creator', style: { width: '60px' } },
{ id: 'modified', numeric: true, label: 'Modified', style: { width: '30px' } }
{ id: 'modified', numeric: true, label: 'Last Update', style: { width: '30px' } }
];
interface EnhancedTableProps {
@ -156,24 +156,21 @@ const mapsFilter = (filter: Filter, search: string): ((mapInfo: MapInfo) => bool
case 'all':
result = true;
break;
case 'public':
result = mapInfo.isPublic;
break;
case 'starred':
result = mapInfo.starred;
break;
case 'owned':
//@todo: complete ...
result = mapInfo.starred;
result = mapInfo.role == 'owner';
break;
case 'shared':
//@todo: complete ...
result = mapInfo.starred;
result = mapInfo.role != 'owner';
break;
case 'label':
result = !mapInfo.labels || mapInfo.labels.includes((filter as LabelFilter).label.id)
break;
case 'public':
result = mapInfo.isPublic;
break;
default:
result = false;
}