Fix source issue

This commit is contained in:
soupette 2019-12-06 10:44:27 +01:00
parent dc9dd4ccfd
commit 3570ce43e2
14 changed files with 154 additions and 41 deletions

View File

@ -0,0 +1,52 @@
{
"routes": [
{
"method": "GET",
"path": "/my-super-content-types",
"handler": "my-super-content-type.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/my-super-content-types/count",
"handler": "my-super-content-type.count",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/my-super-content-types/:id",
"handler": "my-super-content-type.findOne",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/my-super-content-types",
"handler": "my-super-content-type.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/my-super-content-types/:id",
"handler": "my-super-content-type.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/my-super-content-types/:id",
"handler": "my-super-content-type.delete",
"config": {
"policies": []
}
}
]
}

View File

@ -0,0 +1,8 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/
module.exports = {};

View File

@ -0,0 +1,44 @@
'use strict';
/**
* Lifecycle callbacks for the `my-super-content-type` model.
*/
module.exports = {
// Before saving a value.
// Fired before an `insert` or `update` query.
// beforeSave: async (model, attrs, options) => {},
// After saving a value.
// Fired after an `insert` or `update` query.
// afterSave: async (model, response, options) => {},
// Before fetching a value.
// Fired before a `fetch` operation.
// beforeFetch: async (model, columns, options) => {},
// After fetching a value.
// Fired after a `fetch` operation.
// afterFetch: async (model, response, options) => {},
// Before fetching all values.
// Fired before a `fetchAll` operation.
// beforeFetchAll: async (model, columns, options) => {},
// After fetching all values.
// Fired after a `fetchAll` operation.
// afterFetchAll: async (model, response, options) => {},
// Before creating a value.
// Fired before an `insert` query.
// beforeCreate: async (model, attrs, options) => {},
// After creating a value.
// Fired after an `insert` query.
// afterCreate: async (model, attrs, options) => {},
// Before updating a value.
// Fired before an `update` query.
// beforeUpdate: async (model, attrs, options) => {},
// After updating a value.
// Fired after an `update` query.
// afterUpdate: async (model, attrs, options) => {},
// Before destroying a value.
// Fired before a `delete` query.
// beforeDestroy: async (model, attrs, options) => {},
// After destroying a value.
// Fired after a `delete` query.
// afterDestroy: async (model, attrs, options) => {}
};

View File

@ -0,0 +1,12 @@
{
"connection": "default",
"collectionName": "my_super_content_type",
"info": {
"name": "My super content type ⚠️"
},
"attributes": {
"name": {
"type": "string"
}
}
}

View File

@ -0,0 +1,8 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/services.html#core-services)
* to customize this service
*/
module.exports = {};

View File

