Skip to content

Commit

Permalink
Merge pull request opensearch-project#5 from wanglam/fix-check-status…
Browse files Browse the repository at this point in the history
…-disappear-after-modal-tab-change

Fix checked status disappear after modal tab change
  • Loading branch information
yubonluo authored Aug 28, 2024
2 parents 724170e + 28a62aa commit fe9635e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const AssociationDataSourceModal = ({

const handleSelectionChange = useCallback(
(newOptions: DataSourceModalOption[]) => {
const displayedConnectionIds = newOptions.map(({ connection }) => connection.id);
const newCheckedConnectionIds = newOptions
.filter(({ checked }) => checked === 'on')
.map(({ connection }) => connection.id);
Expand All @@ -129,12 +130,18 @@ export const AssociationDataSourceModal = ({
option = { ...option };
const checkedInNewOptions = newCheckedConnectionIds.includes(option.connection.id);
const connection = option.connection;
option.checked = checkedInNewOptions ? 'on' : undefined;
// Some connections may hidden by different tab, we should not update checked status for these connections
if (displayedConnectionIds.includes(connection.id)) {
option.checked = checkedInNewOptions ? 'on' : undefined;
}

// Set option to 'on' if checked status of any child DQC become 'on' this time
if (connection.connectionType === DataSourceConnectionType.OpenSearchConnection) {
const childDQCIds = allConnections
.filter(({ parentId }) => parentId === connection.id)
.map(({ id }) => id);
.map(({ id }) => id)
// Ensure all child DQCs has been displayed, or the checked status should not been updated
.filter((id) => displayedConnectionIds.includes(id));
// Check if there any DQC change to checked status this time, set to "on" if exists.
if (
newCheckedConnectionIds.some(
Expand All @@ -148,9 +155,11 @@ export const AssociationDataSourceModal = ({
}
}

// Set option to 'on' if checked status of parent data source become 'on' this time
if (connection.connectionType === DataSourceConnectionType.DirectQueryConnection) {
const parentConnection = allConnections.find(({ id }) => id === connection.parentId);
if (parentConnection) {
// Ensure parent connection has been displayed, or the checked status should not been changed.
if (parentConnection && displayedConnectionIds.includes(parentConnection.id)) {
const isParentCheckedLastTime = !!prevOptions.find(
(item) => item.connection.id === parentConnection.id && item.checked === 'on'
);
Expand Down

0 comments on commit fe9635e

Please sign in to comment.