SHARE
TWEET

Untitled

a guest Sep 19th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  //function manimpulasi datasource API
  2.   const retriveDataSourceStageView = async () => {
  3.      await getStage_View().then(response => {
  4.       props.retriveDataSourceStage(response);
  5.       const rows = response.map(item => ({
  6.         stageId: item.id,
  7.         stage: item.code,
  8.         hour: ''
  9.       }));
  10.       setDataRows(rows)
  11.       setIsFetching(true);
  12.     })
  13.     .catch(err => {
  14.       console.log(err);
  15.     });
  16.   };
  17.  
  18.  
  19.   //function manipulasi data curriculum detail
  20.   const retriveDetailDataCurriculum = async () => {
  21.     setIsFetching(true);
  22.     await getDetailCurriculum_View(props.match.params.id).then(response => {
  23.        props.retriveDataDetailCurriculum(response);
  24.          let convertedData = [];
  25.          if (DataRows) {
  26.            response.details.forEach(defDat => {
  27.              if (!convertedData.find(search => search.subjectId == defDat.subjectId)) {
  28.                convertedData.push({
  29.                  rowId: v4(),
  30.                  subjectId: defDat.subjectId,
  31.                  subject: defDat.subject,
  32.                  rowData: DataRows
  33.                });
  34.              }
  35.  
  36.              // ambil index subject yg rowData-nya akan di-udpate
  37.              const index = convertedData.map(conv => conv.subjectId).indexOf(defDat.subjectId);
  38.              // ini dapet subject kaya di .push()
  39.              // harus deepClone, kalau tidak, rowData-nya jadi sama semua
  40.              const currentObj = JSON.parse(JSON.stringify(convertedData[index]));
  41.              //  rowData yg akan di-edit
  42.              let currentRowData = [...currentObj.rowData];
  43.              currentRowData = [...currentRowData].map(rowCell => {
  44.                // row yg stageId-nya sama saja yg di-update, kalau tak ada, tak perlu update
  45.                if (currentObj.subjectId == defDat.subjectId && rowCell.stageId == defDat.stageId) {
  46.                  rowCell.hour = defDat.hour;
  47.                }
  48.                return rowCell;
  49.              });
  50.              convertedData[index] = {
  51.                ...convertedData[index],
  52.                rowData: currentRowData
  53.              };
  54.            });
  55.          } else {
  56.            console.log('loadingggggg............');
  57.          }
  58.          // end of default data foreach
  59.          setDataRowsCurriculum(convertedData);
  60.          setIsFetching(false);
  61.     });
  62.   };
  63.  
  64.  
  65.   //manggil function data stage
  66.   console.log('data rows', DataRows);
  67.   //manggil function data curriculum
  68.   console.log('data detail', DataRowsCurriculum);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top