Skip to content

Commit

Permalink
feat: change flow to save updated attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Apr 1, 2024
1 parent 9aa7703 commit d9bd447
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions app/packs/src/components/container/ContainerDatasetModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class ContainerDatasetModal extends Component {
this.handleSwitchMode = this.handleSwitchMode.bind(this);
this.handleModalClose = this.handleModalClose.bind(this);
this.handleSaveWithoutClose = this.handleSaveWithoutClose.bind(this);
// this.onLoadingStoreChange = this.onLoadingStoreChange.bind(this);
this.onLoadingStoreChange = this.onLoadingStoreChange.bind(this);
}

componentDidMount() {
Expand All @@ -37,7 +37,7 @@ export default class ContainerDatasetModal extends Component {
onLoadingStoreChange(state) {
const { loading } = state;
if (!loading) {
UIActions.saveAttachmentDataset.defer('', false);
UIActions.saveAttachmentDataset.defer('', false, '');
}
}

Expand Down Expand Up @@ -66,7 +66,8 @@ export default class ContainerDatasetModal extends Component {
});

const { elementID, templateType } = this.props;
UIActions.saveAttachmentDataset(elementID, templateType);
const datasetID = this.datasetInput.current.state.datasetContainer.id;
UIActions.saveAttachmentDataset(elementID, templateType, datasetID);
}

handleNameChange(newName) {
Expand Down
11 changes: 7 additions & 4 deletions app/packs/src/components/container/ContainerDatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ContainerDatasets extends Component {
},
};
if (isSaving && datasetContainer) {
UIActions.saveAttachmentDataset.defer('', false);
UIActions.saveAttachmentDataset.defer('', false, datasetContainer.id);
this.state.modal = { show: true, datasetContainer: datasetContainer };
}
}
Expand All @@ -53,11 +53,14 @@ export default class ContainerDatasets extends Component {
const prevChildren = prevProps.container.children;
const childrenIds = children.map((item) => item.id);
const prevChildrenIds = prevChildren.map((item) => item.id);
const diffIds = childrenIds.filter((id) => !prevChildrenIds.includes(id));
let diffIds = childrenIds.filter((id) => !prevChildrenIds.includes(id));
const uiStoreContainerDataSet = (UIStore.getState() && UIStore.getState().containerDataSet) || { isSaving: false };
const { isSaving } = uiStoreContainerDataSet;
const { isSaving, datasetID } = uiStoreContainerDataSet;
if (isSaving) {
UIActions.saveAttachmentDataset.defer('', false);
if (diffIds.length === 0) {
diffIds = [datasetID];
}
UIActions.saveAttachmentDataset.defer('', false, datasetID);
const filterChildren = children.filter((item) => diffIds.includes(item.id));
const datasetContainer = filterChildren.length > 0 ? filterChildren[0] : null;
this.setState({
Expand Down
4 changes: 2 additions & 2 deletions app/packs/src/stores/alt/actions/UIActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class UIActions {
rerenderGenericWorkflow(params) { return params; }
showGenericWorkflowModal(show) { return show; }

saveAttachmentDataset(elementID, templateType) {
return { elementID: elementID, elementType: templateType};
saveAttachmentDataset(elementID, templateType, datasetID) {
return { elementID: elementID, elementType: templateType, datasetID: datasetID};
}
}

Expand Down
5 changes: 3 additions & 2 deletions app/packs/src/stores/alt/stores/UIStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,12 @@ class UIStore {

handleSaveAttachmentDataset(data) {
const { isSaving } = this.state.containerDataSet;
const { elementID, elementType } = data;
const { elementID, elementType, datasetID } = data;
this.state.containerDataSet = {
elementID: elementID,
elementType: elementType,
isSaving: !isSaving
isSaving: !isSaving,
datasetID: datasetID,
}
}
}
Expand Down

0 comments on commit d9bd447

Please sign in to comment.