Skip to content

Commit

Permalink
update minor changes on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dieriba committed Feb 6, 2025
1 parent 90c9a13 commit d0759d8
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 115 deletions.
2 changes: 1 addition & 1 deletion frontend/src/lib/components/triggers/CaptureWrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
return false
}
if (invalidRelations(args.publication.table_to_track, true) === true) {
if (invalidRelations(args.publication.table_to_track, true, true) === true) {
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
}
async function updateTrigger(): Promise<void> {
if (selectedTable === 'specific' && invalidRelations(relations, true) === true) {
if (selectedTable === 'specific' && invalidRelations(relations, true, true) === true) {
return
}
if (edit) {
Expand Down Expand Up @@ -333,12 +333,47 @@
disabled={!can_write}
/>
</Label>
<Section label="Runnable">
<p class="text-xs text-tertiary">
Pick a script or flow to be triggered <Required required={true} />
</p>
<div class="flex flex-row mb-2">
<ScriptPicker
disabled={fixedScriptPath != '' || !can_write}
initialPath={fixedScriptPath || initialScriptPath}
kinds={['script']}
allowFlow={true}
bind:itemKind
bind:scriptPath={script_path}
allowRefresh
/>

{#if script_path === undefined && is_flow === false}
<div class="flex">
<Button
disabled={!can_write}
btnClasses="ml-4 mt-2"
color="dark"
size="xs"
on:click={getTemplateScript}
target="_blank"
{loading}
>Create from template
<Tooltip light>
The conversion requires a <strong>database resource</strong> and at least one
<strong>schema</strong>
to be set.<br />
Please ensure these conditions are met before proceeding.
</Tooltip>
</Button>
</div>
{/if}
</div>
</Section>
<Section label="Database">
<p class="text-xs text-tertiary">
<p class="text-xs text-tertiary mb-2">
Pick a database to connect to <Required required={true} />
</p>

<div class="flex flex-col gap-8">
<div class="flex flex-col gap-2">
<ResourcePicker
Expand Down Expand Up @@ -543,43 +578,6 @@
{/if}
</div>
</Section>
<Section label="Runnable">
<p class="text-xs text-tertiary">
Pick a script or flow to be triggered <Required required={true} />
</p>
<div class="flex flex-row mb-2">
<ScriptPicker
disabled={fixedScriptPath != '' || !can_write}
initialPath={fixedScriptPath || initialScriptPath}
kinds={['script']}
allowFlow={true}
bind:itemKind
bind:scriptPath={script_path}
allowRefresh
/>

{#if script_path === undefined && is_flow === false}
<div class="flex">
<Button
disabled={!can_write}
btnClasses="ml-4 mt-2"
color="dark"
size="xs"
on:click={getTemplateScript}
target="_blank"
{loading}
>Create from template
<Tooltip light>
The conversion requires a <strong>database resource</strong> and at least one
<strong>schema</strong>
to be set.<br />
Please ensure these conditions are met before proceeding.
</Tooltip>
</Button>
</div>
{/if}
</div>
</Section>
</div>
{/if}
</DrawerContent>
Expand Down
79 changes: 39 additions & 40 deletions frontend/src/lib/components/triggers/postgres/RelationPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { invalidRelations } from './utils'
import AddPropertyFormV2 from '$lib/components/schema/AddPropertyFormV2.svelte'
import Label from '$lib/components/Label.svelte'
import { emptyStringTrimmed, sendUserToast } from '$lib/utils'
export let relations: Relations[] = []
export let selectedTable: 'all' | 'specific'
Expand Down Expand Up @@ -49,46 +50,6 @@
<ToggleButton value="specific" label="Specific Tables" />
</ToggleButtonGroup>
</div>
{#if selectedTable !== 'all'}
<div class="grow min-w-0 pr-10">
<AddPropertyFormV2
customName="Schema"
on:add={({ detail }) => {
if (relations == undefined || !Array.isArray(relations)) {
relations = []
relations = relations.concat({
schema_name: 'public',
table_to_track: []
})
} else if (relations.length === 0) {
relations = relations.concat({
schema_name: 'public',
table_to_track: []
})
} else if (invalidRelations(relations, true) === false) {
relations = relations.concat({
schema_name: detail.name,
table_to_track: []
})
}
}}
>
<svelte:fragment slot="trigger">
<Button
variant="border"
color="light"
size="xs"
btnClasses="w-full"
disabled={!can_write}
startIcon={{ icon: Plus }}
nonCaptureEvent
>
Add schema
</Button>
</svelte:fragment>
</AddPropertyFormV2>
</div>
{/if}
</div>
{#if selectedTable !== 'all'}
{#if relations && relations.length > 0}
Expand Down Expand Up @@ -249,5 +210,43 @@
{/each}
</div>
{/if}
<div class="grow min-w-0 pr-10">
<AddPropertyFormV2
customName="Schema"
on:add={({ detail }) => {
if (relations == undefined || !Array.isArray(relations)) {
relations = []
relations = relations.concat({
schema_name: 'public',
table_to_track: []
})
} else if (emptyStringTrimmed(detail.name)) {
sendUserToast('Schema name must not be empty', true)
} else {
const appendedRelations = relations.concat({
schema_name: detail.name,
table_to_track: []
})
if (invalidRelations(appendedRelations, false, true) === false) {
relations = appendedRelations
}
}
}}
>
<svelte:fragment slot="trigger">
<Button
variant="border"
color="light"
size="xs"
btnClasses="w-full"
disabled={!can_write}
startIcon={{ icon: Plus }}
nonCaptureEvent
>
Add schema
</Button>
</svelte:fragment>
</AddPropertyFormV2>
</div>
{/if}
</div>
85 changes: 51 additions & 34 deletions frontend/src/lib/components/triggers/postgres/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,90 @@ type RelationError = {
schemaName?: string
trackAllTablesInSchema: boolean
trackSpecificColumnsInTable: boolean
duplicateSchemaName: boolean | undefined
}
export function invalidRelations(relations: Relations[], showError?: boolean): boolean {
let result: RelationError = {
export function invalidRelations(
relations: Relations[],
trackSchemaTableError: boolean,
showError?: boolean
): boolean {
let error: RelationError = {
schemaIndex: -1,
tableIndex: -1,
schemaError: false,
tableError: false,
trackAllTablesInSchema: false,
trackSpecificColumnsInTable: false
trackSpecificColumnsInTable: false,
duplicateSchemaName: undefined
}

const duplicateName: Set<string> = new Set()
console.log(relations.length)
for (const [schemaIndex, relation] of relations.entries()) {
error.schemaIndex = schemaIndex + 1
error.schemaName = relation.schema_name
if (emptyString(relation.schema_name)) {
result.schemaError = true
result.schemaIndex = schemaIndex + 1
error.schemaError = true
break
} else {
if (duplicateName.has(relation.schema_name)) {
error.duplicateSchemaName = true
break
}
duplicateName.add(relation.schema_name)
const tableToTrack = relation.table_to_track
if (tableToTrack.length > 0) {
for (const [tableIndex, table] of tableToTrack.entries()) {
if (emptyString(table.table_name)) {
result.tableError = true
result.tableIndex = tableIndex + 1
result.schemaName = relation.schema_name
result.schemaIndex = schemaIndex + 1
error.tableError = true
error.tableIndex = tableIndex + 1
break
}
if (
!result.trackSpecificColumnsInTable &&
!error.trackSpecificColumnsInTable &&
table.columns_name &&
table.columns_name.length > 0
) {
result.trackSpecificColumnsInTable = true
error.trackSpecificColumnsInTable = true
}
}
if (result.tableError) {
if (error.tableError) {
break
}
} else if (!result.trackAllTablesInSchema) {
result.trackAllTablesInSchema = true
} else if (!error.trackAllTablesInSchema) {
error.trackAllTablesInSchema = true
}

if (result.trackAllTablesInSchema && result.trackSpecificColumnsInTable) {
if (
trackSchemaTableError &&
error.trackAllTablesInSchema &&
error.trackSpecificColumnsInTable
) {
break
}
}
}
const errorFound =
error.tableError ||
error.schemaError ||
error.duplicateSchemaName ||
(trackSchemaTableError && error.trackAllTablesInSchema && error.trackSpecificColumnsInTable)
if (showError && errorFound) {
let errorMessage: string = ''

const error =
result.tableError ||
result.schemaError ||
(result.trackAllTablesInSchema && result.trackSpecificColumnsInTable)
if (showError) {
if (error === true) {
let errorMessage: string = ''

if (result.schemaError) {
errorMessage = `Schema Error: Please enter a name for schema number ${result.schemaIndex}`
} else if (result.tableError) {
errorMessage = `Table Error: Please enter a name for table number ${result.tableIndex} inside schema number ${result.schemaIndex}`
errorMessage += emptyString(result.schemaName) ? '' : ` named: ${result.schemaName}`
} else {
errorMessage =
'Configuration Error: Schema-level tracking and specific table tracking with column selection cannot be used together. Refer to the documentation for valid configurations.'
}
sendUserToast(errorMessage, true)
if (error.schemaError) {
errorMessage = `Schema Error: Please enter a name for schema number ${error.schemaIndex}`
} else if (error.tableError) {
errorMessage = `Table Error: Please enter a name for table number ${error.tableIndex} inside schema number ${error.schemaIndex}`
errorMessage += emptyString(error.schemaName) ? '' : ` named: ${error.schemaName}`
} else if (error.duplicateSchemaName) {
errorMessage = `Schema Error: schema name '${error.schemaName}' is already taken`
} else {
errorMessage =
'Configuration Error: Schema-level tracking and specific table tracking with column selection cannot be used together. Refer to the documentation for valid configurations.'
}
sendUserToast(errorMessage, true)
}

return error
return errorFound
}

0 comments on commit d0759d8

Please sign in to comment.