Skip to content

Commit

Permalink
Display more accurate infoAlertText on columns with locked data type
Browse files Browse the repository at this point in the history
Make a call to the columns api to check if the referent column is a
primary key and show appropriate message in InfoBox based on that.
  • Loading branch information
ejenk0 committed Oct 25, 2023
1 parent 6e11407 commit 946d97f
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import type { ColumnTypeOptionsSaveArgs } from '@mathesar/components/abstract-type-control/types';
import AbstractTypeSelector from '@mathesar/components/abstract-type-control/AbstractTypeSelector.svelte';
import InfoBox from '@mathesar/components/message-boxes/InfoBox.svelte';
import { getTable } from '@mathesar/stores/tables';
import { getAPI } from '@mathesar/api/utils/requestUtils';
import { columnsApi } from '@mathesar/api/columns';
const tabularData = getTabularDataStoreFromContext();
$: ({ columnsDataStore } = $tabularData);
Expand All @@ -30,15 +33,23 @@
...column.column,
abstractType: column.abstractType,
};
$: infoAlertText = (() => {
$: getInfoAlertText = async () => {
if (column.column.primary_key) {
return 'The data type of the primary key column is restricted and cannot be changed.';
}
if (column.linkFk) {
return 'The data type of the foreign key column is restricted to the data type of the primary key column and cannot be changed.';
const referentColumn = (
await columnsApi.list(column.linkFk.referent_table)
).results.find((col) => col.id === column.linkFk?.referent_columns[0]);
if (referentColumn?.primary_key) {
return 'The data type of the foreign key column is restricted to the data type of the primary key column it references and cannot be changed.';
} else {
return 'The data type of the foreign key column is restricted to the data type of the unique column it references and cannot be changed.';
}
}
return '';
})();
};
</script>

{#if disallowDataTypeChange}
Expand All @@ -47,13 +58,15 @@
column={columnWithAbstractType}
disabled={true}
/>
{#if infoAlertText}
<InfoBox>
<span class="info-alert">
{infoAlertText}
</span>
</InfoBox>
{/if}
{#await getInfoAlertText() then infoAlertText}
{#if infoAlertText}
<InfoBox>
<span class="info-alert">
{infoAlertText}
</span>
</InfoBox>
{/if}
{/await}
{:else}
{#key columnWithAbstractType}
<AbstractTypeControl column={columnWithAbstractType} {save} />
Expand Down

0 comments on commit 946d97f

Please sign in to comment.