Skip to content

add period dates action. script to migrate existing data #478

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

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

eperedo
Copy link
Contributor

@eperedo eperedo commented Feb 9, 2025

📌 References

📝 Implementation

  • create new attribute for period dates (metadata in issue)
  • add action to dataSet list
  • script to migrate existing data to new attribute
 npx ts-node src/scripts/migrate-dataset-period-dates.ts -u 'http://localhost:8080' --username 'username' --password 'password'

📹 Screenshots/Screen capture

Project-Configuration-app-period_dates.webm

🔥 Notes to the tester

#8695uy4nz

@eperedo eperedo requested a review from MiquelAdell February 9, 2025 19:23
@MiquelAdell MiquelAdell merged commit efff939 into feature/logs Feb 19, 2025
1 check passed
@MiquelAdell MiquelAdell requested a review from tokland February 20, 2025 12:31
@MiquelAdell
Copy link
Contributor

@tokland I merged this PR in a rush but, whenever you have time, I would like to provide a code review anyway and we can have a different PR with the changes if needed.

Thanks!

Copy link
Collaborator

@tokland tokland left a comment

Choose a reason for hiding this comment

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

[code-only review] Already merged, but still requested by @MiquelAdell. In-line comments:

onSave: (periodDate: PeriodDate) => void;
};

function useGetYears(props: { period: PeriodDate }) {
Copy link
Collaborator

@tokland tokland Feb 26, 2025

Choose a reason for hiding this comment

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

Typically, we put props+component+hooks/helper functions

})}
</PeriodsContainer>
)}
</ConfirmationDialog>
Copy link
Collaborator

@tokland tokland Feb 26, 2025

Choose a reason for hiding this comment

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

We may add a blank line between non-single-line components at the same indentation level (for example 129/130)

label={i18n.t("End date of data input")}
minDate={periodDate.startDate}
className="datepicker"
format="yyyy-MM-DD"
Copy link
Collaborator

@tokland tokland Feb 26, 2025

Choose a reason for hiding this comment

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

repeated prop format. Either a variable or a wrapper component that adds common props.

const onUpdatePeriodDate = (date: string, fieldName: "startDate" | "endDate") => {
const newValues = periodDate?.setDates(date, fieldName);
setPeriodDate(newValues);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to custom hook

console.debug(JSON.stringify(response, null, 4));
},
error => {
console.error(error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[good practices] process.exit(1) on the error branch

}

setDates(date: string, fieldName: "startDate" | "endDate"): PeriodDate {
return this._update({ [fieldName]: date });
Copy link
Collaborator

@tokland tokland Feb 26, 2025

Choose a reason for hiding this comment

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

That's unfortunate, but TS does not enforce type-safety when building objects from dynamic keys:

microsoft/TypeScript#13948

A 100% type-safe workaround is using: const newAttrs = fromPairs([[fieldName, date]]) (fromPairs from ts-utils or EST lodash should both work)

@@ -54,6 +53,31 @@ export function convertToCategories(d2Categories: D2Category[]): Category[] {
}));
}

export function convertAttributeValueToDate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a very specific non-generic function, utils.ts probably is not be the best place.

periodDate: PeriodDate;
outcomeDate: PeriodDate;
outputDate: PeriodDate;
};
Copy link
Collaborator

@tokland tokland Feb 26, 2025

Choose a reason for hiding this comment

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

[no need to change]

I see you created an entity+repo for DataSetPeriodDate.

This is something we have been discussing lately, and I'd like to confirm with @xurxodev, but from our last chat about this, he stated that having different "flavors" or entities is not correct. I see two alternatives:

  • Add these 3 fields would be in DataSet. I think this is the most simple option. And then we simply improve the existing DataSet/DataSetRepository. You may then say that we typically don't need them and getting the info from the attribute is very costly (i don't think it's the case here). Then we'd see alternatives.

-Have a DataSetPeriodDate, but not as flavor, but as its own entity. So having dataSetId: Id + 3 fields. Typically we do this if the entity has sense in isolation. Here it's 1:1 relation, it does not seem a typical case for this.

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.

3 participants