Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Admin control panel (MVP) #657

Merged
merged 117 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
431c51a
1
daniloflek Oct 6, 2021
fc7911a
Merge branch 'develop' of https://github.com/ita-social-projects/doka…
daniloflek Oct 7, 2021
d91b8a6
add materialsList component
pavlyukdm Oct 8, 2021
faba274
implemented a adminlabSlice and asyncThunk getMatirealsAction
daniloflek Oct 8, 2021
6dca7bc
implemented a adminlabSlice and asyncThunk getMatirealsAction
daniloflek Oct 8, 2021
614eacc
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 8, 2021
6be5550
hotfix
daniloflek Oct 8, 2021
8ce4863
connect materialsList to redux store
pavlyukdm Oct 8, 2021
55a59a6
remove unused components from materialsView
pavlyukdm Oct 8, 2021
8d4fc50
add modifideViewsCounter to view
pavlyukdm Oct 8, 2021
4f82d31
added sort and filters in reducer
daniloflek Oct 9, 2021
081aed1
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 9, 2021
85cef2b
refactor MaterialsList
pavlyukdm Oct 9, 2021
fc2eb1d
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 9, 2021
cbe937f
add params to getMatirealsAction
pavlyukdm Oct 9, 2021
0fb3623
create tableHeadContent for tableHeadRows map
pavlyukdm Oct 9, 2021
23fbc57
change components structure
pavlyukdm Oct 9, 2021
7cedd8d
1
daniloflek Oct 10, 2021
b598ebe
Filter prototype add setFilter action added
daniloflek Oct 10, 2021
7d87280
add basic styles
pavlyukdm Oct 10, 2021
214ce52
add sortKeys to tableHeadContent
pavlyukdm Oct 10, 2021
120b821
fix typo
pavlyukdm Oct 10, 2021
374010b
implement sorting for columns
pavlyukdm Oct 11, 2021
8f62d05
fix sorting
pavlyukdm Oct 11, 2021
0a7a699
implement sorting by modified_at
pavlyukdm Oct 11, 2021
efad555
add types
pavlyukdm Oct 11, 2021
8605d28
add icons to sorted column
pavlyukdm Oct 11, 2021
5f69be6
Filters 2.0, new component added MatirealsFilter
daniloflek Oct 11, 2021
d7a5fcc
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 11, 2021
fa5cf34
filter fix
daniloflek Oct 12, 2021
415beb8
refactor sorting
pavlyukdm Oct 12, 2021
cf5dfd4
add styling
pavlyukdm Oct 12, 2021
3fe6da1
add pagination skeleton
pavlyukdm Oct 12, 2021
6602889
Added page value to reducer also added 3 action for seting page value…
daniloflek Oct 12, 2021
fc3f4dd
Added page value to reducer also added 3 action for seting page value…
daniloflek Oct 13, 2021
105f517
replace custom label to TableSortLabel
pavlyukdm Oct 19, 2021
5ab8f53
rename sorting handler
pavlyukdm Oct 19, 2021
c70f93b
remove unused file
pavlyukdm Oct 19, 2021
6c66889
add ability of different direction default sorting
pavlyukdm Oct 19, 2021
f93ef5e
add types
pavlyukdm Oct 19, 2021
965b054
add tableBody wrapper
pavlyukdm Oct 19, 2021
48ff5f5
add tableRow wrapper to thead
pavlyukdm Oct 19, 2021
bc4b3d4
add styling
pavlyukdm Oct 19, 2021
55b266c
filter styles added
daniloflek Oct 19, 2021
f12dd31
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 19, 2021
366f87a
change default sorting order
pavlyukdm Oct 20, 2021
672670e
improve sorting logic
pavlyukdm Oct 20, 2021
3109fe4
implement basic ui pagination
pavlyukdm Oct 21, 2021
e08671d
add styling to pagination
pavlyukdm Oct 21, 2021
200b880
fix incorrect pagination
pavlyukdm Oct 21, 2021
496c388
added status and totalPage number to state
daniloflek Oct 21, 2021
8292a66
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Oct 21, 2021
c05ed64
set real total pages count
pavlyukdm Oct 21, 2021
c781022
change NEW_LOAD_POSTS_LIMIT to 12 according to US
pavlyukdm Oct 21, 2021
452f546
implement show pagination only if pages count more than 1
pavlyukdm Oct 21, 2021
8fa7ebe
Added functional for pagination and table size changing
daniloflek Oct 21, 2021
2631ce7
Added functional for pagination and table size changing
daniloflek Oct 21, 2021
3c468d7
add icon to post type
pavlyukdm Oct 22, 2021
7a6d6e5
fix pagination and styling
pavlyukdm Oct 22, 2021
57f7b72
fix temp scroll
pavlyukdm Oct 22, 2021
97cc0b0
fix typos
pavlyukdm Oct 22, 2021
2676a5e
useDispach changed to useActions
daniloflek Oct 22, 2021
4d6d1a2
text field for searching by aftor and title added
daniloflek Oct 22, 2021
a29b017
add filter styling
pavlyukdm Oct 22, 2021
271438e
add filter styling
pavlyukdm Oct 22, 2021
eae4288
fix typos
pavlyukdm Oct 22, 2021
4e4dfad
add filter styling
pavlyukdm Oct 23, 2021
9024a81
aaaaaa
daniloflek Oct 25, 2021
767ef16
status filter added
daniloflek Oct 25, 2021
dac51e7
rename adminLab step 1
pavlyukdm Oct 25, 2021
1e324e6
rename adminLab step 2
pavlyukdm Oct 25, 2021
8b10879
fix incorrect draft checkbox work
pavlyukdm Oct 25, 2021
e66503b
add materials files back
pavlyukdm Oct 26, 2021
41c3a97
add edit button
pavlyukdm Oct 27, 2021
c69610a
clean up console.log
pavlyukdm Oct 27, 2021
1a2cfe5
add icon to edit button
pavlyukdm Oct 28, 2021
c550541
add action buttons skeleton
pavlyukdm Oct 29, 2021
1dfa489
refactor posttype styling
pavlyukdm Oct 29, 2021
74c0613
add statuses translation
pavlyukdm Nov 1, 2021
2f18fde
rename property in IContent
pavlyukdm Nov 1, 2021
fbcb7f8
refactor tablehead
pavlyukdm Nov 2, 2021
86866df
add styling to sortable labels
pavlyukdm Nov 2, 2021
d142979
add sorting by date
pavlyukdm Nov 2, 2021
5cbad90
add sorting by status
pavlyukdm Nov 2, 2021
89f1d10
add hover effects
pavlyukdm Nov 2, 2021
2138d8c
change table structure
pavlyukdm Nov 2, 2021
65d46e5
fix views counters display
pavlyukdm Nov 2, 2021
ae1a634
api for fake views added
daniloflek Nov 2, 2021
58993b0
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Nov 2, 2021
5df21ac
atchive proto added
daniloflek Nov 2, 2021
f4e7093
separate materials view by roles
pavlyukdm Nov 3, 2021
c861937
Merge remote-tracking branch 'origin/admin_table' into admin_table
pavlyukdm Nov 3, 2021
6f4044a
refactor file structure
pavlyukdm Nov 3, 2021
b1a9076
implement MVP action button group
pavlyukdm Nov 3, 2021
ea09ea5
Merge branch 'develop' into admin_table2
pavlyukdm Nov 4, 2021
021fef8
implement action button group
pavlyukdm Nov 4, 2021
784d819
add styling
pavlyukdm Nov 4, 2021
b37b82f
refactor action button group
pavlyukdm Nov 4, 2021
140a86c
remove unused vars
pavlyukdm Nov 4, 2021
2e0ae73
ts types normalisation
daniloflek Nov 4, 2021
3a62d55
removeng dependency
daniloflek Nov 4, 2021
6ee6e89
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Nov 4, 2021
17a4458
fix minor issues
pavlyukdm Nov 5, 2021
e54f8fd
fix import issues
pavlyukdm Nov 5, 2021
0ae9495
code smell
daniloflek Nov 5, 2021
7791f76
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Nov 5, 2021
f2d60df
code smell fix
daniloflek Nov 5, 2021
9fd5eaf
AdminFilter.ts condition fix
daniloflek Nov 5, 2021
fbcf97c
fix style vars
pavlyukdm Nov 5, 2021
b27e6e3
add localization
pavlyukdm Nov 5, 2021
ea53a67
asyncActions.ts types refactoring
daniloflek Nov 5, 2021
503ecfe
Merge branch 'admin_table' of https://github.com/ita-social-projects/…
daniloflek Nov 5, 2021
bc56926
translation for filters added
daniloflek Nov 5, 2021
5ef3ee2
console.logs removed
daniloflek Nov 6, 2021
edc63a5
remove console.log
pavlyukdm Nov 8, 2021
f81394d
filter localisation added
daniloflek Nov 8, 2021
a00bb13
options translation added
daniloflek Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/locales/uk/parts/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const admin = {
id: 'Id',
title: 'Заголовок',
status: 'Статус',
dateOfStatusChange: 'Дата зміни статусу',
direction: 'Тема',
author: 'Автор',
views: 'Перегляди',
realViews: 'Реальні перегляди',
viewsFull: 'Кількість переглядів, що відображається',
realViewsFull: 'Реальна кількість переглядів',
actions: 'Дії',
DRAFT: 'Чернетка',
MODERATION_FIRST_SIGN: 'Не переглянутий',
MODERATION_SECOND_SIGN: 'На модерації',
PUBLISHED: 'Опублікований',
ARCHIVED: 'Архівований',
edit: 'Редагувати',
archive: 'Надіслати в архів',
remove: 'Видалити',
publish: 'Опублікувати',
schedulePublish: 'Запланувати публікацію',
changePublicationDate: 'Змінити дату публікації',
changeViewsCount: 'Змінити кількість переглядів',
returnToAuthor: 'Надіслати автору на редагування',
statuses: 'Статуси',
directions: 'Теми',
types: 'Типи',
};
2 changes: 2 additions & 0 deletions src/locales/uk/ukrainian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { materials } from './parts/materials';
import { date } from './parts/date';
import { loginRegistration } from './parts/loginRegistration';
import { passwordForms } from './parts/passwordForms';
import { admin } from './parts/admin';

