-
Notifications
You must be signed in to change notification settings - Fork 344
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
move form to another workspace #339
Conversation
WalkthroughThis update enhances the application by introducing the ability to change a form's workspace. Users can now select a new workspace for a form using the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (4)
- app/Http/Controllers/Forms/FormController.php (1 hunks)
- client/components/open/forms/components/FormWorkspaceModal.vue (1 hunks)
- client/components/pages/forms/show/ExtraMenu.vue (3 hunks)
- routes/api.php (1 hunks)
Additional comments: 5
client/components/open/forms/components/FormWorkspaceModal.vue (1)
- 1-48: The template structure and modal implementation look good. However, consider adding
aria-label
attributes to interactive elements (e.g., buttons) for improved accessibility. This ensures that users with assistive technologies can better understand the purpose of each interactive element.app/Http/Controllers/Forms/FormController.php (1)
- 222-240: The implementation of the
updateWorkspace
method looks solid. However, consider adding validation to ensure that the user has permission to move the form to the target workspace. This prevents unauthorized workspace changes and enhances security.Additionally, it's a good practice to check if the form already belongs to the target workspace before proceeding with the update. This can save unnecessary database operations.
routes/api.php (1)
- 93-93: The new route for updating a form's workspace is correctly defined and follows the RESTful API conventions. However, ensure that appropriate middleware is applied to this route to enforce authentication and authorization checks, safeguarding against unauthorized access.
client/components/pages/forms/show/ExtraMenu.vue (2)
- 110-120: The addition of the "Change workspace" link in the form menu is implemented correctly. However, consider adding an
aria-label
to the link for improved accessibility, providing screen reader users with context about the action.- 166-166: The integration of the
FormWorkspaceModal
component is done correctly. It's good practice to conditionally render components based on the state (showFormWorkspaceModal
) to improve performance by not rendering the component until needed.
<script setup> | ||
import { ref, defineProps, defineEmits, computed } from 'vue' | ||
const emit = defineEmits(['close']) | ||
const workspacesStore = useWorkspacesStore() | ||
const formsStore = useFormsStore() | ||
|
||
const selectedWorkspace = ref(null); | ||
const props = defineProps({ | ||
show: { type: Boolean, required: true }, | ||
form: { type: Object, required: true }, | ||
}) | ||
const workspaces = computed(() => workspacesStore.getAll) | ||
const workspace = computed(() => workspacesStore.getByKey(props.form?.workspace_id)) | ||
const loading = ref(false) | ||
const workspacesSelectOptions = computed(()=> workspaces.value.filter((w)=>{ | ||
return w.id !== workspace.value.id | ||
}).map(workspace => ({ name: workspace.name, value: workspace.id }))) | ||
|
||
|
||
const onSubmit = () => { | ||
const endpoint = '/open/forms/' + props.form.id + '/workspace/' + selectedWorkspace.value | ||
if(! selectedWorkspace.value) { | ||
useAlert().error('Please select a workspace!') | ||
return; | ||
} | ||
opnFetch(endpoint, { method: 'POST' }).then(data => { | ||
loading.value = false; | ||
emit('close') | ||
useAlert().success('Form workspace updated successfully.') | ||
workspacesStore.setCurrentId(selectedWorkspace.value) | ||
formsStore.resetState() | ||
formsStore.loadAll(selectedWorkspace.value) | ||
const router = useRouter() | ||
const route = useRoute() | ||
if (route.name !== 'home') { | ||
router.push({ name: 'home' }) | ||
} | ||
formsStore.loadAll(selectedWorkspace.value) | ||
}).catch((error) => { | ||
useAlert().error(err?.data?.message ?? 'Something went wrong, please try again!') | ||
loading.value = false; | ||
}) | ||
} | ||
|
||
const isUrl = (str) => { | ||
try { | ||
new URL(str) | ||
} catch (_) { | ||
return false | ||
} | ||
return true | ||
} | ||
</script> |
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.
In the onSubmit
method, there's a potential issue with how errors are handled. Specifically, the catch block references err
which is not defined within its scope. It should be error
as per the catch block's parameter.
- useAlert().error(err?.data?.message ?? 'Something went wrong, please try again!')
+ useAlert().error(error?.data?.message ?? 'Something went wrong, please try again!')
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
<script setup> | |
import { ref, defineProps, defineEmits, computed } from 'vue' | |
const emit = defineEmits(['close']) | |
const workspacesStore = useWorkspacesStore() | |
const formsStore = useFormsStore() | |
const selectedWorkspace = ref(null); | |
const props = defineProps({ | |
show: { type: Boolean, required: true }, | |
form: { type: Object, required: true }, | |
}) | |
const workspaces = computed(() => workspacesStore.getAll) | |
const workspace = computed(() => workspacesStore.getByKey(props.form?.workspace_id)) | |
const loading = ref(false) | |
const workspacesSelectOptions = computed(()=> workspaces.value.filter((w)=>{ | |
return w.id !== workspace.value.id | |
}).map(workspace => ({ name: workspace.name, value: workspace.id }))) | |
const onSubmit = () => { | |
const endpoint = '/open/forms/' + props.form.id + '/workspace/' + selectedWorkspace.value | |
if(! selectedWorkspace.value) { | |
useAlert().error('Please select a workspace!') | |
return; | |
} | |
opnFetch(endpoint, { method: 'POST' }).then(data => { | |
loading.value = false; | |
emit('close') | |
useAlert().success('Form workspace updated successfully.') | |
workspacesStore.setCurrentId(selectedWorkspace.value) | |
formsStore.resetState() | |
formsStore.loadAll(selectedWorkspace.value) | |
const router = useRouter() | |
const route = useRoute() | |
if (route.name !== 'home') { | |
router.push({ name: 'home' }) | |
} | |
formsStore.loadAll(selectedWorkspace.value) | |
}).catch((error) => { | |
useAlert().error(err?.data?.message ?? 'Something went wrong, please try again!') | |
loading.value = false; | |
}) | |
} | |
const isUrl = (str) => { | |
try { | |
new URL(str) | |
} catch (_) { | |
return false | |
} | |
return true | |
} | |
</script> | |
useAlert().error(error?.data?.message ?? 'Something went wrong, please try again!') |
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- app/Http/Controllers/Forms/FormController.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- app/Http/Controllers/Forms/FormController.php
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- client/components/open/forms/components/FormWorkspaceModal.vue (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- client/components/open/forms/components/FormWorkspaceModal.vue
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.
Great work @madassdev! For next time: even if not mentioned, it's always best to add a test case when adding new API endpoints 👍
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- routes/api.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- routes/api.php
Summary by CodeRabbit