diff --git a/frontend/src/api/cubicweb.ts b/frontend/src/api/cubicweb.ts index c5b515e40f41ae13d3fa9da15263d074f6a40402_ZnJvbnRlbmQvc3JjL2FwaS9jdWJpY3dlYi50cw==..af82274edd23f9cad51b71e8f95352424219a5c3_ZnJvbnRlbmQvc3JjL2FwaS9jdWJpY3dlYi50cw== 100644 --- a/frontend/src/api/cubicweb.ts +++ b/frontend/src/api/cubicweb.ts @@ -1,5 +1,12 @@ import { useClient } from "@/context/ClientContext"; -import { CWFile, DataService, ImportProcess, Project, Recipe } from "@/types"; +import { + CWFile, + DataService, + ImportProcess, + ProcessType, + Project, + Recipe, +} from "@/types"; import { RQLParams, BinariesParam, @@ -221,7 +228,9 @@ export function useApiCreateRecipe() { const client = useClient(); const insertRql = - "INSERT ImportRecipe X: X name %(name)s, X graph_uri %(graph_uri)s, X process_type %(process_type)s"; + "INSERT ImportRecipe X: X name %(name)s, X graph_uri %(graph_uri)s"; + const setProcessRql = + "SET X use_process %(process_type)s WHERE X eid %(eid)s"; const setDataServiceRql = "SET X dataservice %(dataservice)s WHERE X eid %(eid)s"; const setProjectRql = @@ -231,6 +240,5 @@ const insertQuery = transaction.push(insertRql, { name: data.name, graph_uri: data.graph_uri, - process_type: data.process_type, }); const eidRef = insertQuery.ref().row(0).column(0); @@ -235,5 +243,9 @@ }); const eidRef = insertQuery.ref().row(0).column(0); + transaction.push(setProcessRql, { + process_type: data.use_process.eid, + eid: eidRef, + }); transaction.push(setDataServiceRql, { dataservice: data.dataservice.eid, eid: eidRef, @@ -254,8 +266,8 @@ "X virtuoso_password ATTR_VIRTUOSO_PASSWORD, X activated ATTR_ACTIVATED, X ontology_file REL_ONTOLOGY?, X shacl_files REL_SHACL?"; const recipeListRql = - "Any X, ATTR_NAME, ATTR_GRAPH_URI, ATTR_PROCESS_TYPE ,REL_DATASERVICE, REL_DATASERVICE_NAME " + - "WHERE X is ImportRecipe, X name ATTR_NAME, X graph_uri ATTR_GRAPH_URI, X process_type ATTR_PROCESS_TYPE, X dataservice REL_DATASERVICE, REL_DATASERVICE name REL_DATASERVICE_NAME, O import_recipes X, O eid %(eid)s"; + "Any X, ATTR_NAME, ATTR_GRAPH_URI, ATTR_PROCESS, ATTR_PROCESS_NAME,REL_DATASERVICE, REL_DATASERVICE_NAME " + + "WHERE X is ImportRecipe, X name ATTR_NAME, X graph_uri ATTR_GRAPH_URI, X use_process ATTR_PROCESS, ATTR_PROCESS name ATTR_PROCESS_NAME, X dataservice REL_DATASERVICE, REL_DATASERVICE name REL_DATASERVICE_NAME, O import_recipes X, O eid %(eid)s"; return async (eid: number) => { try { @@ -276,8 +288,8 @@ eid: r[0], name: r[1], graph_uri: r[2], - process_type: r[3], - dataservice: { eid: r[4], name: r[5] }, + use_process: { eid: r[3], name: r[4] }, + dataservice: { eid: r[5], name: r[6] }, }) as Recipe, ); @@ -460,6 +472,22 @@ }; } +export function useApiGetProcessTypeList(): () => Promise<Array<ProcessType>> { + const client = useClient(); + const rql = + "Any X, ATTR_NAME WHERE X is ProcessType, X name ATTR_NAME, X activated True"; + return async () => { + const result = await client.execute(rql, {}); + return result.map( + (r) => + ({ + eid: r[0], + name: r[1], + }) as ProcessType, + ); + }; +} + export function useApiGetProjectList(): () => Promise<Array<Project>> { const client = useClient(); const rql = diff --git a/frontend/src/app/project/[eid]/page.tsx b/frontend/src/app/project/[eid]/page.tsx index c5b515e40f41ae13d3fa9da15263d074f6a40402_ZnJvbnRlbmQvc3JjL2FwcC9wcm9qZWN0L1tlaWRdL3BhZ2UudHN4..af82274edd23f9cad51b71e8f95352424219a5c3_ZnJvbnRlbmQvc3JjL2FwcC9wcm9qZWN0L1tlaWRdL3BhZ2UudHN4 100644 --- a/frontend/src/app/project/[eid]/page.tsx +++ b/frontend/src/app/project/[eid]/page.tsx @@ -93,7 +93,7 @@ <RecipeCard key={i} name={d.name} - processType={d.process_type} + processTypeName={d.use_process.name} dataserviceName={d.dataservice.name} onOpen={() => { if (selectedRecipeEid !== d.eid) { diff --git a/frontend/src/components/RecipeModal.tsx b/frontend/src/components/RecipeModal.tsx index c5b515e40f41ae13d3fa9da15263d074f6a40402_ZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvUmVjaXBlTW9kYWwudHN4..af82274edd23f9cad51b71e8f95352424219a5c3_ZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvUmVjaXBlTW9kYWwudHN4 100644 --- a/frontend/src/components/RecipeModal.tsx +++ b/frontend/src/components/RecipeModal.tsx @@ -1,5 +1,9 @@ -import { useApiCreateRecipe, useApiGetDataServiceList } from "@/api/cubicweb"; -import { DataService, Recipe, processNames } from "@/types"; +import { + useApiCreateRecipe, + useApiGetDataServiceList, + useApiGetProcessTypeList, +} from "@/api/cubicweb"; +import { DataService, Recipe, ProcessType } from "@/types"; import { LoadingButton } from "@mui/lab"; import { Autocomplete, @@ -28,6 +32,8 @@ onSuccess, }: RecipeModalProps) { const [data, setData] = useState<Array<DataService> | undefined>(); + const [processTypes, setProcessTypes] = + useState<Array<ProcessType | undefined>>(); const [loading, setLoading] = useState<boolean>(true); const [saving, setSaving] = useState(false); const getDataServiceList = useApiGetDataServiceList(); @@ -31,8 +37,9 @@ const [loading, setLoading] = useState<boolean>(true); const [saving, setSaving] = useState(false); const getDataServiceList = useApiGetDataServiceList(); + const getProcessTypeList = useApiGetProcessTypeList(); const createRecipe = useApiCreateRecipe(); const { handleSubmit, control, reset } = useForm<Recipe>({ defaultValues: { name: "", @@ -34,9 +41,8 @@ const createRecipe = useApiCreateRecipe(); const { handleSubmit, control, reset } = useForm<Recipe>({ defaultValues: { name: "", - process_type: "default", }, }); @@ -46,6 +52,7 @@ setTimeout(() => { setLoading(false); getDataServiceList().then((d) => setData(d)); + getProcessTypeList().then((d) => setProcessTypes(d)); }, 1000); } else { reset(); @@ -144,7 +151,7 @@ )} /> <Controller - name="process_type" + name="use_process" control={control} rules={{ required: true }} render={({ field, fieldState: { error } }) => ( @@ -152,8 +159,14 @@ disabled={saving} value={field.value} onChange={(_, newValue) => field.onChange(newValue)} - options={["default", "default-dryrun"]} - getOptionLabel={(option: string) => processNames[option]} + options={processTypes ? processTypes : []} + loading={loading} + getOptionLabel={ + processTypes + ? (option) => + processTypes.find((p) => p == option)?.name ?? "" + : () => "" + } renderInput={(params) => ( <TextField {...params} diff --git a/frontend/src/components/cards/RecipeCard.tsx b/frontend/src/components/cards/RecipeCard.tsx index c5b515e40f41ae13d3fa9da15263d074f6a40402_ZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvY2FyZHMvUmVjaXBlQ2FyZC50c3g=..af82274edd23f9cad51b71e8f95352424219a5c3_ZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvY2FyZHMvUmVjaXBlQ2FyZC50c3g= 100644 --- a/frontend/src/components/cards/RecipeCard.tsx +++ b/frontend/src/components/cards/RecipeCard.tsx @@ -12,7 +12,6 @@ import CheckIcon from "@mui/icons-material/Check"; import CloseIcon from "@mui/icons-material/Close"; import PlayArrowIcon from "@mui/icons-material/PlayArrow"; -import { processNames } from "@/types"; interface RecipeCardProps { name: string; @@ -16,7 +15,7 @@ interface RecipeCardProps { name: string; - processType: "default" | "default-dryrun"; + processTypeName: string; dataserviceName: string; lastProcessDate?: Date; lastProcessSuccess?: boolean; @@ -30,7 +29,7 @@ name, lastProcessDate, lastProcessSuccess, - processType, + processTypeName, dataserviceName, selected, onOpen, @@ -86,7 +85,7 @@ </> ) : null} <Typography variant="body2"> - Process type: {processNames[processType]} + Process type: {processTypeName} </Typography> <Typography variant="body2"> Data Service: {dataserviceName} diff --git a/frontend/src/types.ts b/frontend/src/types.ts index c5b515e40f41ae13d3fa9da15263d074f6a40402_ZnJvbnRlbmQvc3JjL3R5cGVzLnRz..af82274edd23f9cad51b71e8f95352424219a5c3_ZnJvbnRlbmQvc3JjL3R5cGVzLnRz 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -4,6 +4,11 @@ updateKey?: number; }; +export type ProcessType = { + eid: number; + name: string; +}; + export type Project = { eid: number; name: string; @@ -32,14 +37,7 @@ name: string; dataservice: { eid: number; name: string }; graph_uri: string; - process_type: "default" | "default-dryrun"; -}; - -export const processNames: { - [key: string]: string; -} = { - default: "processus d'import standard", - "default-dryrun": "processus d'import standard sans publication", + use_process: ProcessType; }; export type ImportProcess = {