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

move form to another workspace #339

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Conversation

madassdev
Copy link
Collaborator

@madassdev madassdev commented Mar 8, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a feature allowing users to change the workspace of a form, including a new modal for workspace selection and navigation enhancements post-update.
    • Added a new option in the form's extra menu to facilitate workspace changes.

@madassdev madassdev requested a review from JhumanJ March 8, 2024 13:34
Copy link
Contributor

coderabbitai bot commented Mar 8, 2024

Walkthrough

This 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 FormWorkspaceModal.vue Vue component. The backend supports this functionality with a new method in the FormController to update the form's workspace and creator ID. Additionally, the ExtraMenu.vue component provides a menu link for accessing the workspace change feature, and an API route in api.php enables updating a form's workspace based on its ID and workspace ID.

Changes

File Path Change Summary
app/Http/Controllers/Forms/FormController.php Added updateWorkspace method to update a form's workspace and creator ID.
client/components/open/forms/components/FormWorkspaceModal.vue Introduced FormWorkspaceModal Vue component for changing a form's workspace via a modal.
client/components/pages/forms/show/ExtraMenu.vue Added workspace change link, initialized modal visibility control, and included FormWorkspaceModal component.
routes/api.php Added new API route in the forms group to update a form's workspace based on its ID and workspace ID.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 30587fb and d830939.
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.

Comment on lines 51 to 103
<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>
Copy link
Contributor

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.

Suggested change
<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!')

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between d830939 and a6b185b.
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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between a6b185b and 356ad47.
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

Copy link
Owner

@JhumanJ JhumanJ left a 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 👍

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 356ad47 and bb0227b.
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

@JhumanJ JhumanJ merged commit 29fdc96 into main Mar 12, 2024
5 checks passed
@JhumanJ JhumanJ deleted the c0656-moved-form-to-another-workpace branch March 12, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants