Skip to content

Commit

Permalink
feat: reworked worklow definition page & added ui definition page (#2596
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chesterkmr authored Jul 31, 2024
1 parent 1ca8635 commit ba6f631
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { fetchUIDefinitions } from '@/domains/ui-definitions/ui-definitions.api';
import { fetchUIDefinition, fetchUIDefinitions } from '@/domains/ui-definitions/ui-definitions.api';
import { GetUIDefinitionByIdDto } from '@/domains/ui-definitions/ui-definitions.types';
import { createQueryKeys } from '@lukemorales/query-key-factory';

export const uiDefinitionsQueryKeys = createQueryKeys('uiDefinitions', {
get: (query: GetUIDefinitionByIdDto) => ({
queryKey: [{ query }],
queryFn: () => fetchUIDefinition(query),
}),
list: () => ({
queryKey: [{}],
queryFn: () => fetchUIDefinitions(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
GetUIDefinitionByIdDto,
IUIDefinition,
UpdateUIDefinitionDto,
} from '@/domains/ui-definitions/ui-definitions.types';
Expand All @@ -17,3 +18,9 @@ export const updateUIDefinition = async (dto: UpdateUIDefinitionDto) => {

return result.data;
};

export const fetchUIDefinition = async (dto: GetUIDefinitionByIdDto) => {
const result = await request.get<IUIDefinition>(`/internal/ui-definition/${dto.uiDefinitionId}`);

return result.data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export interface UpdateUIDefinitionDto {
uiDefinitionId: string;
uiDefinition: IUIDefinition;
}

export interface GetUIDefinitionByIdDto {
uiDefinitionId: string;
}
49 changes: 49 additions & 0 deletions apps/workflows-dashboard/src/pages/UIDefinition/UIDefinition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { LoadingSpinner } from '@/components/atoms/LoadingSpinner';
import { DashboardLayout } from '@/components/layouts/DashboardLayout';
import { useUIDefinitionQuery } from '@/pages/UIDefinition/hooks/useUIDefinitionQuery';
import { UIDefinitionEditor } from '@/pages/WorkflowDefinition/components/UIDefinitionEditor';
import { isAxiosError } from 'axios';
import { Link, useParams } from 'react-router-dom';

export const UIDefinition = () => {
const id = useParams<{ id: string }>().id;
const { data, isLoading, error } = useUIDefinitionQuery({ uiDefinitionId: id! });

if (isLoading) {
return (
<DashboardLayout pageName="Loading">
<div className="flex h-full w-full justify-center">
<LoadingSpinner />
</div>
</DashboardLayout>
);
}

if (isAxiosError(error)) {
if (error.response?.status === 404) {
return (
<DashboardLayout pageName="UI Definition">
<h1 className="flex flex-col gap-4">UI Definition not found.</h1>
<h2>
Back to{' '}
<Link to="/ui-definitions">
<span className="underline">list.</span>
</Link>
</h2>
</DashboardLayout>
);
}

return (
<DashboardLayout pageName="UI Definition">Failed to fetch ui definition.</DashboardLayout>
);
}

if (!data) return null;

return (
<DashboardLayout pageName={`UI Definition - ${data?.id}`}>
<UIDefinitionEditor uiDefinition={data} />
</DashboardLayout>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useUIDefinitionQuery';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GetUIDefinitionByIdDto, uiDefinitionsQueryKeys } from '@/domains/ui-definitions';
import { useQuery } from '@tanstack/react-query';

export const useUIDefinitionQuery = (query: GetUIDefinitionByIdDto) => {
const { isLoading, data, error } = useQuery({
...uiDefinitionsQueryKeys.get(query),
// @ts-ignore
retry: false,
keepPreviousData: true,
});

return {
isLoading,
data,
error,
};
};
1 change: 1 addition & 0 deletions apps/workflows-dashboard/src/pages/UIDefinition/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './UIDefinition';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { JSONViewButton } from '@/components/molecules/JSONViewButton';
import { IUIDefinition } from '@/domains/ui-definitions';
import { formatDate } from '@/utils/format-date';
import { createColumnHelper } from '@tanstack/react-table';
import { Eye } from 'lucide-react';
import { ArrowRightCircleIcon, Eye } from 'lucide-react';
import { Link } from 'react-router-dom';

const columnHelper = createColumnHelper<IUIDefinition>();

Expand Down Expand Up @@ -61,4 +62,12 @@ export const uiDefinitionTableColumnns = [
cell: info => formatDate(info.getValue<Date>()),
header: () => 'Created At',
}),
columnHelper.accessor('id', {
cell: info => (
<Link to={`/ui-definitions/${info.row.original.id}`}>
<ArrowRightCircleIcon />
</Link>
),
header: () => '',
}),
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DashboardLayout } from '@/components/layouts/DashboardLayout';
import { XstateVisualizer } from '@/components/organisms/XstateVisualizer';
import { IWorkflow } from '@/domains/workflows/api/workflow';
import { EditorCard } from '@/pages/WorkflowDefinition/components/EditorCard';
import { UIDefinitionEditor } from '@/pages/WorkflowDefinition/components/UIDefinitionEditor';
import { WorkflowDefinitionSummaryCard } from '@/pages/WorkflowDefinition/components/WorkflowDefinitionSummaryCard';
import { useUpgradeWorkflowDefinitionVersionMutation } from '@/pages/WorkflowDefinition/hooks/useUpgradeWorkflowDefinitionVersionMutation';
import { useWorkflowDefinitionEdit } from '@/pages/WorkflowDefinition/hooks/useWorkflowDefinitionEdit';
Expand Down Expand Up @@ -83,25 +82,14 @@ export const WorkflowDefinition = () => {
</div>
</div>
<div className="flex flex-row gap-2">
{workflowDefinitionValue && (
<div className="w-1/2">
<EditorCard
title="Workflow Definition"
value={workflowDefinitionValue}
onSave={handleWorkflowDefinitionSave}
onUpgrade={() =>
upgradeWorkflowDefinitionVersion({ workflowDefinitionId: data.id! })
}
/>
</div>
)}
{data.uiDefinitions.length ? (
<div className="w-1/2">
<UIDefinitionEditor uiDefinition={data.uiDefinitions[0]!} />
</div>
) : null}
</div>
<div className="flex flex-row gap-2">
<div className="w-1/2">
<EditorCard
title="Workflow Definition"
value={workflowDefinitionValue || {}}
onSave={workflowDefinitionValue ? handleWorkflowDefinitionSave : undefined}
onUpgrade={() => upgradeWorkflowDefinitionVersion({ workflowDefinitionId: data.id! })}
/>
</div>
<div className="w-1/2">
<EditorCard
title="Config"
Expand All @@ -112,20 +100,16 @@ export const WorkflowDefinition = () => {
onUpgrade={() => upgradeWorkflowDefinitionVersion({ workflowDefinitionId: data.id! })}
/>
</div>
{workflowDefinitionExtensions && (
<div className="w-1/2">
<EditorCard
title="Plugins"
value={workflowDefinitionExtensions || {}}
onSave={handleWorkflowExtensionsSave}
onUpgrade={() =>
upgradeWorkflowDefinitionVersion({ workflowDefinitionId: data.id! })
}
/>
</div>
)}
</div>
<div className="flex flex-row gap-2">
<div className="w-1/2">
<EditorCard
title="Plugins"
value={workflowDefinitionExtensions || {}}
onSave={handleWorkflowExtensionsSave}
onUpgrade={() => upgradeWorkflowDefinitionVersion({ workflowDefinitionId: data.id! })}
/>
</div>
<div className="w-1/2">
<EditorCard
title="Context Schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EditorCard } from '@/pages/WorkflowDefinition/components/EditorCard';
import { useUIDefinitionEditorTabs } from '@/pages/WorkflowDefinition/components/UIDefinitionEditor/hooks/useUIDefinitionEditorTabs';
import { useUIDefinitionElementUpdate } from '@/pages/WorkflowDefinition/components/UIDefinitionEditor/hooks/useUIDefinitionElementUpdate';
import { useUpgradeWorkflowDefinitionVersionMutation } from '@/pages/WorkflowDefinition/hooks/useUpgradeWorkflowDefinitionVersionMutation';
import { FunctionComponent, useMemo } from 'react';
import { FunctionComponent } from 'react';

interface UIDefinitionEditorProps {
uiDefinition: IUIDefinition;
Expand All @@ -22,11 +22,6 @@ export const UIDefinitionEditor: FunctionComponent<UIDefinitionEditorProps> = ({
useUIDefinitionElementUpdate(uiDefinition.workflowDefinitionId, uiDefinition);
const { mutate: upgradeVersion } = useUpgradeWorkflowDefinitionVersionMutation();

const hasChanges = useMemo(
() => JSON.stringify(uiDefinition) !== JSON.stringify(uiDefinitionValue),
[uiDefinitionValue, uiDefinition],
);

return (
<EditorCard
title="UI Definition"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { updateUIDefinition, UpdateUIDefinitionDto } from '@/domains/ui-definitions';
import { IWorkflowDefinition } from '@/domains/workflow-definitions';
import {
uiDefinitionsQueryKeys,
updateUIDefinition,
UpdateUIDefinitionDto,
} from '@/domains/ui-definitions';
import { queryClient } from '@/lib/react-query/query-client';
import { useMutation } from '@tanstack/react-query';
import { toast } from 'sonner';
Expand All @@ -8,18 +11,9 @@ export const useUpdateUIDefinitionMutation = () => {
return useMutation({
mutationFn: async (dto: UpdateUIDefinitionDto) => updateUIDefinition(dto),
onMutate(dto) {
const queryKeys = [
'workflowDefinitions',
'get',
{ query: { workflowDefinitionId: dto.workflowDefinitionId } },
];
const { queryKey } = uiDefinitionsQueryKeys.get({ uiDefinitionId: dto.uiDefinitionId });

const previousDefinition = queryClient.getQueryData<IWorkflowDefinition>(queryKeys);

queryClient.setQueryData(queryKeys, {
...previousDefinition,
uiDefinitions: [dto.uiDefinition],
});
queryClient.setQueryData(queryKey, dto.uiDefinition);
},
onSuccess: () => {
toast.success('UI definition updated successfully.');
Expand Down
5 changes: 5 additions & 0 deletions apps/workflows-dashboard/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AlertDefinitions } from '@/pages/AlertDefinitions';
import { Filters } from '@/pages/Filters';
import { Overview } from '@/pages/Overview';
import { SignIn } from '@/pages/SignIn';
import { UIDefinition } from '@/pages/UIDefinition';
import { UIDefinitions } from '@/pages/UIDefinitions';
import { WorkflowDefinition } from '@/pages/WorkflowDefinition';
import { WorkflowDefinitions } from '@/pages/WorkflowDefinitions';
Expand Down Expand Up @@ -48,6 +49,10 @@ export const router = createBrowserRouter([
path: 'ui-definitions',
Component: withSessionProtected(UIDefinitions),
},
{
path: 'ui-definitions/:id',
Component: withSessionProtected(UIDefinition),
},
{
path: 'alert-definitions',
Component: withSessionProtected(AlertDefinitions),
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations

0 comments on commit ba6f631

Please sign in to comment.