Folder structure, components naming and importing conventions
Our folder structure and file naming follows modern frontend project guidelines, https://react-file-structure.surge.sh/
List of rules we agreed on:
Filenames and folder structure:
Each component should have it’s own folder eg:
src/components/ebo-modal/ebo-modal.vuesrc/components/ebo-modal/index.js
Global reusable components should be in /src/components/folder, view or feature related components should be siting in the components folder in the view or feature folder, see the example from previous rule.
Components in a view or feature should not repeat the name of the view in the filename eg:
- Bad:
src/views/dashboard/funding-account/components/ebo-funding-account-currencies-dropdown/ebo-funding-account-currencies-dropdown.vue - Good:
src/views/dashboard/funding-account/components/currencies-dropdown/currencies-dropdown.vue
Components in a view or feature should not have their filename prefixed with ebo-, only global components should eg:
- Bad:
src/components/modal/modal.vueorsrc/views/dashboard/funding-account/components/ebo-currencies-dropdown/ebo-currencies-dropdown.vue - Good:
src/components/ebo-modal/ebo-modal.vueorsrc/views/dashboard/funding-account/components/currencies-dropdown/currencies-dropdown.vue
Importing components in the views:
Import name should be always in format Ebo
- Bad:
import Modal from '@/components/ebo-modal'orimport EboDashboardModal from '@/components/ebo-modal' - Good:
import EboModal from '@/components/ebo-modal'
NOTE: If you think the parent name is too long and doesn’t make sense to have the name of the component, try to categorise the component into a feature, to break down the folder tree: eg:
- Not very good name:
/trade-finance/submitted-requests/components/add-suppliers-modal/add-suppliers-modal.vueimported as:EboSubmittedRequestsAddSuppliersModal - Better name:
/trade-finance/submitted-requests/suppliers/components/add-modal/add-modal.vueimported as:EboSuppliersAddModal
Name of the component, CSS class, data-test, describe() and mount()
All of them should follow the same rule as the import name. eg:
/dashboard/funding-account/components/currencies-dropdown/currencies-dropdown.vue
<template>
<div class="ebo-funding-account-currencies-dropdown"
data-test="ebo-funding-account-currencies-dropdown">
...
</div>
</template>
<script>
export default {
name: 'EboFundingAccountCurrenciesDropdown',
...
}
</script>
/dashboard/funding-account/components/currencies-dropdown/currencies-dropdown.spec.js
describe('EboFundingAccountCurrenciesDropdown', () => {
function mountEboFundingAccountCurrenciesDropdown() {
// ...
}
});