Skip to content

Commit

Permalink
Fix/graphql not working (#457)
Browse files Browse the repository at this point in the history
* fix: graphql not working

* fix: form input re-render loop

* fix: navigation ui

* fix: API & gql

* feat: extend list of restricted content types

* fix: tests and circleci

* fix: settings form

* fix: additional field name validator

* fix: align tests config

* fix: additional fields

* fix: nav item form, additional fields, move to Strapi useForm

* fix: circleci cfg changes

* fix: rest endpoint and additional fields

* fix: bughunt awaited and skipped tests

---------

Co-authored-by: CodeVoyager <[email protected]>
  • Loading branch information
cyp3rius and CodeVoyager authored Oct 10, 2024
1 parent 899a92a commit 8e7069b
Show file tree
Hide file tree
Showing 65 changed files with 19,531 additions and 1,134 deletions.
70 changes: 56 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ version: 2.1
orbs:
codecov: codecov/[email protected]
jobs:
build-and-test:
test:
environment:
CODECOV_TOKEN: c803c20c-c45d-4a63-9ba9-58c7d5d05bbf
docker:
- image: cimg/node:18.18.2
- image: cimg/node:20.12.2
working_directory: ~/repo
resource_class: large
steps:
- checkout
- run:
Expand All @@ -27,26 +28,67 @@ jobs:
command: |
node --version
yarn --version
- run:
name: Configure NPM
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- run:
name: Install
command: |
yarn install
- run:
name: Build
name: Test
command: |
yarn build
# - run:
# name: Test
# command: |
# yarn test:unit
# - codecov/upload:
# flags: unittest
# file:
yarn test:unit:ci
environment:
JEST_JUNIT_OUTPUT_DIR: ./reports/
- store_test_results:
path: ./reports/
- codecov/upload:
flags: unittest
file:
- save_cache:
paths:
- ./node_modules
key: strapi-plugin-navigation-v3-{{ checksum "yarn.lock" }}
- persist_to_workspace:
root: ~/repo
paths: .
deploy:
environment:
CODECOV_TOKEN: c803c20c-c45d-4a63-9ba9-58c7d5d05bbf
docker:
- image: cimg/node:20.12.2
working_directory: ~/repo
resource_class: large
steps:
- attach_workspace:
at: ~/repo
- run:
name: Configure NPM
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- run:
name: Build
command: |
yarn build
- run:
name: Publish package
command: npm publish --tag beta

workflows:
build-and-test:
jobs:
- build-and-test
version: 2
test-deploy:
jobs:
- test:
filters:
tags:
only: /^v.*/
- deploy:
requires:
- test
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ node_modules
.node_history
yarn.lock
package-lock.json
.yarnrc.yml


############################
Expand All @@ -105,6 +106,7 @@ package-lock.json

testApp
coverage
junit.xml

############################
# Strapi
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.14.0
v20.12.0
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ Is applied for **Public API** both for REST and GraphQL. You can manage is by tw
{
"id": "News",
"title": "News",
"templateName": "pages:1",
"related": {
"contentType": "page",
"collectionName": "pages",
Expand Down Expand Up @@ -505,7 +504,6 @@ Return a rendered navigation structure depends on passed type (`TREE`, `RFR` or
"News": {
"id": "News",
"title": "News",
"templateName": "pages:1",
"related": {
"contentType": "page",
"collectionName": "pages",
Expand All @@ -519,7 +517,6 @@ Return a rendered navigation structure depends on passed type (`TREE`, `RFR` or
"Community": {
"id": "Community",
"title": "Community",
"templateName": "pages:2",
"related": {
"contentType": "page",
"collectionName": "pages",
Expand All @@ -533,7 +530,6 @@ Return a rendered navigation structure depends on passed type (`TREE`, `RFR` or
"Highlights": {
"id": "Highlights",
"title": "Highlights",
"templateName": "pages:3",
"related": {
"contentType": "page",
"collectionName": "pages",
Expand Down Expand Up @@ -678,14 +674,6 @@ query {
}
```

### Template name

Depending on a content type `templateName` will be resolved differently

For collection types it will be read from content type's attribute name `template` holding a component which definition has option named `templateName`.

For single types a global name of this content type will be used as a template name or it can be set manually with an option named `templateName`.

## 🔌 Extensions

### Slug generation
Expand Down
16 changes: 8 additions & 8 deletions admin/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ export const getApiClient = once((fetch: ReturnType<typeof getFetchClient>) => (
return [URL_PREFIX, 'navigations'];
},

delete(id: number) {
return fetch.del(`/${URL_PREFIX}/${id}`);
delete(documentId: string) {
return fetch.del(`/${URL_PREFIX}/${documentId}`);
},

create(body: Omit<NavigationSchema, 'documentId' | 'id' | 'slug'>) {
return fetch.post(`/${URL_PREFIX}/`, body);
},

update(body: NavigationSchema) {
return fetch.put(`/${URL_PREFIX}/${body.id}`, body);
return fetch.put(`/${URL_PREFIX}/${body.documentId}`, body);
},

purge({ id, withLangVersions }: { id?: number; withLangVersions?: boolean }) {
purge({ documentId, withLangVersions }: { documentId?: string; withLangVersions?: boolean }) {
return fetch.del(
`/${URL_PREFIX}/cache/purge/${id ?? ''}?clearLocalisations=${!!withLangVersions}`
`/${URL_PREFIX}/cache/purge/${documentId ?? ''}?clearLocalisations=${!!withLangVersions}`
);
},

Expand Down Expand Up @@ -151,7 +151,7 @@ export const getApiClient = once((fetch: ReturnType<typeof getFetchClient>) => (
return [URL_PREFIX, 'locale'];
},

copyNavigationLocale({ source, target }: { source: number; target: number }) {
copyNavigationLocale({ source, target }: { source: string; target: string }) {
return fetch.put(`/${URL_PREFIX}/i18n/copy/${source}/${target}`);
},

Expand All @@ -160,8 +160,8 @@ export const getApiClient = once((fetch: ReturnType<typeof getFetchClient>) => (
structureId = '',
target,
}: {
source: number;
target: number;
source: string;
target: string;
structureId?: string;
}) {
return fetch
Expand Down
8 changes: 6 additions & 2 deletions admin/src/api/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type NavigationPluginConfigSchema = z.infer<typeof configSchema>;
export type AudienceDBSchema = z.infer<typeof audienceDBSchema>;
export const audienceDBSchema = z.object({
id: z.number(),
documentId: z.string(),
name: z.string(),
key: z.string(),
});
Expand All @@ -14,6 +15,7 @@ export const navigationItemTypeSchema = z.enum(['INTERNAL', 'EXTERNAL']);

const navigationItemBaseSchema = z.object({
id: z.number(),
documentId: z.string(),
title: z.string(),
type: navigationItemTypeSchema,
path: z.string(),
Expand Down Expand Up @@ -54,7 +56,8 @@ export const navigationSchema = z.object({
});

const navigationCustomFieldBase = z.object({
name: z.string(),
// TODO: Proper message translation
name: z.string().refine((current) => !current.includes(' '), { message: 'No space allowed' }),
label: z.string(),
required: z.boolean().optional(),
enabled: z.boolean().optional(),
Expand Down Expand Up @@ -113,6 +116,7 @@ export const configSchema = z.object({
availableAudience: z
.object({
id: z.number(),
documentId: z.string(),
name: z.string(),
key: z.string(),
})
Expand Down Expand Up @@ -297,7 +301,7 @@ export const contentTypeSchema = contentTypeFullSchema.pick({
export type StrapiContentTypeItemSchema = z.infer<typeof strapiContentTypeItemSchema>;
export const strapiContentTypeItemSchema = z
.object({
id: z.number().optional(),
id: z.number(),
documentId: z.string(),
locale: z.string().or(z.null()).optional(),
})
Expand Down
2 changes: 1 addition & 1 deletion admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from './pages/App';
import SettingsPage from './pages/SettingsPage';
import { PLUGIN_ID } from './pluginId';
import pluginPermissions from './utils/permissions';
import { flattenObject, prefixPluginTranslations } from '@virtuslab/strapi-utils';
import { flattenObject, prefixPluginTranslations } from '@sensinum/strapi-utils';
import trads from "./translations";

const name = "navigation";
Expand Down
Loading

0 comments on commit 8e7069b

Please sign in to comment.