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; modified: string;
description: string; description: string;
isPublic: boolean; isPublic: boolean;
role: 'owner' | 'editor' | 'viewer'
} }
export type HistoryChange = { export type HistoryChange = {
@ -47,7 +48,7 @@ export type ErrorInfo = {
interface Client { interface Client {
createMap(map: BasicMapInfo): Promise<number>; createMap(map: BasicMapInfo): Promise<number>;
deleteMap(id: number): Promise<void>; deleteMap(id: number): Promise<void>;
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>; renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>;
fetchAllMaps(): Promise<MapInfo[]>; fetchAllMaps(): Promise<MapInfo[]>;
@ -56,7 +57,8 @@ interface Client {
changeStarred(id: number, starred: boolean): Promise<void>; changeStarred(id: number, starred: boolean): Promise<void>;
fetchLabels(): Promise<Label[]>; fetchLabels(): Promise<Label[]>;
deleteLabel(id: number): Promise<void>; // createLabel(label: Label): Promise<void>;
deleteLabel(id: number): Promise<void>;
registerNewUser(user: NewUser): Promise<void>; registerNewUser(user: NewUser): Promise<void>;
resetPassword(email: string): Promise<void>; resetPassword(email: string): Promise<void>;

View File

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

View File

@ -98,11 +98,12 @@ export default class RestClient implements Client {
id: m.id, id: m.id,
starred: Boolean(m.starred), starred: Boolean(m.starred),
title: m.title, title: m.title,
labels: [], labels: m.labels,
creator: m.creator, creator: m.creator,
modified: m.lastModificationTime, modified: m.lastModificationTime,
description: m.description, description: m.description,
isPublic: false isPublic: m['public'],
role: m.role
} }
}) })
success(maps); success(maps);
@ -233,8 +234,15 @@ export default class RestClient implements Client {
} }
deleteLabel(id: number): Promise<void> { deleteLabel(id: number): Promise<void> {
console.log("Fetching labels from server") const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
return Promise.resolve(); 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: 'title', numeric: false, label: 'Name' },
{ id: 'labels', numeric: false }, { id: 'labels', numeric: false },
{ id: 'creator', numeric: false, label: 'Creator', style: { width: '60px' } }, { 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 { interface EnhancedTableProps {
@ -156,24 +156,21 @@ const mapsFilter = (filter: Filter, search: string): ((mapInfo: MapInfo) => bool
case 'all': case 'all':
result = true; result = true;
break; break;
case 'public':
result = mapInfo.isPublic;
break;
case 'starred': case 'starred':
result = mapInfo.starred; result = mapInfo.starred;
break; break;
case 'owned': case 'owned':
//@todo: complete ... result = mapInfo.role == 'owner';
result = mapInfo.starred;
break; break;
case 'shared': case 'shared':
//@todo: complete ... result = mapInfo.role != 'owner';
result = mapInfo.starred;
break; break;
case 'label': case 'label':
result = !mapInfo.labels || mapInfo.labels.includes((filter as LabelFilter).label.id) result = !mapInfo.labels || mapInfo.labels.includes((filter as LabelFilter).label.id)
break; break;
case 'public':
result = mapInfo.isPublic;
break;
default: default:
result = false; result = false;
} }