Skip to content

Commit 479447f

Browse files
committed
fetch config before dialog
1 parent 08b2fad commit 479447f

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

src/dashboard/Data/Config/Config.react.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ class Config extends TableView {
5858
this.loadData();
5959
}
6060

61-
loadData() {
61+
async loadData() {
6262
this.setState({ loading: true });
63-
this.props.config.dispatch(ActionTypes.FETCH).finally(() => {
63+
try {
64+
await this.props.config.dispatch(ActionTypes.FETCH);
6465
this.cacheData = new Map(this.props.config.data);
66+
} finally {
6567
this.setState({ loading: false });
66-
});
68+
}
6769
}
6870

6971
renderToolbar() {
@@ -133,8 +135,8 @@ class Config extends TableView {
133135
return extras;
134136
}
135137

136-
renderRow(data) {
137-
let value = data.value;
138+
parseValueForModal(dataValue) {
139+
let value = dataValue;
138140
let modalValue = value;
139141
let type = typeof value;
140142

@@ -149,11 +151,11 @@ class Config extends TableView {
149151
} else if (value instanceof Parse.GeoPoint) {
150152
type = 'GeoPoint';
151153
value = `(${value.latitude}, ${value.longitude})`;
152-
modalValue = data.value.toJSON();
153-
} else if (data.value instanceof Parse.File) {
154+
modalValue = dataValue.toJSON();
155+
} else if (dataValue instanceof Parse.File) {
154156
type = 'File';
155157
value = (
156-
<a target="_blank" href={data.value.url()} rel="noreferrer">
158+
<a target="_blank" href={dataValue.url()} rel="noreferrer">
157159
Open in new window
158160
</a>
159161
);
@@ -168,14 +170,53 @@ class Config extends TableView {
168170
}
169171
type = type.substr(0, 1).toUpperCase() + type.substr(1);
170172
}
171-
const openModal = () =>
173+
174+
return {
175+
value: value,
176+
modalValue: modalValue,
177+
type: type,
178+
};
179+
}
180+
181+
renderRow(data) {
182+
// Parse modal data
183+
const { value, modalValue, type } = this.parseValueForModal(data.value);
184+
185+
/**
186+
* Opens the modal dialog to edit the Config parameter.
187+
*/
188+
const openModal = async () => {
189+
190+
// Show dialog
172191
this.setState({
192+
loading: true,
173193
modalOpen: true,
174194
modalParam: data.param,
175195
modalType: type,
176196
modalValue: modalValue,
177197
modalMasterKeyOnly: data.masterKeyOnly,
178198
});
199+
200+
// Fetch config data
201+
await this.loadData();
202+
203+
// Get latest param values
204+
const fetchedParams = this.props.config.data.get('params');
205+
const fetchedValue = fetchedParams.get(this.state.modalParam);
206+
const fetchedMasterKeyOnly = this.props.config.data.get('masterKeyOnly')?.get(this.state.modalParam) || false;
207+
208+
// Parse fetched data
209+
const { modalValue: fetchedModalValue } = this.parseValueForModal(fetchedValue);
210+
211+
// Update dialog
212+
this.setState({
213+
modalValue: fetchedModalValue,
214+
modalMasterKeyOnly: fetchedMasterKeyOnly,
215+
loading: false,
216+
});
217+
};
218+
219+
// Define column styles
179220
const columnStyleLarge = { width: '30%', cursor: 'pointer' };
180221
const columnStyleSmall = { width: '15%', cursor: 'pointer' };
181222

src/dashboard/Data/Config/ConfigDialog.react.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ export default class ConfigDialog extends React.Component {
181181
});
182182
}
183183

184+
componentDidUpdate(prevProps) {
185+
// Update parameter value or masterKeyOnly if they have changed
186+
if (this.props.value !== prevProps.value || this.props.masterKeyOnly !== prevProps.masterKeyOnly) {
187+
this.setState({
188+
value: this.props.value,
189+
masterKeyOnly: this.props.masterKeyOnly,
190+
});
191+
}
192+
}
193+
184194
render() {
185195
const newParam = !this.props.param;
186196
const typeDropdown = (

0 commit comments

Comments
 (0)