Skip to content

Commit

Permalink
Cleanup plugin, Move config to pluginOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Freyb committed Jun 5, 2023
1 parent 1a60a5b commit 7c048ae
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 213 deletions.
27 changes: 16 additions & 11 deletions admin/src/components/SelectorField/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
import { get } from 'lodash';
import {
Field,
FieldLabel,
FieldError,
FieldHint,
Select,
Option,
Loader,
Stack,
Typography,
} from '@strapi/design-system';
import { useIntl } from 'react-intl';
import useConfig from '../../hooks/useConfig';
import pluginId from '../../pluginId';

const SelectorField = ({
value,
Expand All @@ -26,12 +28,13 @@ const SelectorField = ({
disabled,
error,
}) => {
// const { options = {} } = attribute;
const { config, isLoading: configIsLoading } = useConfig();

const { formatMessage } = useIntl();

console.log('Tags', config);
const { allLayoutData } = useCMEditViewDataManager();
const pluginOptions = get(
allLayoutData,
`contentType.pluginOptions.${pluginId}`,
);
const tagsEnabled = !!pluginOptions;

return (
<Field
Expand All @@ -44,15 +47,17 @@ const SelectorField = ({
<Stack spacing={1}>
<FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>

{configIsLoading ? (
<Loader small>Loading content...</Loader>
{!tagsEnabled ? (
<Typography fontWeight="bold">
Invalid scheme configuration
</Typography>
) : (
<Select
placeholder={placeholder && formatMessage(placeholder)}
aria-label={formatMessage(intlLabel)}
aria-disabled={disabled}
disabled={disabled}
value={value || config.defaultTag}
value={value || pluginOptions.defaultTag}
onChange={(newValue) => {
onChange({
target: {
Expand All @@ -63,7 +68,7 @@ const SelectorField = ({
});
}}
>
{Object.keys(config.tags).map((tagKey) => (
{Object.keys(pluginOptions.tags).map((tagKey) => (
<Option key={tagKey} value={tagKey}>
{tagKey}
</Option>
Expand Down
15 changes: 6 additions & 9 deletions admin/src/hooks/contentManagerHooks/addColumnToTable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import get from 'lodash/get';
import styled from 'styled-components';
import { Status, Typography, Loader } from '@strapi/design-system';
import { Status, Typography } from '@strapi/design-system';
import pluginId from '../../pluginId';
import useConfig from '../useConfig';

const StyledStatus = styled(Status)`
width: min-content;
Expand All @@ -28,15 +27,13 @@ const addColumnToTableHook = ({ displayedHeaders, layout }) => {
searchable: true,
sortable: true,
},
name: 'content-tags',
name: pluginOptions.fieldName,
cellFormatter(cellData) {
const { config, isLoading: configIsLoading } = useConfig();

if (configIsLoading) return <Loader small>Loading content...</Loader>;

const tagKey = cellData[pluginOptions.fieldName] ?? config.defaultTag;
const tagKey =
cellData[pluginOptions.fieldName] ?? pluginOptions.defaultTag;
const tagProperties =
config.tags[tagKey] || config.tags[config.defaultTag];
pluginOptions.tags[tagKey] ||
pluginOptions.tags[pluginOptions.defaultTag];
const tagColor = tagProperties.color;

return (
Expand Down
37 changes: 0 additions & 37 deletions admin/src/hooks/useConfig/index.js

This file was deleted.

23 changes: 0 additions & 23 deletions admin/src/pages/App/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions server/bootstrap.js

This file was deleted.

42 changes: 0 additions & 42 deletions server/config/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions server/content-types/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions server/controllers/config-controller.js

This file was deleted.

7 changes: 0 additions & 7 deletions server/controllers/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions server/destroy.js

This file was deleted.

18 changes: 0 additions & 18 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
'use strict';

const register = require('./register');
const bootstrap = require('./bootstrap');
const destroy = require('./destroy');
const config = require('./config');
const contentTypes = require('./content-types');
const controllers = require('./controllers');
const routes = require('./routes');
const middlewares = require('./middlewares');
const policies = require('./policies');
const services = require('./services');

module.exports = {
register,
bootstrap,
destroy,
config,
controllers,
routes,
services,
contentTypes,
policies,
middlewares,
};
3 changes: 0 additions & 3 deletions server/middlewares/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions server/policies/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions server/routes/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions server/services/config-service.js

This file was deleted.

7 changes: 0 additions & 7 deletions server/services/index.js

This file was deleted.

0 comments on commit 7c048ae

Please sign in to comment.