Skip to content

Commit

Permalink
Merge pull request #923 from factly/feature/fix-issues
Browse files Browse the repository at this point in the history
fixed create profiles and formats issues
  • Loading branch information
shreeharsha-factly authored Jun 27, 2024
2 parents 86c191c + 830f0cc commit bf5b5c8
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 13 deletions.
2 changes: 2 additions & 0 deletions server/service/core/action/post/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func createPost(ctx context.Context, post post, status string, r *http.Request)
SpaceID: uint(sID),
DescriptionAMP: post.DescriptionAMP,
MigratedHTML: post.MigratedHTML,
Language: post.Language,
}

if post.MigrationID != nil {
Expand Down Expand Up @@ -554,6 +555,7 @@ func createPost(ctx context.Context, post post, status string, r *http.Request)
"tag_ids": post.TagIDs,
"category_ids": post.CategoryIDs,
"author_ids": post.AuthorIDs,
"language": result.Language,
}

if result.Format.Slug == "fact-check" {
Expand Down
3 changes: 2 additions & 1 deletion server/service/core/action/post/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type post struct {
Meta postgres.Jsonb `json:"meta" swaggertype:"primitive,string"`
HeaderCode string `json:"header_code"`
FooterCode string `json:"footer_code"`
Language string `json:"language"`
MetaFields postgres.Jsonb `json:"meta_fields" swaggertype:"primitive,string"`
DescriptionAMP string `json:"description_amp"`
MigrationID *uint `json:"migration_id"`
MigrationID *uint `json:"migration_id"`
MigratedHTML string `json:"migrated_html"`
CategoryIDs []uint `json:"category_ids"`
TagIDs []uint `json:"tag_ids"`
Expand Down
2 changes: 2 additions & 0 deletions server/service/core/action/post/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func update(w http.ResponseWriter, r *http.Request) {
"meta_fields": post.MetaFields,
"description_amp": post.DescriptionAMP,
"migrated_html": post.MigratedHTML,
"language": post.Language,
}

if post.MigrationID != nil {
Expand Down Expand Up @@ -648,6 +649,7 @@ func update(w http.ResponseWriter, r *http.Request) {
"tag_ids": post.TagIDs,
"category_ids": post.CategoryIDs,
"author_ids": post.AuthorIDs,
"language": result.Language,
}

if result.Format.Slug == "fact-check" {
Expand Down
1 change: 1 addition & 0 deletions server/service/core/model/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Post struct {
Medium *Medium `gorm:"foreignKey:featured_medium_id" json:"medium"`
FormatID uint `gorm:"column:format_id" json:"format_id" sql:"DEFAULT:NULL"`
Format *Format `json:"format"`
Language string `gorm:"column:language" json:"language"`
PublishedDate *time.Time `gorm:"column:published_date" json:"published_date"`
SpaceID uint `gorm:"column:space_id" json:"space_id"`
Schemas postgres.Jsonb `gorm:"column:schemas" json:"schemas" swaggertype:"primitive,string"`
Expand Down
12 changes: 5 additions & 7 deletions studio/src/pages/dashboard/components/Features.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useNavigation from '../../../utils/useNavigation';

function Features() {
const dispatch = useDispatch();
const history = useNavigation();
const navigate = useNavigation();

const superOrg = useSelector(({ admin }) => {
return admin.organisation;
Expand Down Expand Up @@ -95,7 +95,7 @@ function Features() {
actions={[
<Button
onClick={() => {
dispatch(addDefaultRatings()).then(() => history('/ratings'));
dispatch(addDefaultRatings()).then(() => navigate('/ratings'));
}}
>
<PlusOutlined /> CREATE RATINGS
Expand All @@ -113,9 +113,7 @@ function Features() {
actions={[
<Button
onClick={() => {
dispatch(addDefaultFormats(selectedSpace)).then(() =>
history('/advanced/formats'),
);
dispatch(addDefaultFormats(selectedSpace));
}}
>
<PlusOutlined /> CREATE FORMATS
Expand All @@ -132,7 +130,7 @@ function Features() {
actions={[
<Button
onClick={() => {
dispatch(addDefaultPolicies()).then(() => history('/members/policies'));
dispatch(addDefaultPolicies()).then(() => navigate('settings/members/policies'));
}}
>
<PlusOutlined /> CREATE POLICIES
Expand All @@ -151,7 +149,7 @@ function Features() {
actions={[
<Button
onClick={() => {
dispatch(addDefaultEvents()).then(() => history('/admin/events'));
dispatch(addDefaultEvents()).then(() => navigate('/admin/events'));
}}
>
<PlusOutlined /> CREATE EVENTS
Expand Down
22 changes: 17 additions & 5 deletions studio/src/pages/posts/components/PostForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import {
Typography,
Collapse,
Divider,
ConfigProvider,
Select,
} from 'antd';
import Selector from '../../../components/Selector';
import { maker } from '../../../utils/sluger';
import MediaSelector from '../../../components/MediaSelector';
import { useDispatch } from 'react-redux';
import { addTemplate } from '../../../actions/posts';
import { Prompt } from 'react-router-dom';
import {
SettingFilled,
LeftOutlined,
Expand All @@ -43,22 +42,23 @@ import MonacoEditor from '../../../components/MonacoEditor';
import getJsonValue from '../../../utils/getJsonValue';
import { DescriptionInput, SlugInput } from '../../../components/FormItems';
import { formatDate } from '../../../utils/date';
import languages from '../../../utils/languages.json';
import useNavigation from '../../../utils/useNavigation';

function PostForm({ onCreate, data = {}, actions = {}, format, page = false }) {
const history = useNavigation();
const navigate = useNavigation();
const formRef = useRef(null);
const [form] = Form.useForm();
const [status, setStatus] = useState(data.status ? data.status : 'draft');
const dispatch = useDispatch();
const [valueChange, setValueChange] = React.useState(false);
const [metaDrawer, setMetaDrawer] = React.useState(false);
const [drawerVisible, setDrawerVisible] = useState(false);
const [codeDrawer, setCodeDrawerVisible] = useState(false);
const [metaFieldsDrawer, setMetaFieldsDrawerVisible] = useState(false);
const [seoDrawer, setSeoDrawerVisible] = useState(false);
const [isModalVisible, setIsModalVisible] = useState(false);
const [isMobileScreen, setIsMobileScreen] = useState(false);
const [selectedLanguage, setSelectedLanguage] = useState('English');

React.useEffect(() => {
const handleResize = () => {
Expand All @@ -72,6 +72,11 @@ function PostForm({ onCreate, data = {}, actions = {}, format, page = false }) {
handleResize();
return () => window.removeEventListener('resize', handleResize);
}, []);
const languagesList = languages.map((language) => ({ value: language, label: language }));

const handleLanguageChange = (value) => {
setSelectedLanguage(value);
};

const showSchemaModal = () => {
setIsModalVisible(true);
Expand Down Expand Up @@ -171,7 +176,7 @@ function PostForm({ onCreate, data = {}, actions = {}, format, page = false }) {

const createTemplate = () => {
dispatch(addTemplate({ post_id: parseInt(data.id) })).then(() => {
page ? history('/pages') : history('/posts');
page ? navigate('/pages') : navigate('/posts');
});
};
const setReadyFlag = () => {
Expand Down Expand Up @@ -412,6 +417,13 @@ function PostForm({ onCreate, data = {}, actions = {}, format, page = false }) {
<Form.Item name="authors" label="Authors">
<Selector mode="multiple" display={'display_name'} action="Authors" />
</Form.Item>
<Form.Item name="language" label="Language">
<Select
options={languagesList}
defaultValue={selectedLanguage}
onChange={handleLanguageChange}
/>
</Form.Item>
<Form.Item name="featured_medium_id" label="Featured Image">
<MediaSelector />
</Form.Item>
Expand Down
136 changes: 136 additions & 0 deletions studio/src/utils/languages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[
"Afrikaan",
"Albanian",
"Amharic",
"Arabic",
"Armenian",
"Assamese",
"Aymara",
"Azerbaijani",
"Bambara",
"Basque",
"Belarusian",
"Bengali",
"Bhojpuri",
"Bosnian",
"Bulgarian",
"Catalan",
"Cebuano",
"Chinese (Simplified)",
"Chinese (Traditional)",
"Corsican",
"Croatian",
"Czech",
"Danish",
"Dhivehi",
"Dogri",
"Dutch",
"English",
"Esperanto",
"Estonian",
"Ewe",
"Filipino (Tagalog)",
"Finnish",
"French",
"Frisian",
"Galician",
"Georgian",
"German",
"Greek",
"Guarani",
"Gujarati",
"Haitian Creole",
"Hausa",
"Hawaiian",
"Hebrew ",
"Hindi",
"Hmong",
"Hungarian",
"Icelandic",
"Igbo",
"Ilocano",
"Indonesian",
"Irish",
"Italian",
"Japanese",
"Javanese ",
"Kannada",
"Kazakh",
"Khmer",
"Kinyarwanda",
"Konkani",
"Korean",
"Krio",
"Kurdish",
"Kurdish (Sorani)",
"Kyrgyz",
"Lao",
"Latin",
"Latvian",
"Lingala",
"Lithuanian",
"Luganda",
"Luxembourgish",
"Macedonian",
"Maithili",
"Malagasy",
"Malay",
"Malayalam",
"Maltese",
"Maori",
"Marathi",
"Meiteilon (Manipuri)",
"Mizo",
"Mongolian",
"Myanmar (Burmese)",
"Nepali",
"Norwegian",
"Nyanja (Chichewa)",
"Odia (Oriya)",
"Oromo",
"Pashto",
"Persian",
"Polish",
"Portuguese (Portugal, Brazil)",
"Punjabi",
"Quechua",
"Romanian",
"Russian",
"Samoan",
"Sanskrit",
"Scots Gaelic",
"Sepedi",
"Serbian",
"Sesotho",
"Shona",
"Sindhi",
"Sinhala (Sinhalese)",
"Slovak",
"Slovenian",
"Somali",
"Spanish",
"Sundanese",
"Swahili",
"Swedish",
"Tagalog (Filipino)",
"Tajik",
"Tamil",
"Tatar",
"Telugu",
"Thai",
"Tigrinya",
"Tsonga",
"Turkish",
"Turkmen",
"Twi (Akan)",
"Ukrainian",
"Urdu",
"Uyghur",
"Uzbek",
"Vietnamese",
"Welsh",
"Xhosa",
"Yiddish",
"Yoruba",
"Zulu"
]

0 comments on commit bf5b5c8

Please sign in to comment.