feat(flow): add virtual paused/published/draft status
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -56,6 +56,10 @@ class UsageData extends Base {
|
||||
|
||||
const subscription = await this.$relatedQuery('subscription');
|
||||
|
||||
if (!subscription) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!subscription.isActive) {
|
||||
return true;
|
||||
}
|
||||
|
1
packages/types/index.d.ts
vendored
1
packages/types/index.d.ts
vendored
@@ -73,6 +73,7 @@ export interface IFlow {
|
||||
name: string;
|
||||
userId: string;
|
||||
active: boolean;
|
||||
status: 'paused' | 'published' | 'draft';
|
||||
steps: IStep[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
|
@@ -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)
|
||||
)}
|
||||
/>
|
||||
|
||||
|
@@ -6,6 +6,7 @@ export const GET_FLOW = gql`
|
||||
id
|
||||
name
|
||||
active
|
||||
status
|
||||
steps {
|
||||
id
|
||||
type
|
||||
|
@@ -26,6 +26,7 @@ export const GET_FLOWS = gql`
|
||||
createdAt
|
||||
updatedAt
|
||||
active
|
||||
status
|
||||
steps {
|
||||
iconUrl
|
||||
}
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user