Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update automations limitation #1728

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions frontend/src/modules/automation/components/automation-toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:model-value="props.automation.state === 'active'"
class="!grow-0 !ml-0"
:disabled="!canEnable"
:before-change="beforeChange"
@change="handleChange"
/>
<span class="ml-2 text-gray-900 text-sm">
Expand All @@ -16,6 +17,9 @@
import { computed, defineProps } from 'vue';
import { useAutomationStore } from '@/modules/automation/store';
import { useStore } from 'vuex';
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';
import { mapGetters } from '@/shared/vuex/vuex.helpers';
import { FeatureFlag } from '@/utils/featureFlag';
import { automationTypes } from '../config/automation-types';

const props = defineProps({
Expand All @@ -29,14 +33,38 @@ const store = useStore();

const { changePublishState } = useAutomationStore();

const { currentTenant } = mapGetters('auth');

const canEnable = computed(() => {
const { type } = props.automation;

if (automationTypes[type]?.enableGuard) {
return props.automation.state === 'active' || automationTypes[type]?.enableGuard(props.automation, store);
}

return true;
});

const beforeChange = () => {
if (props.automation.state === 'active') {
return true;
}

const isFeatureEnabled = FeatureFlag.isFlagEnabled(
FeatureFlag.flags.automations,
);

if (!isFeatureEnabled) {
const planWorkflowCountMax = getWorkflowMax(
currentTenant.value.plan,
);

showWorkflowLimitDialog({ planWorkflowCountMax });
}

return isFeatureEnabled;
};

const handleChange = (value) => {
changePublishState(props.automation.id, value);
};
Expand Down
27 changes: 0 additions & 27 deletions frontend/src/modules/automation/pages/automation-list-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ import { storeToRefs } from 'pinia';
import pluralize from 'pluralize';
import AppAutomationForm from '@/modules/automation/components/automation-form.vue';
import AppAutomationListTable from '@/modules/automation/components/list/automation-list-table.vue';
import { mapGetters } from '@/shared/vuex/vuex.helpers';
import AppAutomationExecutions from '@/modules/automation/components/automation-executions.vue';
import { FeatureFlag } from '@/utils/featureFlag';
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';

import { useStore } from 'vuex';
import config from '@/config';
Expand All @@ -158,40 +156,15 @@ const {
} = storeToRefs(automationStore);
const { getAutomations, changeAutomationFilter } = automationStore;

const { currentTenant } = mapGetters('auth');

const store = useStore();
const fetchIntegrations = () => store.dispatch('integration/doFetch');

/**
* Check if tenant has feature flag enabled
*/
const canAddAutomation = () => {
const isFeatureEnabled = FeatureFlag.isFlagEnabled(
FeatureFlag.flags.automations,
);

if (!isFeatureEnabled) {
const planWorkflowCountMax = getWorkflowMax(
currentTenant.value.plan,
);

showWorkflowLimitDialog({ planWorkflowCountMax });
}

return isFeatureEnabled;
};

// Executions drawer
const createAutomation = (type) => {
if (!automationTypes[type].canCreate(store)) {
return;
}

if (!canAddAutomation()) {
return;
}

openAutomationForm.value = true;
editAutomation.value = null;
automationFormType.value = type;
Expand Down