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

Feat: cms plugin #2393

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion cms/config/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ export default ({ env }) => ({
host: env('MEILISEARCH_HOST'),
apiKey: env('MEILISEARCH_MASTER_KEY'),
}
}
},
betagouv: {
enabled: true,
resolve: './src/plugins/betagouv',
},
});
176 changes: 176 additions & 0 deletions cms/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "cms",
"private": true,
"version": "0.1.0",
"workspaces": [
"src/plugins/*"
],
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
Expand Down
30 changes: 0 additions & 30 deletions cms/src/api/row/content-types/row/schema.json

This file was deleted.

7 changes: 0 additions & 7 deletions cms/src/api/row/controllers/row.ts

This file was deleted.

7 changes: 0 additions & 7 deletions cms/src/api/row/routes/row.ts

This file was deleted.

7 changes: 0 additions & 7 deletions cms/src/api/row/services/row.ts

This file was deleted.

20 changes: 20 additions & 0 deletions cms/src/plugins/betagouv/admin/src/components/FlowCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { Box, Typography, Button } from '@strapi/design-system';
import getTrad from '../utils/getTrad';
import { useIntl } from "react-intl"

import { useFlowRun } from '../hooks/useFlowRun';

const FlowCard = (props: {id: string}) => {
const { formatMessage } = useIntl();
const [run, isLoading, isError] = useFlowRun(props.id);

return (
<Box padding={4} hasRadius background="neutral0" shadow="tableShadow">
<Typography>{formatMessage({ id: getTrad(`flow-${props.id}`)})}</Typography>
<Button onClick={run} disabled={isLoading}>{formatMessage({ id: getTrad('action')})}</Button>
</Box>
);
};

export default FlowCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
*
* Initializer
*
*/

import { useEffect, useRef } from 'react';
import pluginId from '../../pluginId';

type InitializerProps = {
setPlugin: (id: string) => void;
};

const Initializer = ({ setPlugin }: InitializerProps) => {
const ref = useRef(setPlugin);

useEffect(() => {
ref.current(pluginId);
}, []);

return null;
};

export default Initializer;
12 changes: 12 additions & 0 deletions cms/src/plugins/betagouv/admin/src/components/PluginIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* PluginIcon
*
*/

import React from 'react';
import { Puzzle } from '@strapi/icons';

const PluginIcon = () => <Puzzle />;

export default PluginIcon;
20 changes: 20 additions & 0 deletions cms/src/plugins/betagouv/admin/src/hooks/useFlowList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState, useEffect } from 'react';
import { useFetchClient } from '@strapi/helper-plugin';
import pluginId from '../pluginId';

export function useFlowList():[Array<string>, boolean] {
const { get } = useFetchClient();
const [isLoading, setIsLoading] = useState(false);
const [flows, setFlows] = useState<Array<string>>([]);

useEffect(() => {
setIsLoading(true);
get(`${pluginId}/flows`)
.then((d: any) => {
setFlows(d.data);
})
.finally(() => setIsLoading(false));
}, []);

return [flows, isLoading];
}
23 changes: 23 additions & 0 deletions cms/src/plugins/betagouv/admin/src/hooks/useFlowRun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState } from 'react';
import { useFetchClient } from '@strapi/helper-plugin';
import pluginId from '../pluginId';

export function useFlowRun(id: string) {
const { post } = useFetchClient();
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);

async function run() {
setIsLoading(true);
try {
await post(`${pluginId}/flows/${id}`);
setIsError(false);
} catch(e) {
console.error(e)
setIsError(true);
} finally {
setIsLoading(false);
}
}
return [run, isLoading, isError];
}
Comment on lines +1 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useFlowRun hook is correctly implemented for executing flows and managing loading and error states. Consider replacing console.error with a more robust error handling strategy, such as reporting errors to an error tracking service, to improve maintainability and debuggability in production environments.

-      console.error(e)
+      // Consider replacing console.error with a more robust error handling strategy

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import { useState } from 'react';
import { useFetchClient } from '@strapi/helper-plugin';
import pluginId from '../pluginId';
export function useFlowRun(id: string) {
const { post } = useFetchClient();
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
async function run() {
setIsLoading(true);
try {
await post(`${pluginId}/flows/${id}`);
setIsError(false);
} catch(e) {
console.error(e)
setIsError(true);
} finally {
setIsLoading(false);
}
}
return [run, isLoading, isError];
}
import { useState } from 'react';
import { useFetchClient } from '@strapi/helper-plugin';
import pluginId from '../pluginId';
export function useFlowRun(id: string) {
const { post } = useFetchClient();
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
async function run() {
setIsLoading(true);
try {
await post(`${pluginId}/flows/${id}`);
setIsError(false);
} catch(e) {
// Consider replacing console.error with a more robust error handling strategy
setIsError(true);
} finally {
setIsLoading(false);
}
}
return [run, isLoading, isError];
}

Loading
Loading