Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function manimpulasi datasource API
- const retriveDataSourceStageView = async () => {
- await getStage_View().then(response => {
- props.retriveDataSourceStage(response);
- const rows = response.map(item => ({
- stageId: item.id,
- stage: item.code,
- hour: ''
- }));
- setDataRows(rows)
- setIsFetching(true);
- })
- .catch(err => {
- console.log(err);
- });
- };
- //function manipulasi data curriculum detail
- const retriveDetailDataCurriculum = async () => {
- setIsFetching(true);
- await getDetailCurriculum_View(props.match.params.id).then(response => {
- props.retriveDataDetailCurriculum(response);
- let convertedData = [];
- if (DataRows) {
- response.details.forEach(defDat => {
- if (!convertedData.find(search => search.subjectId == defDat.subjectId)) {
- convertedData.push({
- rowId: v4(),
- subjectId: defDat.subjectId,
- subject: defDat.subject,
- rowData: DataRows
- });
- }
- // ambil index subject yg rowData-nya akan di-udpate
- const index = convertedData.map(conv => conv.subjectId).indexOf(defDat.subjectId);
- // ini dapet subject kaya di .push()
- // harus deepClone, kalau tidak, rowData-nya jadi sama semua
- const currentObj = JSON.parse(JSON.stringify(convertedData[index]));
- // rowData yg akan di-edit
- let currentRowData = [...currentObj.rowData];
- currentRowData = [...currentRowData].map(rowCell => {
- // row yg stageId-nya sama saja yg di-update, kalau tak ada, tak perlu update
- if (currentObj.subjectId == defDat.subjectId && rowCell.stageId == defDat.stageId) {
- rowCell.hour = defDat.hour;
- }
- return rowCell;
- });
- convertedData[index] = {
- ...convertedData[index],
- rowData: currentRowData
- };
- });
- } else {
- console.log('loadingggggg............');
- }
- // end of default data foreach
- setDataRowsCurriculum(convertedData);
- setIsFetching(false);
- });
- };
- //manggil function data stage
- console.log('data rows', DataRows);
- //manggil function data curriculum
- console.log('data detail', DataRowsCurriculum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement