From e7335f56223f871e50063bab2968976b9f3f32f9 Mon Sep 17 00:00:00 2001 From: Riccardo Graziosi <31478034+riggraz@users.noreply.github.com> Date: Sun, 5 Feb 2023 11:55:38 +0100 Subject: [PATCH] Add setting to manage visibility of vote count, vote button and decide root page (#197) --- app/controllers/static_pages_controller.rb | 31 +++++++--- app/javascript/actions/Tenant/updateTenant.ts | 2 - app/javascript/components/Board/BoardP.tsx | 7 +++ app/javascript/components/Board/PostList.tsx | 8 ++- .../components/Board/PostListItem.tsx | 12 +++- app/javascript/components/Board/index.tsx | 13 +++- .../components/LikeButton/LikeButtonP.tsx | 11 +++- .../components/Post/PostBoardSelect.tsx | 3 +- app/javascript/components/Post/PostP.tsx | 19 ++++-- .../components/Post/PostStatusSelect.tsx | 9 +-- app/javascript/components/Post/index.tsx | 4 ++ .../General/GeneralSiteSettingsP.tsx | 61 ++++++++++++++++++- .../components/SiteSettings/General/index.tsx | 3 + .../SiteSettings/Users/UserForm.tsx | 3 +- .../containers/GeneralSiteSettings.tsx | 10 ++- app/javascript/helpers/formUtils.ts | 7 ++- app/javascript/interfaces/IPost.ts | 2 +- app/javascript/interfaces/ITenantSetting.ts | 3 + app/javascript/reducers/postReducer.ts | 4 +- app/javascript/reducers/postsReducer.ts | 4 +- .../stylesheets/components/LikeButton.scss | 2 +- app/policies/tenant_setting_policy.rb | 2 +- app/views/boards/show.html.erb | 4 +- app/views/posts/show.html.erb | 1 + app/views/site_settings/general.html.erb | 4 ++ config/locales/backend/backend.en.yml | 28 ++++++++- config/locales/en.yml | 2 + config/routes.rb | 2 +- ..._vote_and_button_vote_to_tenant_setting.rb | 6 ++ ...748_add_root_board_id_to_tenant_setting.rb | 5 ++ db/schema.rb | 5 +- spec/factories/tenant_settings.rb | 1 - spec/models/tenant_setting_spec.rb | 12 ++++ spec/routing/static_pages_routing_spec.rb | 2 +- spec/system/likes_spec.rb | 2 +- 35 files changed, 246 insertions(+), 48 deletions(-) create mode 100644 db/migrate/20230204145211_add_show_vote_and_button_vote_to_tenant_setting.rb create mode 100644 db/migrate/20230204171748_add_root_board_id_to_tenant_setting.rb diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index bd05e8a0..86e25032 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,14 +1,19 @@ class StaticPagesController < ApplicationController skip_before_action :load_tenant_data, only: [:showcase, :pending_tenant, :blocked_tenant] - def roadmap - @post_statuses = PostStatus - .find_roadmap - .select(:id, :name, :color) + def root + @board = Board.find_by(id: Current.tenant.tenant_setting.root_board_id) - @posts = Post - .find_with_post_status_in(@post_statuses) - .select(:id, :title, :board_id, :post_status_id, :user_id, :created_at) + if @board + render 'boards/show' + else + get_roadmap_data + render 'static_pages/roadmap' + end + end + + def roadmap + get_roadmap_data end def showcase @@ -20,4 +25,16 @@ class StaticPagesController < ApplicationController def blocked_tenant end + + private + + def get_roadmap_data + @post_statuses = PostStatus + .find_roadmap + .select(:id, :name, :color) + + @posts = Post + .find_with_post_status_in(@post_statuses) + .select(:id, :title, :board_id, :post_status_id, :user_id, :created_at) + end end \ No newline at end of file diff --git a/app/javascript/actions/Tenant/updateTenant.ts b/app/javascript/actions/Tenant/updateTenant.ts index 9653c084..79202a1c 100644 --- a/app/javascript/actions/Tenant/updateTenant.ts +++ b/app/javascript/actions/Tenant/updateTenant.ts @@ -76,8 +76,6 @@ export const updateTenant = ({ }, }); - console.log(body) - const res = await fetch(`/tenants/0`, { method: 'PATCH', headers: buildRequestHeaders(authenticityToken), diff --git a/app/javascript/components/Board/BoardP.tsx b/app/javascript/components/Board/BoardP.tsx index ddf26081..31c704f8 100644 --- a/app/javascript/components/Board/BoardP.tsx +++ b/app/javascript/components/Board/BoardP.tsx @@ -7,6 +7,7 @@ import PostList from './PostList'; import Sidebar from '../common/Sidebar'; import IBoard from '../../interfaces/IBoard'; +import ITenantSetting from '../../interfaces/ITenantSetting'; import { PostsState } from '../../reducers/postsReducer'; import { PostStatusesState } from '../../reducers/postStatusesReducer'; @@ -14,6 +15,8 @@ import { PostStatusesState } from '../../reducers/postStatusesReducer'; interface Props { board: IBoard; isLoggedIn: boolean; + isPowerUser: boolean; + tenantSetting: ITenantSetting; authenticityToken: string; posts: PostsState; postStatuses: PostStatusesState; @@ -63,6 +66,8 @@ class BoardP extends React.Component { const { board, isLoggedIn, + isPowerUser, + tenantSetting, authenticityToken, posts, postStatuses, @@ -97,6 +102,8 @@ class BoardP extends React.Component { ; + showLikeCount: boolean; + showLikeButtons: boolean; postStatuses: Array; areLoading: boolean; error: string; @@ -27,6 +29,8 @@ interface Props { const PostList = ({ posts, + showLikeCount, + showLikeButtons, postStatuses, areLoading, error, @@ -53,7 +57,9 @@ const PostList = ({ title={post.title} description={post.description} postStatus={postStatuses.find(postStatus => postStatus.id === post.postStatusId)} - likesCount={post.likesCount} + likeCount={post.likeCount} + showLikeCount={showLikeCount} + showLikeButtons={showLikeButtons} liked={post.liked} commentsCount={post.commentsCount} diff --git a/app/javascript/components/Board/PostListItem.tsx b/app/javascript/components/Board/PostListItem.tsx index 3d5e2597..bcb1d411 100644 --- a/app/javascript/components/Board/PostListItem.tsx +++ b/app/javascript/components/Board/PostListItem.tsx @@ -12,7 +12,9 @@ interface Props { title: string; description?: string; postStatus: IPostStatus; - likesCount: number; + likeCount: number; + showLikeCount: boolean; + showLikeButtons: boolean; liked: number; commentsCount: number; @@ -25,7 +27,9 @@ const PostListItem = ({ title, description, postStatus, - likesCount, + likeCount, + showLikeCount, + showLikeButtons, liked, commentsCount, @@ -35,7 +39,9 @@ const PostListItem = ({
window.location.href = `/posts/${id}`} className="postListItem"> { } render() { - const { board, isLoggedIn, authenticityToken } = this.props; + const { + board, + isLoggedIn, + isPowerUser, + tenantSetting, + authenticityToken, + } = this.props; return ( diff --git a/app/javascript/components/LikeButton/LikeButtonP.tsx b/app/javascript/components/LikeButton/LikeButtonP.tsx index 50dc0707..b5a6a344 100644 --- a/app/javascript/components/LikeButton/LikeButtonP.tsx +++ b/app/javascript/components/LikeButton/LikeButtonP.tsx @@ -2,7 +2,9 @@ import * as React from 'react'; interface Props { postId: number; - likesCount: number; + likeCount: number; + showLikeCount?: boolean; + showLikeButton?: boolean; liked: number; handleLikeSubmit( postId: number, @@ -15,7 +17,9 @@ interface Props { const LikeButtonP = ({ postId, - likesCount, + likeCount, + showLikeCount = true, + showLikeButton = true, liked, handleLikeSubmit, authenticityToken, @@ -29,9 +33,10 @@ const LikeButtonP = ({ else window.location.href = `/users/sign_in`; }} className={`likeButton${liked ? ' liked' : ''}`} + hidden={!showLikeButton} >
- {likesCount} + { showLikeCount && {likeCount} } ); diff --git a/app/javascript/components/Post/PostBoardSelect.tsx b/app/javascript/components/Post/PostBoardSelect.tsx index f4c05009..46854472 100644 --- a/app/javascript/components/Post/PostBoardSelect.tsx +++ b/app/javascript/components/Post/PostBoardSelect.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { getLabel } from '../../helpers/formUtils'; import IBoard from '../../interfaces/IBoard'; @@ -25,7 +26,7 @@ const PostBoardSelect = ({ id="selectPickerBoard" className="selectPicker" > - + {boards.map((board, i) => (