-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from t3-innovation-network/staging
Release 09/25/24
- Loading branch information
Showing
26 changed files
with
311 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/javascript/components/align-and-fine-tune/AlignmentTransformation.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { useLocalStore } from 'easy-peasy'; | ||
import Modal from 'react-modal'; | ||
import updateAlignment from '../../services/updateAlignment'; | ||
import AlertNotice from '../shared/AlertNotice'; | ||
import ModalStyles from '../shared/ModalStyles'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faLeftRight, faTimes } from '@fortawesome/free-solid-svg-icons'; | ||
import { transformationAlignmentStore } from './stores/transformationAlignmentStore'; | ||
import useDidMountEffect from '../../helpers/useDidMountEffect'; | ||
import { i18n } from 'utils/i18n'; | ||
|
||
const AlignmentTransformation = (props) => { | ||
Modal.setAppElement('body'); | ||
|
||
const { alignment, isOpen, onUpdate, onClose } = props; | ||
const [state, actions] = useLocalStore(() => | ||
transformationAlignmentStore({ | ||
transformation: alignment?.transformation || {}, | ||
initialData: alignment?.transformation || {}, | ||
}) | ||
); | ||
const { transformation, withChanges } = state; | ||
|
||
const handleToChange = (e) => actions.handleChange({ to: e.target.value }); | ||
const handleFromChange = (e) => actions.handleChange({ from: e.target.value }); | ||
|
||
const handleSave = async () => { | ||
actions.setLoading(true); | ||
try { | ||
let response = await updateAlignment({ | ||
id: alignment.id, | ||
transformation, | ||
}); | ||
|
||
if (response.error) { | ||
actions.setError(response.error); | ||
return; | ||
} | ||
|
||
onUpdate({ saved: true, transformation }); | ||
} finally { | ||
actions.setLoading(false); | ||
} | ||
}; | ||
|
||
useDidMountEffect(() => { | ||
if (isOpen) actions.setTransformation(alignment?.transformation); | ||
}, [isOpen]); | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onRequestClose={onClose} | ||
contentLabel={i18n.t('ui.mapping.transformation.title')} | ||
style={ModalStyles} | ||
shouldCloseOnEsc={true} | ||
shouldCloseOnOverlayClick={true} | ||
> | ||
<div className="card"> | ||
<div className="card-header"> | ||
<FontAwesomeIcon icon={faLeftRight} className="col-primary" /> | ||
<a className="float-right cursor-pointer" onClick={onClose}> | ||
<FontAwesomeIcon icon={faTimes} /> | ||
</a> | ||
</div> | ||
<div className="card-body"> | ||
{state.hasErrors && <AlertNotice message={state.errors} onClose={actions.clearErrors} />} | ||
<div className="row"> | ||
<div className="col col-12 form-group"> | ||
<label>{i18n.t('ui.mapping.transformation.form.to.label')}</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
placeholder={i18n.t('ui.mapping.transformation.form.to.placeholder')} | ||
value={transformation.to || ''} | ||
onChange={handleToChange} | ||
autoFocus | ||
/> | ||
</div> | ||
<div className="col col-12 form-group"> | ||
<label>{i18n.t('ui.mapping.transformation.form.from.label')}</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
placeholder={i18n.t('ui.mapping.transformation.form.from.placeholder')} | ||
value={transformation.from || ''} | ||
onChange={handleFromChange} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col"> | ||
<button | ||
className="btn btn-dark mt-3 mr-3" | ||
onClick={handleSave} | ||
disabled={!withChanges || state.loading} | ||
> | ||
{i18n.t('ui.mapping.transformation.form.save')} | ||
</button> | ||
<button | ||
className="btn btn-link mt-3 col-primary" | ||
onClick={onClose} | ||
disabled={state.loading} | ||
> | ||
{i18n.t('ui.buttons.cancel')} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AlignmentTransformation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/javascript/components/align-and-fine-tune/stores/transformationAlignmentStore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { action, computed } from 'easy-peasy'; | ||
import { baseModel } from '../../stores/baseModel'; | ||
import { easyStateSetters } from '../../stores/easyState'; | ||
import { assign, isEqual } from 'lodash'; | ||
|
||
export const defaultState = { | ||
// status | ||
loading: false, | ||
// options | ||
// data | ||
initialData: {}, | ||
transformation: {}, | ||
}; | ||
|
||
export const transformationAlignmentStore = (initialData = {}) => ({ | ||
...baseModel(initialData), | ||
...easyStateSetters(defaultState, initialData), | ||
|
||
// computed | ||
withChanges: computed((state) => !isEqual(state.transformation, state.initialData)), | ||
|
||
// actions | ||
handleChange: action((state, payload) => { | ||
assign(state.transformation, payload); | ||
}), | ||
// thunks | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.