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

studio: show a message or error component when there are no claimants #669 #924

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
2 changes: 1 addition & 1 deletion studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@factly/scooter-core": "^0.0.42",
"@factly/scooter-embed": "^0.0.42",
"@factly/scooter-table": "^0.0.42",
"@factly/scooter-claim":"^0.0.42",
"@factly/scooter-claim": "^0.0.42",
"@monaco-editor/react": "4.4.6",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
Expand Down
8 changes: 5 additions & 3 deletions studio/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import './App.css';
import { createBrowserRouter, RouterProvider , Route } from "react-router-dom";
import { createBrowserRouter, RouterProvider, Route } from 'react-router-dom';
// import 'antd/dist/antd.css';
import 'antd/dist/reset.css';
import BasicLayout from './layouts/basic';
Expand All @@ -13,7 +13,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { getFormats } from '../src/actions/formats';
import deepEqual from 'deep-equal';


function App() {
const [reloadFlag, setReloadFlag] = React.useState(false);
const dispatch = useDispatch();
Expand Down Expand Up @@ -46,7 +45,10 @@ function App() {
React.useEffect(() => {
fetchFormats();
}, [dispatch, selected, reloadFlag]);
const router = createBrowserRouter( extractV6RouteObject(routes , formats ,setReloadFlag ,reloadFlag) , { basename: process.env.PUBLIC_URL});
const router = createBrowserRouter(
extractV6RouteObject(routes, formats, setReloadFlag, reloadFlag),
{ basename: process.env.PUBLIC_URL },
);
return (
<div className="App">
<RouterProvider router={router} />
Expand Down
42 changes: 21 additions & 21 deletions studio/src/components/AdminRoute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ function AdminRoute({ component: Component, ...rest }) {
});

if (loading) {
return () => null
return () => null;
}

if (!loading && !org)
return (
<Result
title="You do not have any organisation."
subTitle="Sorry, you are not authorized to access this page."
extra={
<a href={`${window.REACT_APP_KAVACH_PUBLIC_URL}/settings`}>
<Button type="primary">Back to Kavach</Button>
</a>
}
/>
<Result
title="You do not have any organisation."
subTitle="Sorry, you are not authorized to access this page."
extra={
<a href={`${window.REACT_APP_KAVACH_PUBLIC_URL}/settings`}>
<Button type="primary">Back to Kavach</Button>
</a>
}
/>
);

if (!loading && org.is_admin && isOwner) {
return <Component {...rest} />
return <Component {...rest} />;
}

return (
<Result
status="403"
title="401"
subTitle="Sorry, you are not authorized to access this page."
extra={
<Link to="/">
<Button type="primary">Back Home</Button>
</Link>
}
/>
<Result
status="403"
title="401"
subTitle="Sorry, you are not authorized to access this page."
extra={
<Link to="/">
<Button type="primary">Back Home</Button>
</Link>
}
/>
);
}

Expand Down
74 changes: 37 additions & 37 deletions studio/src/components/FormItems/DescriptionInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import axios from 'axios';
import { RATINGS_API } from '../../constants/ratings';
import { CLAIMANTS_API } from '../../constants/claimants';
import { CLAIMS_API } from '../../constants/claims';
import { ScooterCore as Editor } from "@factly/scooter-core";
import { ScooterCore as Editor } from '@factly/scooter-core';
import { MEDIA_API } from '../../constants/media';
import { useSelector } from 'react-redux';
import { FactCheck } from "@factly/scooter-claim";
import { Image } from "@factly/scooter-image";
import { Embed } from "@factly/scooter-embed";
import { ScooterTable } from "@factly/scooter-table";
import { CodeBlock } from "@factly/scooter-code-block";
import { FactCheck } from '@factly/scooter-claim';
import { Image } from '@factly/scooter-image';
import { Embed } from '@factly/scooter-embed';
import { ScooterTable } from '@factly/scooter-table';
import { CodeBlock } from '@factly/scooter-code-block';

const DescriptionInput = ({
name = 'description',
Expand All @@ -33,52 +33,52 @@ const DescriptionInput = ({
<Form.Item name={name} {...formItemProps}>
{/* <Editor {...inputProps} /> */}
<Editor
extensions={[
FactCheck,
Image,
Embed,
ScooterTable,
CodeBlock,
]}
extensions={[FactCheck, Image, Embed, ScooterTable, CodeBlock]}
menuType="bubble"
heightStrategy="flexible"
rows={rows ? rows : 10}
{...inputProps}
initialValue={initialValue}
uploadEndpoint={window.REACT_APP_COMPANION_URL}
iframelyEndpoint={window.REACT_APP_IFRAMELY_URL}
meta = {{
meta={{
claims: {
1: { id: 1, claim: "Claim 1", fact: "Fact 1" },
2: { id: 2, claim: "Claim 2", fact: "Fact 2" },
3: { id: 3, claim: "Claim 3", fact: "Fact 3" },
4: { id: 4, claim: "Claim 4", fact: "Fact 4" }
}
1: { id: 1, claim: 'Claim 1', fact: 'Fact 1' },
2: { id: 2, claim: 'Claim 2', fact: 'Fact 2' },
3: { id: 3, claim: 'Claim 3', fact: 'Fact 3' },
4: { id: 4, claim: 'Claim 4', fact: 'Fact 4' },
},
}}
claimConfig={{
ratingsFetcher : (page=1) => {
ratingsFetcher: (page = 1) => {
return axios
.get(RATINGS_API, {
params: { page: page, limit: 10 },
}).then((res) => {return res.data})
.get(RATINGS_API, {
params: { page: page, limit: 10 },
})
.then((res) => {
return res.data;
});
},
claimantsFetcher : (page=1) => {
claimantsFetcher: (page = 1) => {
return axios
.get(CLAIMANTS_API, {
params: { page: page, limit: 10 },
}).then((res) => {return res.data})
.get(CLAIMANTS_API, {
params: { page: page, limit: 10 },
})
.then((res) => {
return res.data;
});
},
claimsFetcher : (searchTerm, page=1 , limit=10 , sort = 'desc' ) => {
claimsFetcher: (searchTerm, page = 1, limit = 10, sort = 'desc') => {
const params = new URLSearchParams();
params.append('q', searchTerm);
params.append('page', page);
params.append('limit', limit);
params.append('sort', sort);
return axios
.get( CLAIMS_API , { params: params})
.then((res) => {return res.data})
return axios.get(CLAIMS_API, { params: params }).then((res) => {
return res.data;
});
},
addClaim : (values) => {
addClaim: (values) => {
function convertIdsToNumbers(obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
Expand All @@ -89,11 +89,11 @@ const DescriptionInput = ({
}
return obj;
}
return axios
.post(CLAIMS_API, convertIdsToNumbers(values))
.then((res) => {return res.data})
},
}}
return axios.post(CLAIMS_API, convertIdsToNumbers(values)).then((res) => {
return res.data;
});
},
}}
imagesFetcher={(currentPage) =>
axios
.get(MEDIA_API, {
Expand Down
22 changes: 11 additions & 11 deletions studio/src/components/GlobalNav/MobileSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function MobileSidebar({ superOrg, permission, orgs, loading, applications, serv
children.map((route, childIndex) => {
return resource.includes(route.title.toLowerCase()) ? (
['Events', 'Permissions'].indexOf(route.title) !== -1 &&
route.isAdmin !== superOrg.is_admin ? null : (
route.isAdmin !== superOrg.is_admin ? null : (
<Menu.Item key={route.menuKey}>
<Link to={route.path} onClick={onClose}>
<span>{route.title}</span>
Expand Down Expand Up @@ -165,7 +165,7 @@ function MobileSidebar({ superOrg, permission, orgs, loading, applications, serv
<Avatar
src={
details[selected]?.fav_icon?.url?.[
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
] || degaImg
}
/>
Expand Down Expand Up @@ -209,7 +209,7 @@ function MobileSidebar({ superOrg, permission, orgs, loading, applications, serv
}}
>
<div>
<Link style={{ ...buttonStyle, color: '#1E1E1E' }} to='/settings' onClick={onClose}>
<Link style={{ ...buttonStyle, color: '#1E1E1E' }} to="/settings" onClick={onClose}>
<SettingOutlined />
</Link>
{applications.length > 0 ? (
Expand Down Expand Up @@ -279,14 +279,14 @@ function MobileSidebar({ superOrg, permission, orgs, loading, applications, serv
return menu.title === 'CORE' && !showCoreMenu
? null
: !menu.isService
? !menu.isAdmin
? getSubMenuItems(menu, index, Icon)
: permission.filter((each) => each.resource === 'admin').length > 0
? getSubMenuItems(menu, index, Icon)
: null
: services?.includes(maker(menu.title))
? getSubMenuItems(menu, index, Icon)
: null;
? !menu.isAdmin
? getSubMenuItems(menu, index, Icon)
: permission.filter((each) => each.resource === 'admin').length > 0
? getSubMenuItems(menu, index, Icon)
: null
: services?.includes(maker(menu.title))
? getSubMenuItems(menu, index, Icon)
: null;
})}
</Menu>
</Drawer>
Expand Down
41 changes: 22 additions & 19 deletions studio/src/components/GlobalNav/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function Sidebar({ superOrg, permission, orgs, loading, applications, services,
children.map((route, childIndex) => {
return resource.includes(route.title.toLowerCase()) ? (
['Events', 'Permissions'].indexOf(route.title) !== -1 &&
route.isAdmin !== superOrg.is_admin ? null : (
route.isAdmin !== superOrg.is_admin ? null : (
<Menu.Item key={route.menuKey}>
<Link to={route.path}>
<span>{route.title}</span>
Expand Down Expand Up @@ -180,19 +180,22 @@ function Sidebar({ superOrg, permission, orgs, loading, applications, services,
background: '#F1F1F1',
}}
>
<div className="menu-header" style={{
width: '100%',
display: "flex",
alignItems: "center",
justifyContent: "center",
}}>
<div
className="menu-header"
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
{collapsed ? (
<img
alt="logo"
className="menu-logo"
src={
details[selected]?.fav_icon?.url?.[
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
] || degaImg
}
/>
Expand All @@ -219,7 +222,7 @@ function Sidebar({ superOrg, permission, orgs, loading, applications, services,
<Avatar
src={
details[selected]?.fav_icon?.url?.[
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw'
] || degaImg
}
/>
Expand All @@ -244,14 +247,14 @@ function Sidebar({ superOrg, permission, orgs, loading, applications, services,
return menu.title === 'CORE' && !showCoreMenu
? null
: !menu.isService
? !menu.isAdmin
? getSubMenuItems(menu, index, Icon)
: permission.filter((each) => each.resource === 'admin').length > 0
? getSubMenuItems(menu, index, Icon)
: null
: services?.includes(maker(menu.title))
? getSubMenuItems(menu, index, Icon)
: null;
? !menu.isAdmin
? getSubMenuItems(menu, index, Icon)
: permission.filter((each) => each.resource === 'admin').length > 0
? getSubMenuItems(menu, index, Icon)
: null
: services?.includes(maker(menu.title))
? getSubMenuItems(menu, index, Icon)
: null;
})}
</Menu>
{!collapsed ? (
Expand Down Expand Up @@ -344,12 +347,12 @@ function Sidebar({ superOrg, permission, orgs, loading, applications, services,
background: '#f0f2f5',
}}
>
<Button style={{...buttonStyle, margin: 'auto'}} onClick={() => onCollapse(false)}>
<Button style={{ ...buttonStyle, margin: 'auto' }} onClick={() => onCollapse(false)}>
<MenuUnfoldOutlined />
</Button>
</div>
)}
</Sider >
</Sider>
</>
);
}
Expand Down
4 changes: 2 additions & 2 deletions studio/src/components/List/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EditOutlined, DeleteOutlined, CloseOutlined, CheckOutlined } from '@ant
import { useDispatch, useSelector } from 'react-redux';
import { deletePost } from '../../actions/posts';
import { formatDate, getDifferenceInModifiedTime } from '../../utils/date';
import { Link, useNavigate } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';
import QuickEdit from './QuickEdit';

function PostList({ actions, format, filters, onPagination, data, fetchPosts, query }) {
Expand Down Expand Up @@ -246,7 +246,7 @@ function PostList({ actions, format, filters, onPagination, data, fetchPosts, qu
onQuickEditUpdate={() => setExpandedRowKeys([])}
/>
),
expandIcon: () => { },
expandIcon: () => {},
}}
pagination={{
showTotal: (total, range) => `${range[0]}-${range[1]} of ${total} results`,
Expand Down
9 changes: 4 additions & 5 deletions studio/src/components/PageHeader/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useMemo } from 'react';
import { Link, useLocation , useMatch , useNavigate} from 'react-router-dom';
import { Link, useLocation, useMatch, useNavigate } from 'react-router-dom';
import { LeftOutlined } from '@ant-design/icons';
import { PageHeader as AntPageHeader } from '@ant-design/pro-layout';
import routes from '../../config/routesConfig';
import _ from 'lodash';
import { matchPath } from 'react-router';
import { useSelector } from 'react-redux';


function Pageheader() {
const state = useSelector((state) => state);
const location = useLocation();
Expand Down Expand Up @@ -53,8 +52,8 @@ function Pageheader() {
const generatedReferenceURL = `/${pathSnippets.slice(0, index - 1).join('/')}`
.concat('/:id/')
.concat(pathSnippets.slice(index, index + 2).join('/'));
let match = matchPath({path: generatedReferenceURL}, location.pathname);
let match = matchPath({ path: generatedReferenceURL }, location.pathname);

if (match) {
const route = _.find(routes, { path: generatedReferenceURL });
if (route) {
Expand Down Expand Up @@ -149,4 +148,4 @@ function Pageheader() {
else return null;
}

export default Pageheader;
export default Pageheader;
Loading
Loading