@ -24,7 +24,6 @@ function LeftMenuLinkContainer({ plugins, ...rest }) {
section.links
.filter(link => link.isDisplayed !== false)
.map(link => {
link.source = link.source || current;
link.plugin = !isEmpty(plugins[link.plugin])
? link.plugin
: plugins[current].id;
@ -54,7 +53,6 @@ function LeftMenuLinkContainer({ plugins, ...rest }) {
label={link.label}
destination={`/plugins/${link.plugin}/${link.destination ||
link.uid}`}
source={link.source}
/>
))}
</ul>

View File

@ -32,8 +32,7 @@ const Logout = ({ history: { push } }) => {
};
const handleGoToAdministrator = () => {
push({
pathname: '/plugins/content-manager/administrator',
search: '?source=admin',
pathname: '/plugins/content-manager/strapi::administrator',
});
};
const handleLogout = () => {

View File

@ -282,6 +282,8 @@ function ListView({
actions: headerAction,
};
console.log(getSearchParams());
return (
<>
<ListViewProvider

View File

@ -32,7 +32,7 @@ const getInjectedComponents = (
currentEnvironment={currentEnvironment}
getModelName={() => slug}
getContentTypeBuilderBaseUrl={() =>
'/plugins/content-type-builder/models/'
'/plugins/content-type-builder/content-types/'
}
push={push}
{...compo.props}

View File

@ -12,8 +12,8 @@ const generateFiltersFromSearch = search => {
!x.includes('_limit') &&
!x.includes('_page') &&
!x.includes('_sort') &&
!x.includes('source') &&
!x.includes('_q=')
!x.includes('_q=') &&
x !== ''
)
.reduce((acc, curr) => {
const [name, value] = curr.split('=');

View File

@ -7,7 +7,7 @@ describe('Content Manager | utils | search', () => {
describe('generateFiltersFromSearch', () => {
it('should generate an array of filters', () => {
const search =
'?_sort=id:ASC&source=content-manager&bool=true&big_number_ne=1&created_at_lt=2019-08-01T00:00:00Z&date_lte=2019-08-02T00:00:00Z&decimal_number_gt=2&enum_ne=noon&float_number_gte=3';
'?_sort=id:ASC&bool=true&big_number_ne=1&created_at_lt=2019-08-01T00:00:00Z&date_lte=2019-08-02T00:00:00Z&decimal_number_gt=2&enum_ne=noon&float_number_gte=3';
const expected = [
{
name: 'bool',
@ -56,7 +56,6 @@ describe('Content Manager | utils | search', () => {
_limit: 10,
_sort: 'id:ASC',
_page: 2,
source: 'content-manager',
filters: [
{
name: 'bool',
@ -96,7 +95,7 @@ describe('Content Manager | utils | search', () => {
],
};
const expected =
'_limit=10&_sort=id:ASC&_page=2&source=content-manager&bool=true&big_number_ne=1&created_at_lt=2019-08-01T00:00:00Z&date_lte=2019-08-02T00:00:00Z&decimal_number_gt=2&enum_ne=noon&float_number_gte=3';
'_limit=10&_sort=id:ASC&_page=2&bool=true&big_number_ne=1&created_at_lt=2019-08-01T00:00:00Z&date_lte=2019-08-02T00:00:00Z&decimal_number_gt=2&enum_ne=noon&float_number_gte=3';
expect(generateSearchFromFilters(data)).toEqual(expected);
});
});

View File

@ -8,6 +8,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { useGlobalContext } from 'strapi-helper-plugin';
import { Button } from '@buffetjs/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
// Create link from content-type-builder to content-manager
function EditViewButton(props) {
@ -19,26 +20,26 @@ function EditViewButton(props) {
props.push(url);
};
if (props.currentEnvironment === 'development') {
return (
<Button
{...props}
onClick={handleClick}
icon={<i className="fa fa-cog" style={{ fontSize: 13 }}></i>}
label={formatMessage({
id: 'content-manager.containers.Edit.Link.Model',
})}
style={{
paddingLeft: 15,
paddingRight: 15,
outline: 0,
fontWeight: 600,
}}
></Button>
);
if (props.getModelName() === 'strapi::administrator') {
return null;
}
return null;
return (
<Button
{...props}
onClick={handleClick}
icon={<FontAwesomeIcon icon="cog" style={{ fontSize: 13 }} />}
label={formatMessage({
id: 'content-manager.containers.Edit.Link.Model',
})}
style={{
paddingLeft: 15,
paddingRight: 15,
outline: 0,
fontWeight: 600,
}}
></Button>
);
}
EditViewButton.propTypes = {

View File

@ -13,11 +13,11 @@ function EditViewLink(props) {
// Retrieve URL from props
const url = `${props.getContentTypeBuilderBaseUrl()}${props.getModelName()}`;
if (props.currentEnvironment === 'development') {
return <LiLink {...props} url={url} />;
if (props.getModelName() === 'strapi::administrator') {
return null;
}
return null;
return <LiLink {...props} url={url} />;
}
EditViewLink.propTypes = {

View File

@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { LiLink } from 'strapi-helper-plugin';
import EditViewLink from '../EditViewLink';
describe('<EditViewLink />', () => {
@ -19,13 +18,4 @@ describe('<EditViewLink />', () => {
it('should not crash', () => {
shallow(<EditViewLink {...props} />);
});
it('should return null if the currentEnvironment is different than development', () => {
const wrapper = shallow(
<EditViewLink {...props} currentEnvironment="test" />
);
const liLink = wrapper.find(LiLink);
expect(liLink).toHaveLength(0);
});
});