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

Refactor source [ch124583] #165

Merged
merged 39 commits into from
Jan 27, 2021
Merged

Conversation

Clebal
Copy link
Contributor

@Clebal Clebal commented Jan 22, 2021

  • Refactored data & source structure in template-sample-app.
  • Refactored hygen layer to fit new structure.
  • Added hygen source to generate sources.
  • Refactored data & source structure in template-skeleton.
  • Added documentation.

From this CH ticket.

Proposal: #164.

@shortcut-integration
Copy link

This pull request has been linked to Clubhouse Story #124583: Refactor source.

@vercel
Copy link

vercel bot commented Jan 22, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/carto-frontend/cra-template-carto/d4fy2lfjq
✅ Preview: https://cra-template-carto-git-feature-ch124583refactor-source.carto-frontend.vercel.app

hygen/_templates/layer/new/prompt.js Outdated Show resolved Hide resolved
Comment on lines 94 to 101
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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved:

Suggested change
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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chapó 👌

Comment on lines 24 to 27
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'));
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertoarana fixed.

Comment on lines 35 to 37
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.`);
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

hygen/_templates/source/new/source.ejs.t Show resolved Hide resolved
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,
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Collaborator

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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}
Copy link
Contributor

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
Copy link
Contributor

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 VictorVelarde changed the base branch from develop to master January 25, 2021 16:46
@aaranadev
Copy link
Collaborator

@VictorVelarde I like suggestion. We are going to change it

@aaranadev
Copy link
Collaborator

Done. I have needed to change the file names to camelCase.

@@ -0,0 +1,19 @@
export const KPI_SOURCE_ID = 'kpiSource';
Copy link
Contributor

@alasarr alasarr Jan 26, 2021

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

Copy link
Contributor

@VictorVelarde VictorVelarde left a 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

@VictorVelarde VictorVelarde merged commit 8e37ab1 into master Jan 27, 2021
@VictorVelarde VictorVelarde deleted the feature/ch124583/refactor-source branch January 27, 2021 20:36
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.

None yet

4 participants