-
-
Notifications
You must be signed in to change notification settings - Fork 71
Add DNS record management feature for mapped domains #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
superdav42
wants to merge
1
commit into
main
Choose a base branch
from
feature/dns-record-management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,337 @@ | ||
| /* global jQuery, ajaxurl, wu_dns_config */ | ||
| /** | ||
| * DNS Management Vue.js Component | ||
| * | ||
| * Handles DNS record display and management in the Ultimate Multisite UI. | ||
| * | ||
| * @since 2.3.0 | ||
| */ | ||
| (function($) { | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Initialize DNS Management when DOM is ready. | ||
| */ | ||
| $(document).ready(function() { | ||
| initDNSManagement(); | ||
| }); | ||
|
|
||
| /** | ||
| * Initialize the DNS Management Vue instance. | ||
| */ | ||
| function initDNSManagement() { | ||
| const container = document.getElementById('wu-dns-records-table'); | ||
|
|
||
| if (!container || typeof Vue === 'undefined') { | ||
| return; | ||
| } | ||
|
|
||
| // Check if Vue instance already exists | ||
| if (container.__vue__) { | ||
| return; | ||
| } | ||
|
|
||
| window.WU_DNS_Management = new Vue({ | ||
| el: '#wu-dns-records-table', | ||
| data: { | ||
| loading: true, | ||
| error: null, | ||
| records: [], | ||
| readonly: false, | ||
| domain: '', | ||
| domainId: '', | ||
| canManage: false, | ||
| provider: '', | ||
| recordTypes: ['A', 'AAAA', 'CNAME', 'MX', 'TXT'], | ||
| selectedRecords: [], | ||
| }, | ||
|
|
||
| computed: { | ||
| hasRecords: function() { | ||
| return this.records && this.records.length > 0; | ||
| }, | ||
|
|
||
| sortedRecords: function() { | ||
| if (!this.records) { | ||
| return []; | ||
| } | ||
|
|
||
| // Sort by type, then by name | ||
| return [...this.records].sort(function(a, b) { | ||
| if (a.type !== b.type) { | ||
| return a.type.localeCompare(b.type); | ||
| } | ||
| return a.name.localeCompare(b.name); | ||
| }); | ||
| }, | ||
| }, | ||
|
|
||
| mounted: function() { | ||
| const el = this.$el; | ||
|
|
||
| this.domain = el.dataset.domain || ''; | ||
| this.domainId = el.dataset.domainId || ''; | ||
| this.canManage = el.dataset.canManage === 'true'; | ||
|
|
||
| if (this.domain) { | ||
| this.loadRecords(); | ||
| } | ||
| }, | ||
|
|
||
| methods: { | ||
| /** | ||
| * Load DNS records from the server. | ||
| */ | ||
| loadRecords: function() { | ||
| const self = this; | ||
|
|
||
| this.loading = true; | ||
| this.error = null; | ||
|
|
||
| $.ajax({ | ||
| url: ajaxurl, | ||
| method: 'POST', | ||
| data: { | ||
| action: 'wu_get_dns_records_for_domain', | ||
| nonce: wu_dns_config.nonce, | ||
| domain: this.domain, | ||
| }, | ||
| success: function(response) { | ||
| self.loading = false; | ||
|
|
||
| if (response.success) { | ||
| self.records = response.data.records || []; | ||
| self.readonly = response.data.readonly || false; | ||
| self.provider = response.data.provider || ''; | ||
|
|
||
| if (response.data.record_types) { | ||
| self.recordTypes = response.data.record_types; | ||
| } | ||
|
|
||
| if (response.data.message && self.readonly) { | ||
| self.error = response.data.message; | ||
| } | ||
| } else { | ||
| self.error = response.data?.message || 'Failed to load DNS records.'; | ||
| } | ||
| }, | ||
| error: function(xhr, status, errorMsg) { | ||
| self.loading = false; | ||
| self.error = 'Network error: ' + errorMsg; | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Refresh the records list. | ||
| */ | ||
| refresh: function() { | ||
| this.loadRecords(); | ||
| }, | ||
|
|
||
| /** | ||
| * Get CSS class for record type badge. | ||
| * | ||
| * @param {string} type The record type. | ||
| * @return {string} CSS classes. | ||
| */ | ||
| getTypeClass: function(type) { | ||
| const classes = { | ||
| 'A': 'wu-bg-blue-100 wu-text-blue-800', | ||
| 'AAAA': 'wu-bg-purple-100 wu-text-purple-800', | ||
| 'CNAME': 'wu-bg-green-100 wu-text-green-800', | ||
| 'MX': 'wu-bg-orange-100 wu-text-orange-800', | ||
| 'TXT': 'wu-bg-gray-100 wu-text-gray-800', | ||
| }; | ||
|
|
||
| return classes[type] || 'wu-bg-gray-100 wu-text-gray-800'; | ||
| }, | ||
|
|
||
| /** | ||
| * Format TTL value for display. | ||
| * | ||
| * @param {number} seconds TTL in seconds. | ||
| * @return {string} Formatted TTL. | ||
| */ | ||
| formatTTL: function(seconds) { | ||
| if (seconds === 1) { | ||
| return 'Auto'; | ||
| } | ||
|
|
||
| if (seconds < 60) { | ||
| return seconds + 's'; | ||
| } | ||
|
|
||
| if (seconds < 3600) { | ||
| return Math.floor(seconds / 60) + 'm'; | ||
| } | ||
|
|
||
| if (seconds < 86400) { | ||
| return Math.floor(seconds / 3600) + 'h'; | ||
| } | ||
|
|
||
| return Math.floor(seconds / 86400) + 'd'; | ||
| }, | ||
|
|
||
| /** | ||
| * Truncate content for display. | ||
| * | ||
| * @param {string} content The content to truncate. | ||
| * @param {number} maxLength Maximum length. | ||
| * @return {string} Truncated content. | ||
| */ | ||
| truncateContent: function(content, maxLength) { | ||
| maxLength = maxLength || 40; | ||
|
|
||
| if (!content || content.length <= maxLength) { | ||
| return content; | ||
| } | ||
|
|
||
| return content.substring(0, maxLength) + '...'; | ||
| }, | ||
|
|
||
| /** | ||
| * Get the edit URL for a record. | ||
| * | ||
| * @param {Object} record The record object. | ||
| * @return {string} Edit URL. | ||
| */ | ||
| getEditUrl: function(record) { | ||
| if (!wu_dns_config.edit_url) { | ||
| return '#'; | ||
| } | ||
|
|
||
| return wu_dns_config.edit_url + | ||
| '&record_id=' + encodeURIComponent(record.id) + | ||
| '&domain_id=' + encodeURIComponent(this.domainId); | ||
| }, | ||
|
|
||
| /** | ||
| * Get the delete URL for a record. | ||
| * | ||
| * @param {Object} record The record object. | ||
| * @return {string} Delete URL. | ||
| */ | ||
| getDeleteUrl: function(record) { | ||
| if (!wu_dns_config.delete_url) { | ||
| return '#'; | ||
| } | ||
|
|
||
| return wu_dns_config.delete_url + | ||
| '&record_id=' + encodeURIComponent(record.id) + | ||
| '&domain_id=' + encodeURIComponent(this.domainId); | ||
| }, | ||
|
|
||
| /** | ||
| * Toggle record selection. | ||
| * | ||
| * @param {string} recordId The record ID. | ||
| */ | ||
| toggleSelection: function(recordId) { | ||
| const index = this.selectedRecords.indexOf(recordId); | ||
|
|
||
| if (index > -1) { | ||
| this.selectedRecords.splice(index, 1); | ||
| } else { | ||
| this.selectedRecords.push(recordId); | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Check if a record is selected. | ||
| * | ||
| * @param {string} recordId The record ID. | ||
| * @return {boolean} True if selected. | ||
| */ | ||
| isSelected: function(recordId) { | ||
| return this.selectedRecords.indexOf(recordId) > -1; | ||
| }, | ||
|
|
||
| /** | ||
| * Select all records. | ||
| */ | ||
| selectAll: function() { | ||
| const self = this; | ||
|
|
||
| this.selectedRecords = this.records.map(function(record) { | ||
| return record.id; | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Deselect all records. | ||
| */ | ||
| deselectAll: function() { | ||
| this.selectedRecords = []; | ||
| }, | ||
|
|
||
| /** | ||
| * Delete selected records (admin bulk operation). | ||
| */ | ||
| deleteSelected: function() { | ||
| if (!this.selectedRecords.length) { | ||
| return; | ||
| } | ||
|
|
||
| if (!confirm('Are you sure you want to delete ' + this.selectedRecords.length + ' selected records?')) { | ||
| return; | ||
| } | ||
|
|
||
| const self = this; | ||
|
|
||
| $.ajax({ | ||
| url: ajaxurl, | ||
| method: 'POST', | ||
| data: { | ||
| action: 'wu_bulk_dns_operations', | ||
| nonce: wu_dns_config.nonce, | ||
| domain: this.domain, | ||
| operation: 'delete', | ||
| records: this.selectedRecords, | ||
| }, | ||
| success: function(response) { | ||
| if (response.success) { | ||
| self.selectedRecords = []; | ||
| self.loadRecords(); | ||
| } else { | ||
| alert('Error: ' + (response.data?.message || 'Failed to delete records.')); | ||
| } | ||
| }, | ||
| error: function() { | ||
| alert('Network error occurred.'); | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Get proxied status display. | ||
| * | ||
| * @param {Object} record The record object. | ||
| * @return {string} Proxied status HTML. | ||
| */ | ||
| getProxiedStatus: function(record) { | ||
| if (this.provider !== 'cloudflare') { | ||
| return ''; | ||
| } | ||
|
|
||
| if (record.proxied) { | ||
| return '<span class="wu-text-orange-500" title="Proxied through Cloudflare">☁</span>'; | ||
| } | ||
|
|
||
| return '<span class="wu-text-gray-400" title="DNS only">☁</span>'; | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reinitialize DNS management when modal content is loaded. | ||
| * This handles wubox modal scenarios. | ||
| */ | ||
| $(document).on('wubox-load', function() { | ||
| setTimeout(function() { | ||
| initDNSManagement(); | ||
| }, 100); | ||
| }); | ||
|
|
||
| })(jQuery); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
WordPress JavaScript optional chaining ES2020 support transpilation requirements💡 Result:
Short answer
Key references
If you want, tell me which build setup you use (WordPress tools, create-react-app, webpack config, TypeScript, @wordpress/scripts) and I’ll give exact config lines to add.
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 251
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 908
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 95
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 125
🏁 Script executed:
# Read package.json to check build dependencies and configuration cat -n package.jsonRepository: Multisite-Ultimate/ultimate-multisite
Length of output: 4082
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 644
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 180
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 323
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 6204
Replace optional chaining with explicit null checks or add Babel transpilation.
The build process uses UglifyJS for minification only, which does not transpile ES2020 syntax like optional chaining (
?.). This code will fail in older browsers (IE11, Safari <14, etc.) that don't support optional chaining. Either add@babel/plugin-transform-optional-chainingto your Babel configuration, or replaceresponse.data?.messagewithresponse.data && response.data.message.Also applies to: 296-298
🤖 Prompt for AI Agents