feat(flow): add virtual paused/published/draft status

This commit is contained in:
Ali BARIN
2023-04-09 16:23:34 +00:00
parent df55f746ca
commit 77e29050c8
8 changed files with 66 additions and 3 deletions

View File

@@ -250,6 +250,12 @@ type FlowEdge {
node: Flow node: Flow
} }
enum FlowStatus {
paused
published
draft
}
type Flow { type Flow {
id: String id: String
name: String name: String
@@ -257,6 +263,7 @@ type Flow {
steps: [Step] steps: [Step]
createdAt: String createdAt: String
updatedAt: String updatedAt: String
status: FlowStatus
} }
type Execution { type Execution {

View File

@@ -1,5 +1,5 @@
import { ValidationError } from 'objection'; import { ValidationError } from 'objection';
import type { ModelOptions, QueryContext } from 'objection'; import type { ModelOptions, QueryContext, StaticHookArguments } from 'objection';
import appConfig from '../config/app'; import appConfig from '../config/app';
import ExtendedQueryBuilder from './query-builder'; import ExtendedQueryBuilder from './query-builder';
import Base from './base'; import Base from './base';
@@ -14,6 +14,7 @@ class Flow extends Base {
name!: string; name!: string;
userId!: string; userId!: string;
active: boolean; active: boolean;
status: 'paused' | 'published' | 'draft';
steps: Step[]; steps: Step[];
published_at: string; published_at: string;
remoteWebhookId: string; remoteWebhookId: string;
@@ -65,6 +66,26 @@ class Flow extends Base {
}, },
}); });
static async afterFind(args: StaticHookArguments<any>): Promise<any> {
const { result } = args;
const referenceFlow = result[0];
if (referenceFlow) {
const shouldBePaused = await referenceFlow.isPaused();
for (const flow of result) {
if (!flow.active) {
flow.status = 'draft';
} else if (flow.active && shouldBePaused) {
flow.status = 'paused';
} else {
flow.status = 'published';
}
}
}
}
async lastInternalId() { async lastInternalId() {
const lastExecution = await this.$relatedQuery('executions') const lastExecution = await this.$relatedQuery('executions')
.orderBy('created_at', 'desc') .orderBy('created_at', 'desc')
@@ -132,6 +153,13 @@ class Flow extends Base {
}); });
} }
async isPaused() {
const user = await this.$relatedQuery('user');
const currentUsageData = await user.$relatedQuery('currentUsageData');
return await currentUsageData.checkIfLimitExceeded();
}
async checkIfQuotaExceeded() { async checkIfQuotaExceeded() {
if (!appConfig.isCloud) return; if (!appConfig.isCloud) return;

View File

@@ -56,6 +56,10 @@ class UsageData extends Base {
const subscription = await this.$relatedQuery('subscription'); const subscription = await this.$relatedQuery('subscription');
if (!subscription) {
return true;
}
if (!subscription.isActive) { if (!subscription.isActive) {
return true; return true;
} }

View File

@@ -73,6 +73,7 @@ export interface IFlow {
name: string; name: string;
userId: string; userId: string;
active: boolean; active: boolean;
status: 'paused' | 'published' | 'draft';
steps: IStep[]; steps: IStep[];
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;

View File

@@ -18,6 +18,26 @@ type FlowRowProps = {
flow: IFlow; flow: IFlow;
}; };
function getFlowStatusTranslationKey(status: IFlow["status"]): string {
if (status === 'published') {
return 'flow.published';
} else if (status === 'paused') {
return 'flow.paused';
}
return 'flow.draft';
}
function getFlowStatusColor(status: IFlow["status"]): 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' {
if (status === 'published') {
return 'success';
} else if (status === 'paused') {
return 'error';
}
return 'info';
}
export default function FlowRow(props: FlowRowProps): React.ReactElement { export default function FlowRow(props: FlowRowProps): React.ReactElement {
const formatMessage = useFormatMessage(); const formatMessage = useFormatMessage();
const contextButtonRef = React.useRef<HTMLButtonElement | null>(null); const contextButtonRef = React.useRef<HTMLButtonElement | null>(null);
@@ -76,10 +96,10 @@ export default function FlowRow(props: FlowRowProps): React.ReactElement {
<ContextMenu> <ContextMenu>
<Chip <Chip
size="small" size="small"
color={flow?.active ? 'success' : 'info'} color={getFlowStatusColor(flow?.status)}
variant={flow?.active ? 'filled' : 'outlined'} variant={flow?.active ? 'filled' : 'outlined'}
label={formatMessage( label={formatMessage(
flow?.active ? 'flow.published' : 'flow.draft' getFlowStatusTranslationKey(flow?.status)
)} )}
/> />

View File

@@ -6,6 +6,7 @@ export const GET_FLOW = gql`
id id
name name
active active
status
steps { steps {
id id
type type

View File

@@ -26,6 +26,7 @@ export const GET_FLOWS = gql`
createdAt createdAt
updatedAt updatedAt
active active
status
steps { steps {
iconUrl iconUrl
} }

View File

@@ -43,6 +43,7 @@
"flow.active": "ON", "flow.active": "ON",
"flow.inactive": "OFF", "flow.inactive": "OFF",
"flow.published": "Published", "flow.published": "Published",
"flow.paused": "Paused",
"flow.draft": "Draft", "flow.draft": "Draft",
"flow.successfullyDeleted": "The flow and associated executions have been deleted.", "flow.successfullyDeleted": "The flow and associated executions have been deleted.",
"flowEditor.publish": "PUBLISH", "flowEditor.publish": "PUBLISH",