export const ukrainian = {
common,
Expand All @@ -16,4 +17,5 @@ export const ukrainian = {
date,
loginRegistration,
passwordForms,
admin,
};
90 changes: 90 additions & 0 deletions src/models/adminLab/asyncActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable */
import { createAsyncThunk } from '@reduxjs/toolkit';

import {
getUniquePostViewsCounter,
archivePost,
getPosts,
} from '../../old/lib/utilities/API/api';
import { mapFetchedPosts } from '../materials/asyncActions';
import { IAdminPost, IAdminLabData } from './types';
import { RootStateType } from '../rootReducer';

interface IFilterOption {
id: number;
}

const setFilter = (
selected: number[] | undefined,
all: IFilterOption[],
): number[] => {
return selected?.length ? selected : all.map(({ id }) => id);
};

export const getMaterialsAction = createAsyncThunk(
'adminLab/getAllAdminsMaterialsAction',
async (
_,
{ rejectWithValue, getState },
): Promise<IAdminLabData | unknown> => {
try {
const {
adminLab: {
meta: { sort, filters, page, size, textFields },
},
properties: { directions, postTypes, origins, statuses },
} = getState() as RootStateType;
const {
data: { content, totalPages },
} = await getPosts('all-posts', {
params: {
page,
size,
types: setFilter(filters.types, postTypes),
directions: setFilter(filters.directions, directions),
origins: setFilter(filters.origins, origins),
statuses: setFilter(filters.statuses, statuses),
sort: [`${sort.sortBy},${sort.order}`],
...textFields,
},
});
const { ids: postIds } = mapFetchedPosts(content);
const postWithViews: IAdminPost[] = await Promise.all(
content.map(async (post) => {
const { data } = await getUniquePostViewsCounter(post.id);
return {
...post,
uniqueViewsCounter: data,
modifiedViewsCounter: data + 4,
};
}),
);
const posts = {};
postWithViews.forEach((post) => {
if (posts && post.id) {
posts[post.id] = post;
}
});
return {
totalPages,
posts,
postIds,
};
} catch (error) {
return rejectWithValue(error.response?.data);
}
},
);

export const archiveAdminPost = createAsyncThunk(
'adminLab/archivePost',
async (options: { id: number }, { rejectWithValue, getState }) => {
try {
const { id } = options;
await archivePost(id);
return id;
} catch (error) {
return rejectWithValue(error.response?.data);
}
},
);
13 changes: 13 additions & 0 deletions src/models/adminLab/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable import/no-cycle */

export {
adminLabReducer,
setStateToInit,
setSort,
setFilter,
setPage,
setFiltersToInit,
setField,
} from './reducers';
export { getMaterialsAction, archiveAdminPost } from './asyncActions';
export { selectAdminLab, selectMeta } from './selectors';
107 changes: 107 additions & 0 deletions src/models/adminLab/reducers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* eslint-disable */
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { getAsyncActionsReducer } from '../helpers/asyncActions';

import {
IAdminLab,
IAdminPost,
SortBy,
Order,
ISort,
IFilter,
IField,
} from './types';
import { LoadingStatusEnum } from '../../old/lib/types';
import { getMaterialsAction, archiveAdminPost } from './asyncActions';

// так можга тягнути перегляди getUniquePostViewsCounter

const initialState: IAdminLab = {
data: {
totalPages: 0,
postIds: [],
posts: {},
},
meta: {
size: 12,
sort: {
order: Order.desc,
sortBy: SortBy.post_id,
},
filters: {
directions: [],
types: [],
statuses: [],
},
page: 0,
textFields: {
author: '',
title: '',
},
},
error: '',
loading: LoadingStatusEnum.idle,
};

const adminLabSlice = createSlice({
name: 'adminLab',
initialState,
reducers: {
setStateToInit: (state) => {
state.data = initialState.data;
state.meta = initialState.meta;
},
setSize: (state, action: PayloadAction<{ size: number }>) => {
state.meta.size = action.payload.size;
},
setField: (state, action: PayloadAction<IField>) => {
const { text, field } = action.payload;
state.meta.textFields[field] = text;
},
setFiltersToInit: (state) => {
state.meta.filters = initialState.meta.filters;
state.meta.textFields = initialState.meta.textFields;
},
setSort: (state, action: PayloadAction<ISort>) => {
state.meta.sort = action.payload;
},
setFilter: (state, action: PayloadAction<IFilter>) => {
const { filter, options } = action.payload;
state.meta.filters[filter] = options;
},
setPage: (state, action: PayloadAction<{ page: number }>) => {
state.meta.page = action.payload.page;
},
editPost: (state, action: PayloadAction<IAdminPost>) => {
const editedPostID = action.payload.id;
state.data.posts = {
...state.data.posts,
[editedPostID]: action.payload,
};
},
},
extraReducers: {
...getAsyncActionsReducer(getMaterialsAction as any),
...getAsyncActionsReducer(archiveAdminPost as any),
[archiveAdminPost.fulfilled.type]: (
state,
action: PayloadAction<string>,
) => {
state.data.posts[action.payload] = {
...state.data.posts[action.payload],
status: 'ARCHIVED',
};
},
},
});

export const {
setStateToInit,
editPost,
setSort,
setFilter,
setPage,
setFiltersToInit,
setField,
} = adminLabSlice.actions;
export const adminLabReducer = adminLabSlice.reducer;
10 changes: 10 additions & 0 deletions src/models/adminLab/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RootStateType } from '../rootReducer';
import { IAdminLabData, IAdminLabMeta } from './types';

