-
Notifications
You must be signed in to change notification settings - Fork 26
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
Refactor source [ch124583] #165
Conversation
Refactored hygen layer to fit new structure. Added hygen source to generate sources.
This pull request has been linked to Clubhouse Story #124583: Refactor source. |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/carto-frontend/cra-template-carto/d4fy2lfjq |
hygen/_templates/layer/new/prompt.js
Outdated
if (answers.view.includes('views/')) { | ||
const selectedViewInitialPath = answers.view.split('(')[1].replace(')', ''); | ||
answers.view_path = viewFiles.find(viewFile => { | ||
return viewFile.path === selectedViewInitialPath.replace('views', VIEWS_DIR) | ||
}).path | ||
} else { | ||
answers.view_path = VIEWS_DIR | ||
} |
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.
Improved:
if (answers.view.includes('views/')) { | |
const selectedViewInitialPath = answers.view.split('(')[1].replace(')', ''); | |
answers.view_path = viewFiles.find(viewFile => { | |
return viewFile.path === selectedViewInitialPath.replace('views', VIEWS_DIR) | |
}).path | |
} else { | |
answers.view_path = VIEWS_DIR | |
} | |
answers.view_path = VIEWS_DIR | |
if (answers.view.includes('views/')) { | |
const selectedViewInitialPath = answers.view.split('(')[1].replace(')', ''); | |
answers.view_path = viewFiles.find(viewFile => { | |
return viewFile.path === selectedViewInitialPath.replace('views', VIEWS_DIR) | |
}).path | |
} |
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.
Chapó 👌
hygen/_templates/promptUtils.js
Outdated
return files | ||
.reduce((a, f) => a.concat(f), []) | ||
.map(file => (typeof file === 'string' ? { path: file.split('src/')[file.split('src/').length - 1], name: file.split('/')[file.split('/').length - 1] } : file)) | ||
.filter(({ name }) => /[A-Z]/.test(name[0]) && name.includes('.js')); |
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 map maybe be a reducer and the filter function is included.
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.
@albertoarana fixed.
const fileName = [answers.name[0].toUpperCase(), ...answers.name.slice(1, answers.name.length)].join('') | ||
const doesSourceAlreadyExists = await doesFileExists(['src', 'data', 'sources', `${fileName}Source.js`]); | ||
if (doesSourceAlreadyExists) throw new Error(`The source ${answers.name} already exists.`); |
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.
If source already exists, the code is executed but nothing happens because hygen has the skip
flag if that source exists.
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.
Fixed.
Co-authored-by: Alberto Arana <aarana@carto.com>
@@ -28,7 +28,7 @@ export default function StoresLayer() { | |||
|
|||
if (storesLayer && source) { | |||
return new CartoSQLLayer({ | |||
id: 'storesPointLayer', | |||
id: LayerStyle.id, |
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.
I think id should be extracted from LayerStyle object, as it is conceptually not included inside style props, what do you think?
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.
An exported const at the top could be useful, as with sources
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.
@VictorVelarde that change is contemplated in the next PR where @Clebal modifies the generator Layer
|
||
export default function Kpi() { | ||
const dispatch = useDispatch(); | ||
|
||
const LAYER_ID = 'kpiLayer'; |
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.
After the good refactor you have done on Source, removing the const here and exposing it from the 'source' file, I think we should probably do the same for layers: exporting a const with the 'id' from each Layer file, and consuming it here with kpiLayer.id. That way, there is just one place for the LAYER_ID, and that is the layer itself, which IMO it makes sense...
what do you think?
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.
It's being done in #167.
column='name' | ||
operationColumn='revenue' | ||
dataSource={kpiSource.id} | ||
column={KPI_SOURCE_COLUMNS.NAME} |
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.
this looks nice!
@@ -55,6 +55,8 @@ function Datasets() { | |||
}; | |||
}, [credentials, dispatch]); | |||
|
|||
// Auto import useEffect | |||
|
|||
return ( | |||
<Grid |
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.
We're gonna remove this file (all related to that tab), but I'll wait till this gets merged, to avoid any conflict
@VictorVelarde I like suggestion. We are going to change it |
Done. I have needed to change the file names to camelCase. |
@@ -0,0 +1,19 @@ | |||
export const KPI_SOURCE_ID = 'kpiSource'; |
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.
I'd simplify this to only export the default.
It adds a data structure that it's not required and it adds complexity in several parts of the code.
KPI_SOURCE_ID is available as default.id
KPI_SOURCE_COLUMNS is like have two ways to define the source: at the SQL and the const.
It's a key concept for new users and we need to simplify this as much as possible.
If someone wants to complicate more to have a more robust architecture is fine, but not for all the users
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.
Fixed some conflicts after merging client-side PR
From this CH ticket.
Proposal: #164.