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
}
enum FlowStatus {
paused
published
draft
}
type Flow {
id: String
name: String
@@ -257,6 +263,7 @@ type Flow {
steps: [Step]
createdAt: String
updatedAt: String
status: FlowStatus
}
type Execution {

View File

@@ -1,5 +1,5 @@
import { ValidationError } from 'objection';
import type { ModelOptions, QueryContext } from 'objection';
import type { ModelOptions, QueryContext, StaticHookArguments } from 'objection';
import appConfig from '../config/app';
import ExtendedQueryBuilder from './query-builder';
import Base from './base';
@@ -14,6 +14,7 @@ class Flow extends Base {
name!: string;
userId!: string;
active: boolean;
status: 'paused' | 'published' | 'draft';
steps: Step[];
published_at: 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() {
const lastExecution = await this.$relatedQuery('executions')
.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() {
if (!appConfig.isCloud) return;

View File

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

View File

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

View File

@@ -18,6 +18,26 @@ type FlowRowProps = {
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 {
const formatMessage = useFormatMessage();
const contextButtonRef = React.useRef<HTMLButtonElement | null>(null);
@@ -76,10 +96,10 @@ export default function FlowRow(props: FlowRowProps): React.ReactElement {
<ContextMenu>
<Chip
size="small"
color={flow?.active ? 'success' : 'info'}
color={getFlowStatusColor(flow?.status)}
variant={flow?.active ? 'filled' : 'outlined'}
label={formatMessage(
flow?.active ? 'flow.published' : 'flow.draft'
getFlowStatusTranslationKey(flow?.status)
)}
/>

View File

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

View File

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

View File

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