export const selectAdminLab = (state: RootStateType): IAdminLabData => {
return state.adminLab.data;
};

export const selectMeta = (state: RootStateType): IAdminLabMeta => {
return state.adminLab.meta;
};
77 changes: 77 additions & 0 deletions src/models/adminLab/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { IPost, LoadingStatusEnum, QueryTypeEnum } from '../../old/lib/types';

export interface IAdminPost extends IPost {
modifiedViewsCounter?: number;
status: string;
}

export enum FieldEnum {
AUTHOR = 'author',
TITLE = 'title',
}

export interface IAdminLab {
data: IAdminLabData;
meta: IAdminLabMeta;
loading: LoadingStatusEnum;
error: string | null;
}

export interface IAdminLabMeta {
sort: ISort;
filters: {
[key in QueryTypeEnum]?: number[];
};
page: number;
size: number;
textFields: {
[key in FieldEnum]: string;
};
}

export interface IFilter {
filter: string;
options: number[];
}

export interface IField {
field: string;
text: string;
}

export interface ISort {
order: keyof typeof Order;
sortBy: keyof typeof SortBy;
}

export interface IAdminLabData {
totalPages: number;
postIds: number[];
posts: IPostsOBJ;
}

export interface IPostsOBJ {
[id: string]: IAdminPost;
}

