({ schema, table }: TableNodeProps)
| 42 | * glyphs and edit-on-click affordances when `editable` is on. |
| 43 | */ |
| 44 | export function TableNode({ schema, table }: TableNodeProps) { |
| 45 | const ctx = useSchemaDiagramContext(); |
| 46 | const { |
| 47 | dummy, |
| 48 | editable, |
| 49 | focusedTables, |
| 50 | foreignKeys, |
| 51 | idOfTable, |
| 52 | rectOfTable, |
| 53 | schemaStatus, |
| 54 | tableStatus, |
| 55 | columnStatus, |
| 56 | panning, |
| 57 | events, |
| 58 | } = ctx; |
| 59 | |
| 60 | const tableColor = useMemo(() => { |
| 61 | const index = (hashCode(table.name) & 0xfffffff) % COLOR_LIST.length; |
| 62 | return COLOR_LIST[index]; |
| 63 | }, [table.name]); |
| 64 | |
| 65 | const isTableDropped = useMemo( |
| 66 | () => |
| 67 | schemaStatus(schema) === "dropped" || tableStatus(table) === "dropped", |
| 68 | [schema, table, schemaStatus, tableStatus] |
| 69 | ); |
| 70 | |
| 71 | const isTableCreated = useMemo( |
| 72 | () => |
| 73 | schemaStatus(schema) === "created" || tableStatus(table) === "created", |
| 74 | [schema, table, schemaStatus, tableStatus] |
| 75 | ); |
| 76 | |
| 77 | const isTableChanged = useMemo( |
| 78 | () => tableStatus(table) === "changed", |
| 79 | [table, tableStatus] |
| 80 | ); |
| 81 | |
| 82 | const tableStatusText = isTableCreated |
| 83 | ? "Created" |
| 84 | : isTableDropped |
| 85 | ? "Dropped" |
| 86 | : isTableChanged |
| 87 | ? "Changed" |
| 88 | : ""; |
| 89 | |
| 90 | const tableClasses = useMemo(() => { |
| 91 | if (focusedTables.size === 0) return ""; |
| 92 | if (focusedTables.has(table)) return "opacity-100"; |
| 93 | if (isFocusedForeignTable(table, focusedTables, foreignKeys)) { |
| 94 | return "opacity-100"; |
| 95 | } |
| 96 | return "opacity-20 hover:opacity-100"; |
| 97 | }, [table, focusedTables, foreignKeys]); |
| 98 | |
| 99 | const columnClasses = useCallback( |
| 100 | (column: ColumnMetadata) => { |
| 101 | const classes: string[] = []; |
nothing calls this directly
no test coverage detected