π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat(nc-gui): add copy from view related utils
Ramesh Mane35806832b76b
diff --git a/packages/nc-gui/components/smartsheet/Toolbar.vue b/packages/nc-gui/components/smartsheet/Toolbar.vueindex 69b1c35477..4fa3e9e2ce 100644--- a/packages/nc-gui/components/smartsheet/Toolbar.vue+++ b/packages/nc-gui/components/smartsheet/Toolbar.vue@@ -88,7 +88,7 @@ provide(IsToolbarIconMode, isToolbarIconMode)<SmartsheetToolbarSortListMenu v-if="isGrid || isGallery || isKanban" />- <SmartsheetToolbarRowColorFilterDropdown v-if="!isPublic && (isGrid || isGallery || isKanban || isMap)" />+ <SmartsheetToolbarRowColorFilterDropdown v-if="!isPublic && (isGrid || isGallery || isKanban)" /><SmartsheetToolbarBulkActionv-if="(isGrid || isGallery) && !isPublic && !isSharedBase && isUIAllowed('scriptExecute') && isViewActionsEnabled"diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.jsonindex 71a06d4160..dba2b9135e 100644--- a/packages/nc-gui/lang/en.json+++ b/packages/nc-gui/lang/en.json@@ -648,6 +648,16 @@"deleteAllRecordDlg": {"subtitle": "Are you sure you want to delete all selected {rowCount} records present in this view?","warning": "This action cannot be undone."+ },+ "copyViewConfig": {+ "fieldVisibility": "Field visibility",+ "fieldOrder": "Field order",+ "columnWidthAndRowHeight": "Column width and row height",+ "rowHeight": "Row height",+ "filters": "Filters",+ "groups": "Groups",+ "sorts": "Sorts",+ "rowColoring": "Row coloring"}},"datatype": {diff --git a/packages/nc-gui/utils/viewUtils.ts b/packages/nc-gui/utils/viewUtils.tsindex d3433bba77..452f382be7 100644--- a/packages/nc-gui/utils/viewUtils.ts+++ b/packages/nc-gui/utils/viewUtils.ts@@ -79,3 +79,178 @@ export const getDefaultViewMetas = (viewType: ViewTypes) => {}return {}}++/**+ * Enum representing the different types of view configurations that can be copied from one view to another.+ * Each type corresponds to a specific aspect of a view's configuration.+ */+export enum CopyViewConfigType {+ /** Field visibility settings */+ FieldVisibility = 'fieldVisibility',+ /** Field ordering configuration */+ FieldOrder = 'fieldOrder',+ /** Column width and row height settings */+ ColumnWidthAndRowHeight = 'columnWidthAndRowHeight',+ /** Row height settings */+ RowHeight = 'rowHeight',+ /** Filter configurations */+ Filters = 'filters',+ /** Grouping configurations */+ Groups = 'groups',+ /** Sort configurations */+ Sorts = 'sorts',+ /** Row coloring settings */+ RowColoring = 'rowColoring',+}++/**+ * Interface representing a copy view config option with its metadata.+ * Used to define the properties and constraints for each type of view configuration that can be copied.+ */+export interface CopyViewConfigOption {+ /** The display order of this option in the UI */+ order: number+ /** The human-readable label for this option */+ label: string+ /** The copy view config type value */+ value: CopyViewConfigType+ /** The i18n translation key for the label */+ i18nLabel: string+ /** Array of view types that support this configuration option */+ supportedViewTypes: ViewTypes[]+}++/**+ * A comprehensive mapping of all available copy view configuration options.+ *+ * This map defines the metadata and constraints for each type of view configuration that can be copied,+ * including display order, labels, i18n keys, and which view types support each configuration option.+ *+ * @remarks+ * Use this map to:+ * - Get the configuration options available for a specific view type+ * - Determine which view types support a particular configuration option+ * - Access i18n labels and display ordering for UI rendering+ *+ * @example+ * ```ts+ * // Get the field visibility option metadata+ * const fieldVisibilityOption = copyViewConfigOptionMap[CopyViewConfigType.FieldVisibility]+ * // Check if it's supported for grid views+ * const isSupported = fieldVisibilityOption.supportedViewTypes.includes(ViewTypes.GRID)+ * ```+ */+export const copyViewConfigOptionMap: Record<CopyViewConfigType, CopyViewConfigOption> = {+ [CopyViewConfigType.FieldVisibility]: {+ order: 1,+ label: 'Field visibility',+ value: CopyViewConfigType.FieldVisibility,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.FieldVisibility}`,+ supportedViewTypes: [ViewTypes.GRID, ViewTypes.GALLERY, ViewTypes.KANBAN, ViewTypes.FORM, ViewTypes.CALENDAR, ViewTypes.MAP],+ },+ [CopyViewConfigType.FieldOrder]: {+ order: 2,+ label: 'Field order',+ value: CopyViewConfigType.FieldOrder,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.FieldOrder}`,+ supportedViewTypes: [ViewTypes.GRID, ViewTypes.GALLERY, ViewTypes.KANBAN, ViewTypes.FORM, ViewTypes.CALENDAR, ViewTypes.MAP],+ },+ [CopyViewConfigType.ColumnWidthAndRowHeight]: {+ order: 3,+ label: 'Column width and row height',+ value: CopyViewConfigType.ColumnWidthAndRowHeight,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.ColumnWidthAndRowHeight}`,+ supportedViewTypes: [ViewTypes.GRID],+ },+ [CopyViewConfigType.RowHeight]: {+ order: 4,+ label: 'Row height',+ value: CopyViewConfigType.RowHeight,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.RowHeight}`,+ supportedViewTypes: [ViewTypes.GRID],+ },+ [CopyViewConfigType.Filters]: {+ order: 5,+ label: 'Filters',+ value: CopyViewConfigType.Filters,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.Filters}`,+ supportedViewTypes: [ViewTypes.GRID, ViewTypes.GALLERY, ViewTypes.KANBAN, ViewTypes.CALENDAR, ViewTypes.MAP],+ },+ [CopyViewConfigType.Groups]: {+ order: 6,+ label: 'Groups',+ value: CopyViewConfigType.Groups,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.Groups}`,+ supportedViewTypes: [ViewTypes.GRID],+ },+ [CopyViewConfigType.Sorts]: {+ order: 7,+ label: 'Sorts',+ value: CopyViewConfigType.Sorts,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.Sorts}`,+ supportedViewTypes: [ViewTypes.GRID, ViewTypes.GALLERY, ViewTypes.KANBAN, ViewTypes.CALENDAR],+ },+ [CopyViewConfigType.RowColoring]: {+ order: 8,+ label: 'Row coloring',+ value: CopyViewConfigType.RowColoring,+ i18nLabel: `objects.copyViewConfig.${CopyViewConfigType.RowColoring}`,+ supportedViewTypes: [ViewTypes.GRID, ViewTypes.GALLERY, ViewTypes.KANBAN, ViewTypes.CALENDAR],+ },+}++/**+ * Retrieves all copy view configuration options with their availability status for a specific view type.+ *+ * This function returns all available configuration options, marking each as enabled or disabled+ * based on whether the source view type supports that particular configuration.+ * The returned options are sorted by their display order.+ *+ * @param copyFromViewType - The view type from which configurations will be copied+ * @returns An array of configuration options with a 'disabled' flag indicating support status, sorted by order+ *+ * @example+ * ```ts+ * // Get all config options for copying from a Grid view+ * const options = getCopyViewConfigOptions(ViewTypes.GRID)+ * // Filter to only enabled options+ * const enabledOptions = options.filter(opt => !opt.disabled)+ * ```+ */+export const getCopyViewConfigOptions = (copyFromViewType: ViewTypes) => {+ return Object.values(copyViewConfigOptionMap)+ .map((option) => {+ const { supportedViewTypes, ...rest } = option+ return {+ ...rest,+ disabled: !supportedViewTypes.includes(copyFromViewType),+ }+ })+ .sort((a, b) => a.order - b.order)+}++/**+ * Filters a list of copy view configuration types to only include those supported by the source view type.+ *+ * This function validates each configuration type against the source view type's capabilities,+ * removing any unsupported or invalid configuration types from the list.+ *+ * @param copyViewConfigTypes - Array of configuration types to be validated+ * @param copyFromViewType - The view type from which configurations will be copied+ * @returns A filtered array containing only the configuration types supported by the source view type+ *+ * @example+ * ```ts+ * // Validate selected config types for a Form view+ * const selectedTypes = [CopyViewConfigType.FieldVisibility, CopyViewConfigType.Filters, CopyViewConfigType.Groups]+ * const supportedTypes = extractSupportedCopyViewConfigTypes(selectedTypes, ViewTypes.FORM)+ * // Result: Only FieldVisibility will be included since Forms don't support Filters or Groups+ * ```+ */+export const extractSupportedCopyViewConfigTypes = (copyViewConfigTypes: CopyViewConfigType[], copyFromViewType: ViewTypes) => {+ return copyViewConfigTypes.filter((type) => {+ if (!copyViewConfigOptionMap[type]) return false++ return copyViewConfigOptionMap[type].supportedViewTypes.includes(copyFromViewType)+ })+}