export interface IMyKnownError {
errorMessage: string;
}

export enum SortBy {
published_at = 'published_at',
post_id = 'post_id',
type_id = 'title',
title = 'title',
content = 'content',
status = 'status',
important = 'important',
created_at = 'created_at',
modified_at = 'modified_at',
author = 'author.firstName',
}

export enum Order {
desc = 'desc',
asc = 'asc',
}
11 changes: 3 additions & 8 deletions src/models/materials/asyncActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ export const fetchMaterials = createAsyncThunk(
'materials/fetchMaterials',
async (options: IFetchMaterialsOptions, { getState, rejectWithValue }) => {
try {
const {
filters,
page,
appendPosts,
url = 'all-posts',
statuses = 'PUBLISHED',
} = options;
const { filters, page, appendPosts, url = 'all-posts' } = options;

const response = await getPosts(url, {
params: {
page: page,
Expand All @@ -33,7 +28,7 @@ export const fetchMaterials = createAsyncThunk(
directions: filters.directions,
origins: filters.origins,
sort: ['published_at,desc'],
statuses,
statuses: [3],
},
});

Expand Down
1 change: 1 addition & 0 deletions src/models/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export {
selectPostTags,
selectPostTypes,
selectRegions,
selectPostStatuses,
} from './selectors';
Loading