-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
305 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Field, | ||
FieldLabel, | ||
FieldError, | ||
FieldHint, | ||
Select, | ||
Option, | ||
Loader, | ||
Stack, | ||
} from '@strapi/design-system'; | ||
import { useIntl } from 'react-intl'; | ||
import useConfig from '../../hooks/useConfig'; | ||
|
||
const SelectorField = ({ | ||
value, | ||
onChange, | ||
name, | ||
intlLabel, | ||
labelAction, | ||
required, | ||
attribute, | ||
hint, | ||
placeholder, | ||
disabled, | ||
error, | ||
}) => { | ||
// const { options = {} } = attribute; | ||
const { config, isLoading: configIsLoading } = useConfig(); | ||
|
||
const { formatMessage } = useIntl(); | ||
|
||
console.log('Tags', config); | ||
|
||
return ( | ||
<Field | ||
name={name} | ||
id={name} | ||
error={error} | ||
required={required} | ||
hint={hint && formatMessage(hint)} | ||
> | ||
<Stack spacing={1}> | ||
<FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel> | ||
|
||
{configIsLoading ? ( | ||
<Loader small>Loading content...</Loader> | ||
) : ( | ||
<Select | ||
placeholder={placeholder && formatMessage(placeholder)} | ||
aria-label={formatMessage(intlLabel)} | ||
aria-disabled={disabled} | ||
disabled={disabled} | ||
value={value} | ||
onChange={(newCountry) => { | ||
onChange({ | ||
target: { | ||
name, | ||
value: newCountry, | ||
type: attribute.type, | ||
}, | ||
}); | ||
}} | ||
> | ||
<Option value="">None</Option> | ||
{Object.entries(config.tags).map(([tagKey, tagProperties]) => ( | ||
<Option key={tagKey} value={tagKey}> | ||
{tagProperties.label} | ||
</Option> | ||
))} | ||
</Select> | ||
)} | ||
<FieldHint /> | ||
<FieldError /> | ||
</Stack> | ||
</Field> | ||
); | ||
}; | ||
|
||
SelectorField.defaultProps = { | ||
description: null, | ||
disabled: false, | ||
error: null, | ||
labelAction: null, | ||
required: false, | ||
value: '', | ||
}; | ||
|
||
SelectorField.propTypes = { | ||
intlLabel: PropTypes.object.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
attribute: PropTypes.object.isRequired, | ||
name: PropTypes.string.isRequired, | ||
description: PropTypes.object, | ||
disabled: PropTypes.bool, | ||
error: PropTypes.string, | ||
labelAction: PropTypes.object, | ||
required: PropTypes.bool, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default SelectorField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { Icon, Flex } from '@strapi/design-system'; | ||
import { List } from '@strapi/icons'; | ||
|
||
const IconBox = styled(Flex)` | ||
background-color: #f0f0ff; /* primary100 */ | ||
border: 1px solid #d9d8ff; /* primary200 */ | ||
svg > path { | ||
fill: #4945ff; /* primary600 */ | ||
} | ||
`; | ||
|
||
const SelectorIcon = () => { | ||
return ( | ||
<IconBox | ||
justifyContent="center" | ||
alignItems="center" | ||
width={7} | ||
height={6} | ||
hasRadius | ||
aria-hidden | ||
> | ||
<Icon as={List} /> | ||
</IconBox> | ||
); | ||
}; | ||
|
||
export default SelectorIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { request, useNotification } from '@strapi/helper-plugin'; | ||
import pluginId from '../../pluginId'; | ||
|
||
const fetchConfig = async () => { | ||
const data = await request(`/${pluginId}/config`, { | ||
method: 'GET', | ||
}); | ||
|
||
return data ?? {}; | ||
}; | ||
|
||
const useConfig = () => { | ||
const toggleNotification = useNotification(); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [config, setConfig] = useState({}); | ||
|
||
useEffect(() => { | ||
fetchConfig() | ||
.then((config) => { | ||
setConfig(config); | ||
}) | ||
.catch(() => { | ||
toggleNotification({ | ||
type: 'warning', | ||
message: { id: 'notification.error' }, | ||
}); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}, [toggleNotification]); | ||
|
||
return { config, isLoading }; | ||
}; | ||
|
||
export default useConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import pluginPkg from '../../package.json'; | ||
const pluginPkg = require('../../package.json'); | ||
|
||
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, ''); | ||
const pluginName = pluginPkg.name; | ||
// eslint-disable-next-line prettier/prettier | ||
const pluginId = pluginName.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, ''); | ||
|
||
export default pluginId; | ||
module.exports = pluginId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
{} | ||
{ | ||
"customField.label": "Tags", | ||
"customField.description": "Assign tags to entities" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
'use strict'; | ||
|
||
const { ValidationError } = require('@strapi/utils').errors; | ||
|
||
module.exports = { | ||
default: {}, | ||
validator() {}, | ||
default: { | ||
colors: { | ||
'dark-blue': '#0000FF', | ||
'dark-green': '#00FF00', | ||
'dark-red': '#FF0000', | ||
black: '#000000', | ||
}, | ||
tags: { | ||
done: { label: 'Done', color: 'dark-green' }, | ||
inProgress: { label: 'In progress', color: 'dark-blue' }, | ||
error: { label: 'Error', color: 'dark-red' }, | ||
}, | ||
}, | ||
validator(config) { | ||
// colors | ||
if (!config.colors) { | ||
throw new ValidationError('You must define colors prop'); | ||
} | ||
// tags | ||
if (!config.tags) { | ||
throw new ValidationError('You must define tags prop'); | ||
} | ||
Object.entries(config.tags).forEach(([tagKey, tagProperties]) => { | ||
if ( | ||
!tagProperties.hasOwnProperty('label') || | ||
!tagProperties.hasOwnProperty('color') | ||
) { | ||
throw new ValidationError( | ||
`Missing properties on tags.${tagKey}: Define label and color`, | ||
); | ||
} | ||
if (!Object.keys(config.colors).includes(tagProperties.color)) { | ||
throw new ValidationError( | ||
`Undefined color key at tags.${tagKey}.color`, | ||
); | ||
} | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
const pluginId = require('../../admin/src/pluginId'); | ||
|
||
module.exports = ({ strapi }) => { | ||
const configService = strapi.plugin(pluginId).service('configService'); | ||
|
||
const getConfig = async (ctx) => { | ||
ctx.body = await configService.getConfig(); | ||
}; | ||
|
||
return { | ||
getConfig, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
'use strict'; | ||
|
||
const myController = require('./my-controller'); | ||
const configController = require('./config-controller'); | ||
|
||
module.exports = { | ||
myController, | ||
configController, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.