Updated GroupCategory functionality with Groups

• Updated:
- GroupCategory functionality with Groups
This commit is contained in:
mgabdev 2020-09-10 17:12:43 -05:00
parent 217aab9faa
commit 6e17b7c17b
10 changed files with 53 additions and 13 deletions

View File

@ -89,6 +89,8 @@ class Api::V1::GroupsController < Api::BaseController
end end
def group_params def group_params
params.permit(:title, :cover_image, :description, :is_private, :tags, :is_visible, :group_categories_id, :slug) thep = params.permit(:title, :password, :cover_image, :description, :is_private, :tags, :is_visible, :group_category_id, :slug)
thep[:tags] = thep[:tags].split(",") unless thep[:tags].nil?
thep
end end
end end

View File

@ -62,7 +62,7 @@ const create = (options, routerHistory) => (dispatch, getState) => {
formData.append('title', options.title) formData.append('title', options.title)
formData.append('description', options.description) formData.append('description', options.description)
formData.append('tags', options.tags) formData.append('tags', options.tags)
formData.append('group_categories_id', options.category) formData.append('group_category_id', options.category)
formData.append('is_private', options.isPrivate) formData.append('is_private', options.isPrivate)
formData.append('is_visible', options.isVisible) formData.append('is_visible', options.isVisible)
@ -105,7 +105,7 @@ const update = (groupId, options, routerHistory) => (dispatch, getState) => {
formData.append('title', options.title) formData.append('title', options.title)
formData.append('description', options.description) formData.append('description', options.description)
formData.append('tags', options.tags) formData.append('tags', options.tags)
formData.append('group_categories_id', options.category) formData.append('group_category_id', options.category)
formData.append('is_private', options.isPrivate) formData.append('is_private', options.isPrivate)
formData.append('is_visible', options.isVisible) formData.append('is_visible', options.isVisible)
formData.append('slug', options.slug) formData.append('slug', options.slug)

View File

@ -1,11 +1,13 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { NavLink } from 'react-router-dom'
import { defineMessages, injectIntl } from 'react-intl' import { defineMessages, injectIntl } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import moment from 'moment-mini' import moment from 'moment-mini'
import { shortNumberFormat } from '../../utils/numbers' import { shortNumberFormat } from '../../utils/numbers'
import slugify from '../../utils/slugify'
import PanelLayout from './panel_layout' import PanelLayout from './panel_layout'
import Button from '../button' import Button from '../button'
import Divider from '../divider' import Divider from '../divider'
@ -39,6 +41,7 @@ class GroupInfoPanel extends ImmutablePureComponent {
const isPrivate = !!group ? group.get('is_private') : false const isPrivate = !!group ? group.get('is_private') : false
const isVisible = !!group ? group.get('is_visible') : false const isVisible = !!group ? group.get('is_visible') : false
const tags = !!group ? group.get('tags') : [] const tags = !!group ? group.get('tags') : []
const groupCategory = !!group ? group.getIn(['group_category', 'text'], null) : null
const descriptionHTML = !!group ? { __html: group.get('description_html') } : {} const descriptionHTML = !!group ? { __html: group.get('description_html') } : {}
if (noPanel) { if (noPanel) {
@ -143,11 +146,26 @@ class GroupInfoPanel extends ImmutablePureComponent {
</Button> </Button>
</GroupInfoPanelRow> </GroupInfoPanelRow>
{
!!groupCategory &&
<React.Fragment>
<Divider isSmall /> <Divider isSmall />
<GroupInfoPanelRow title={intl.formatMessage(messages.category)} icon='apps'> <GroupInfoPanelRow title={intl.formatMessage(messages.category)} icon='apps'>
<Text>General</Text> <Button
isText
color='brand'
backgroundColor='none'
className={_s.mlAuto}
to={`/groups/browse/categories/${slugify(groupCategory)}`}
>
<Text color='inherit' weight='medium' size='normal' className={_s.underline_onHover}>
{groupCategory}
</Text>
</Button>
</GroupInfoPanelRow> </GroupInfoPanelRow>
</React.Fragment>
}
<Divider isSmall /> <Divider isSmall />

View File

@ -134,7 +134,7 @@ class GroupCreate extends ImmutablePureComponent {
const memberCount = group ? group.get('member_count') : 0 const memberCount = group ? group.get('member_count') : 0
const hasGroupSlug = group ? !!group.get('slug') : false const hasGroupSlug = group ? !!group.get('slug') : false
let categoriesOptions = [] let categoriesOptions = [{'title':'',value:''}]
if (categories) { if (categories) {
for (let i = 0; i < categories.count(); i++) { for (let i = 0; i < categories.count(); i++) {
const c = categories.get(i) const c = categories.get(i)

View File

@ -53,7 +53,7 @@ export default function groupEditorReducer(state = initialState, action) {
map.set('isPrivate', action.group.get('is_private')) map.set('isPrivate', action.group.get('is_private'))
map.set('isVisible', action.group.get('is_visible')) map.set('isVisible', action.group.get('is_visible'))
map.set('id', action.group.get('slug')) map.set('id', action.group.get('slug'))
map.set('category', action.group.get('category')) map.set('category', action.group.getIn(['group_category', 'id'], null))
map.set('isSubmitting', false) map.set('isSubmitting', false)
}) })
case GROUP_EDITOR_TITLE_CHANGE: case GROUP_EDITOR_TITLE_CHANGE:

View File

@ -20,11 +20,13 @@
# is_private :boolean default(FALSE) # is_private :boolean default(FALSE)
# is_visible :boolean default(FALSE) # is_visible :boolean default(FALSE)
# tags :string default([]), is an Array # tags :string default([]), is an Array
# group_categories_id :bigint(8)
# password :string # password :string
# group_category_id :integer
# #
class Group < ApplicationRecord class Group < ApplicationRecord
self.ignored_columns = ["group_categories_id"]
include Paginable include Paginable
include GroupInteractions include GroupInteractions
include GroupCoverImage include GroupCoverImage
@ -45,6 +47,8 @@ class Group < ApplicationRecord
has_many :group_removed_accounts, inverse_of: :group, dependent: :destroy has_many :group_removed_accounts, inverse_of: :group, dependent: :destroy
has_many :removed_accounts, source: :account, through: :group_removed_accounts has_many :removed_accounts, source: :account, through: :group_removed_accounts
belongs_to :group_categories, optional: true, foreign_key: 'group_category_id'
validates :title, presence: true validates :title, presence: true
validates :description, presence: true validates :description, presence: true

View File

@ -0,0 +1,5 @@
class RemoveGroupCategoriesIdFromGroup < ActiveRecord::Migration[5.2]
def change
safety_assured { remove_column :groups, :group_categories_id }
end
end

View File

@ -0,0 +1,6 @@
class AddForeignKeyToGroupForGroupCategory < ActiveRecord::Migration[5.2]
def change
add_column :groups, :group_category_id, :integer
add_foreign_key :groups, :group_categories, on_delete: :nullify, validate: false
end
end

View File

@ -0,0 +1,5 @@
class ValidateAddForeignKeyToGroupForGroupCategory < ActiveRecord::Migration[5.2]
def change
validate_foreign_key :groups, :group_categories
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_09_01_165533) do ActiveRecord::Schema.define(version: 2020_09_08_210104) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements" enable_extension "pg_stat_statements"
@ -391,10 +391,9 @@ ActiveRecord::Schema.define(version: 2020_09_01_165533) do
t.boolean "is_private", default: false t.boolean "is_private", default: false
t.boolean "is_visible", default: false t.boolean "is_visible", default: false
t.string "tags", default: [], array: true t.string "tags", default: [], array: true
t.bigint "group_categories_id"
t.string "password" t.string "password"
t.integer "group_category_id"
t.index ["account_id"], name: "index_groups_on_account_id" t.index ["account_id"], name: "index_groups_on_account_id"
t.index ["group_categories_id"], name: "index_groups_on_group_categories_id"
t.index ["slug"], name: "index_groups_on_slug", unique: true t.index ["slug"], name: "index_groups_on_slug", unique: true
end end
@ -959,6 +958,7 @@ ActiveRecord::Schema.define(version: 2020_09_01_165533) do
add_foreign_key "group_pinned_statuses", "statuses", on_delete: :cascade add_foreign_key "group_pinned_statuses", "statuses", on_delete: :cascade
add_foreign_key "group_removed_accounts", "accounts", on_delete: :cascade add_foreign_key "group_removed_accounts", "accounts", on_delete: :cascade
add_foreign_key "group_removed_accounts", "groups", on_delete: :cascade add_foreign_key "group_removed_accounts", "groups", on_delete: :cascade
add_foreign_key "groups", "group_categories", on_delete: :nullify
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
add_foreign_key "invites", "users", on_delete: :cascade add_foreign_key "invites", "users", on_delete: :cascade