-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Standardize runtime environment status handling #8026
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Runtime } from '@/api/interface/runtime'; | ||
|
|
||
| export function disabledButton(row: Runtime.Runtime, type: string): boolean { | ||
| switch (type) { | ||
| case 'stop': | ||
| return row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building'; | ||
| case 'start': | ||
| return ( | ||
| row.status === 'Starting' || | ||
| row.status === 'Recreating' || | ||
| row.status === 'Running' || | ||
| row.status === 'Building' | ||
| ); | ||
| case 'restart': | ||
| return row.status === 'Recreating' || row.status === 'Building'; | ||
| case 'edit': | ||
| return row.status === 'Recreating' || row.status === 'Building'; | ||
| case 'extension': | ||
| case 'config': | ||
| return row.status != 'Running'; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue'; | |
| import AppResources from '@/views/website/runtime/php/check/index.vue'; | ||
| import { ElMessageBox } from 'element-plus'; | ||
| import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; | ||
| import { disabledButton } from '@/utils/runtime'; | ||
|
|
||
| let timer: NodeJS.Timer | null = null; | ||
| const loading = ref(false); | ||
|
|
@@ -139,7 +140,7 @@ const buttons = [ | |
| openModules(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating' || row.status === 'stopped'; | ||
| return disabledButton(row, 'stop'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -148,7 +149,7 @@ const buttons = [ | |
| operateRuntime('down', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating' || row.status === 'stopped'; | ||
| return disabledButton(row, 'stop'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -157,7 +158,7 @@ const buttons = [ | |
| operateRuntime('up', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; | ||
| return disabledButton(row, 'start'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -166,7 +167,7 @@ const buttons = [ | |
| operateRuntime('restart', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating'; | ||
| return disabledButton(row, 'restart'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -175,7 +176,7 @@ const buttons = [ | |
| openDetail(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating'; | ||
| return disabledButton(row, 'edit'); | ||
| }, | ||
| }, | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, but I need a specific code snippet to analyze. Please provide more details about the code you are referring to or share the entire codebase with its contents so that I can accurately review it for you. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,7 @@ import ComposeLogs from '@/components/compose-log/index.vue'; | |
| import Config from '@/views/website/runtime/php/config/index.vue'; | ||
| import Supervisor from '@/views/website/runtime/php/supervisor/index.vue'; | ||
| import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; | ||
| import { disabledButton } from '@/utils/runtime'; | ||
|
|
||
| const paginationConfig = reactive({ | ||
| cacheSizeKey: 'runtime-page-size', | ||
|
|
@@ -160,7 +161,7 @@ const buttons = [ | |
| openExtensionsManagement(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status != 'running'; | ||
| return disabledButton(row, 'extension'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -169,7 +170,7 @@ const buttons = [ | |
| operateRuntime('down', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating' || row.status === 'stopped' || row.status === 'building'; | ||
| return disabledButton(row, 'stop'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -178,12 +179,7 @@ const buttons = [ | |
| operateRuntime('up', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return ( | ||
| row.status === 'starting' || | ||
| row.status === 'recreating' || | ||
| row.status === 'running' || | ||
| row.status === 'building' | ||
| ); | ||
| return disabledButton(row, 'start'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -192,7 +188,7 @@ const buttons = [ | |
| operateRuntime('restart', row.id); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'recreating' || row.status === 'building'; | ||
| return disabledButton(row, 'restart'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -201,7 +197,7 @@ const buttons = [ | |
| openDetail(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'building'; | ||
| return disabledButton(row, 'edit'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -210,7 +206,7 @@ const buttons = [ | |
| openConfig(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'building'; | ||
| return disabledButton(row, 'config'); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -219,14 +215,11 @@ const buttons = [ | |
| openSupervisor(row); | ||
| }, | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'building'; | ||
| return disabledButton(row, 'config'); | ||
| }, | ||
| }, | ||
| { | ||
| label: i18n.global.t('commons.button.delete'), | ||
| disabled: function (row: Runtime.Runtime) { | ||
| return row.status === 'building'; | ||
| }, | ||
| click: function (row: Runtime.Runtime) { | ||
| openDelete(row); | ||
| }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a JavaScript code snippet related to web components. Without actual source context and detailed code analysis, it's tough to provide specific improvements or suggestions directly. However, if we're talking about efficiency in this context:
As an example of improved optimization within these sections, you might refactor the "disabled" state checks into utility functions rather than deep nesting logic inside each element declaration. This could improve maintainability when dealing with complex configurations later on. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems well-structured and does not contain any obvious errors nor significant inefficiencies.
There isn't much room for improvement or suggestion without more context, however, to make specific optimizations.
However, this function could benefit from using
reduceif it's being used frequently in conditional branches. It would reduce redundancy, increase readability, and potentially optimize performance under certain circumstances:It'll be important to consider that the switch statement can become redundant with a loop where conditions match exactly like below: