diff --git a/charts/budibase/templates/app-service-deployment.yaml b/charts/budibase/templates/app-service-deployment.yaml index fbe9c1d363..7358e474ca 100644 --- a/charts/budibase/templates/app-service-deployment.yaml +++ b/charts/budibase/templates/app-service-deployment.yaml @@ -194,7 +194,7 @@ spec: {{ end }} image: budibase/apps:{{ .Values.globals.appVersion | default .Chart.AppVersion }} - imagePullPolicy: IfNotPresent + imagePullPolicy: Always {{- if .Values.services.apps.startupProbe }} {{- with .Values.services.apps.startupProbe }} startupProbe: diff --git a/hosting/docker-compose.build.yaml b/hosting/docker-compose.build.yaml index 7ead001a1c..dbc3613599 100644 --- a/hosting/docker-compose.build.yaml +++ b/hosting/docker-compose.build.yaml @@ -6,7 +6,7 @@ services: app-service: build: context: .. - dockerfile: packages/server/Dockerfile.v2 + dockerfile: packages/server/Dockerfile args: - BUDIBASE_VERSION=0.0.0+dev-docker container_name: build-bbapps @@ -36,7 +36,7 @@ services: worker-service: build: context: .. - dockerfile: packages/worker/Dockerfile.v2 + dockerfile: packages/worker/Dockerfile args: - BUDIBASE_VERSION=0.0.0+dev-docker container_name: build-bbworker diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile index 84c3b824fb..eedd1e4213 100644 --- a/hosting/single/Dockerfile +++ b/hosting/single/Dockerfile @@ -1,44 +1,59 @@ FROM node:18-slim as build # install node-gyp dependencies -RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends apt-utils cron g++ make python3 +RUN apt-get update && apt-get install -y --no-install-recommends g++ make python3 jq -# add pin script -WORKDIR / -ADD scripts/cleanup.sh ./ -RUN chmod +x /cleanup.sh -# build server +# copy and install dependencies WORKDIR /app -ADD packages/server . +COPY package.json . COPY yarn.lock . -RUN yarn install --production=true --network-timeout 1000000 -RUN /cleanup.sh +COPY lerna.json . +COPY .yarnrc . -# build worker -WORKDIR /worker -ADD packages/worker . -COPY yarn.lock . -RUN yarn install --production=true --network-timeout 1000000 -RUN /cleanup.sh +COPY packages/server/package.json packages/server/package.json +COPY packages/worker/package.json packages/worker/package.json +# string-templates does not get bundled during the esbuild process, so we want to use the local version +COPY packages/string-templates/package.json packages/string-templates/package.json -FROM budibase/couchdb + +COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh +RUN chmod +x ./scripts/removeWorkspaceDependencies.sh +RUN ./scripts/removeWorkspaceDependencies.sh packages/server/package.json +RUN ./scripts/removeWorkspaceDependencies.sh packages/worker/package.json + + +# We will never want to sync pro, but the script is still required +RUN echo '' > scripts/syncProPackage.js +RUN jq 'del(.scripts.postinstall)' package.json > temp.json && mv temp.json package.json +RUN ./scripts/removeWorkspaceDependencies.sh package.json +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production + +# copy the actual code +COPY packages/server/dist packages/server/dist +COPY packages/server/pm2.config.js packages/server/pm2.config.js +COPY packages/server/client packages/server/client +COPY packages/server/builder packages/server/builder +COPY packages/worker/dist packages/worker/dist +COPY packages/worker/pm2.config.js packages/worker/pm2.config.js +COPY packages/string-templates packages/string-templates + + +FROM budibase/couchdb as runner ARG TARGETARCH ENV TARGETARCH $TARGETARCH +ENV NODE_MAJOR 18 #TARGETBUILD can be set to single (for single docker image) or aas (for azure app service) # e.g. docker build --build-arg TARGETBUILD=aas .... ARG TARGETBUILD=single ENV TARGETBUILD $TARGETBUILD -COPY --from=build /app /app -COPY --from=build /worker /worker - # install base dependencies RUN apt-get update && \ - apt-get install -y --no-install-recommends software-properties-common nginx uuid-runtime redis-server + apt-get install -y --no-install-recommends software-properties-common nginx uuid-runtime redis-server libaio1 # Install postgres client for pg_dump utils -RUN apt install software-properties-common apt-transport-https gpg -y \ +RUN apt install -y software-properties-common apt-transport-https ca-certificates gnupg \ && curl -fsSl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/postgresql.gpg > /dev/null \ && echo deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main | tee /etc/apt/sources.list.d/postgresql.list \ && apt update -y \ @@ -47,14 +62,12 @@ RUN apt install software-properties-common apt-transport-https gpg -y \ # install other dependencies, nodejs, oracle requirements, jdk8, redis, nginx WORKDIR /nodejs -RUN curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh && \ - bash /tmp/nodesource_setup.sh && \ - apt-get install -y --no-install-recommends libaio1 nodejs && \ - npm install --global yarn pm2 +COPY scripts/install-node.sh ./install.sh +RUN chmod +x install.sh && ./install.sh # setup nginx -ADD hosting/single/nginx/nginx.conf /etc/nginx -ADD hosting/single/nginx/nginx-default-site.conf /etc/nginx/sites-enabled/default +COPY hosting/single/nginx/nginx.conf /etc/nginx +COPY hosting/single/nginx/nginx-default-site.conf /etc/nginx/sites-enabled/default RUN mkdir -p /var/log/nginx && \ touch /var/log/nginx/error.log && \ touch /var/run/nginx.pid && \ @@ -62,19 +75,19 @@ RUN mkdir -p /var/log/nginx && \ WORKDIR / RUN mkdir -p scripts/integrations/oracle -ADD packages/server/scripts/integrations/oracle scripts/integrations/oracle +COPY packages/server/scripts/integrations/oracle scripts/integrations/oracle RUN /bin/bash -e ./scripts/integrations/oracle/instantclient/linux/install.sh # setup minio WORKDIR /minio -ADD scripts/install-minio.sh ./install.sh +COPY scripts/install-minio.sh ./install.sh RUN chmod +x install.sh && ./install.sh # setup runner file WORKDIR / -ADD hosting/single/runner.sh . +COPY hosting/single/runner.sh . RUN chmod +x ./runner.sh -ADD hosting/single/healthcheck.sh . +COPY hosting/single/healthcheck.sh . RUN chmod +x ./healthcheck.sh # Script below sets the path for storing data based on $DATA_DIR @@ -82,8 +95,19 @@ RUN chmod +x ./healthcheck.sh ADD hosting/single/ssh/sshd_config /etc/ ADD hosting/single/ssh/ssh_setup.sh /tmp -# cleanup cache -RUN yarn cache clean -f +# setup letsencrypt certificate +RUN apt-get install -y certbot python3-certbot-nginx +COPY hosting/letsencrypt /app/letsencrypt +RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh + +COPY --from=build /app/node_modules /node_modules +COPY --from=build /app/package.json /package.json +COPY --from=build /app/packages/server /app +COPY --from=build /app/packages/worker /worker +COPY --from=build /app/packages/string-templates /string-templates + +RUN cd /string-templates && yarn link && cd ../app && yarn link @budibase/string-templates && cd ../worker && yarn link @budibase/string-templates + EXPOSE 80 EXPOSE 443 @@ -91,20 +115,10 @@ EXPOSE 443 EXPOSE 2222 VOLUME /data -# setup letsencrypt certificate -RUN apt-get install -y certbot python3-certbot-nginx -ADD hosting/letsencrypt /app/letsencrypt -RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh -# Remove cached files -RUN rm -rf \ - /root/.cache \ - /root/.npm \ - /root/.pip \ - /usr/local/share/doc \ - /usr/share/doc \ - /usr/share/man \ - /var/lib/apt/lists/* \ - /tmp/* +ARG BUDIBASE_VERSION +# Ensuring the version argument is sent +RUN test -n "$BUDIBASE_VERSION" +ENV BUDIBASE_VERSION=$BUDIBASE_VERSION HEALTHCHECK --interval=15s --timeout=15s --start-period=45s CMD "/healthcheck.sh" diff --git a/hosting/single/Dockerfile.v2 b/hosting/single/Dockerfile.v2 deleted file mode 100644 index dd61c779b5..0000000000 --- a/hosting/single/Dockerfile.v2 +++ /dev/null @@ -1,130 +0,0 @@ -FROM node:18-slim as build - -# install node-gyp dependencies -RUN apt-get update && apt-get install -y --no-install-recommends g++ make python3 jq - - -# copy and install dependencies -WORKDIR /app -COPY package.json . -COPY yarn.lock . -COPY lerna.json . -COPY .yarnrc . - -COPY packages/server/package.json packages/server/package.json -COPY packages/worker/package.json packages/worker/package.json -# string-templates does not get bundled during the esbuild process, so we want to use the local version -COPY packages/string-templates/package.json packages/string-templates/package.json - - -COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh -RUN chmod +x ./scripts/removeWorkspaceDependencies.sh -RUN ./scripts/removeWorkspaceDependencies.sh packages/server/package.json -RUN ./scripts/removeWorkspaceDependencies.sh packages/worker/package.json - - -# We will never want to sync pro, but the script is still required -RUN echo '' > scripts/syncProPackage.js -RUN jq 'del(.scripts.postinstall)' package.json > temp.json && mv temp.json package.json -RUN ./scripts/removeWorkspaceDependencies.sh package.json -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production - -# copy the actual code -COPY packages/server/dist packages/server/dist -COPY packages/server/pm2.config.js packages/server/pm2.config.js -COPY packages/server/client packages/server/client -COPY packages/server/builder packages/server/builder -COPY packages/worker/dist packages/worker/dist -COPY packages/worker/pm2.config.js packages/worker/pm2.config.js -COPY packages/string-templates packages/string-templates - - -FROM budibase/couchdb as runner -ARG TARGETARCH -ENV TARGETARCH $TARGETARCH -ENV NODE_MAJOR 18 -#TARGETBUILD can be set to single (for single docker image) or aas (for azure app service) -# e.g. docker build --build-arg TARGETBUILD=aas .... -ARG TARGETBUILD=single -ENV TARGETBUILD $TARGETBUILD - -# install base dependencies -RUN apt-get update && \ - apt-get install -y --no-install-recommends software-properties-common nginx uuid-runtime redis-server libaio1 - -# Install postgres client for pg_dump utils -RUN apt install -y software-properties-common apt-transport-https ca-certificates gnupg \ - && curl -fsSl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/postgresql.gpg > /dev/null \ - && echo deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main | tee /etc/apt/sources.list.d/postgresql.list \ - && apt update -y \ - && apt install postgresql-client-15 -y \ - && apt remove software-properties-common apt-transport-https gpg -y - -# install other dependencies, nodejs, oracle requirements, jdk8, redis, nginx -WORKDIR /nodejs -COPY scripts/install-node.sh ./install.sh -RUN chmod +x install.sh && ./install.sh - -# setup nginx -COPY hosting/single/nginx/nginx.conf /etc/nginx -COPY hosting/single/nginx/nginx-default-site.conf /etc/nginx/sites-enabled/default -RUN mkdir -p /var/log/nginx && \ - touch /var/log/nginx/error.log && \ - touch /var/run/nginx.pid && \ - usermod -a -G tty www-data - -WORKDIR / -RUN mkdir -p scripts/integrations/oracle -COPY packages/server/scripts/integrations/oracle scripts/integrations/oracle -RUN /bin/bash -e ./scripts/integrations/oracle/instantclient/linux/install.sh - -# setup minio -WORKDIR /minio -COPY scripts/install-minio.sh ./install.sh -RUN chmod +x install.sh && ./install.sh - -# setup runner file -WORKDIR / -COPY hosting/single/runner.sh . -RUN chmod +x ./runner.sh -COPY hosting/single/healthcheck.sh . -RUN chmod +x ./healthcheck.sh - -# Script below sets the path for storing data based on $DATA_DIR -# For Azure App Service install SSH & point data locations to /home -COPY hosting/single/ssh/sshd_config /etc/ -COPY hosting/single/ssh/ssh_setup.sh /tmp - - -# setup letsencrypt certificate -RUN apt-get install -y certbot python3-certbot-nginx -COPY hosting/letsencrypt /app/letsencrypt -RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh - -COPY --from=build /app/node_modules /node_modules -COPY --from=build /app/package.json /package.json -COPY --from=build /app/packages/server /app -COPY --from=build /app/packages/worker /worker -COPY --from=build /app/packages/string-templates /string-templates - -RUN cd /string-templates && yarn link && cd ../app && yarn link @budibase/string-templates && cd ../worker && yarn link @budibase/string-templates - - -EXPOSE 80 -EXPOSE 443 -# Expose port 2222 for SSH on Azure App Service build -EXPOSE 2222 -VOLUME /data - -ARG BUDIBASE_VERSION -# Ensuring the version argument is sent -RUN test -n "$BUDIBASE_VERSION" -ENV BUDIBASE_VERSION=$BUDIBASE_VERSION - -HEALTHCHECK --interval=15s --timeout=15s --start-period=45s CMD "/healthcheck.sh" - -# must set this just before running -ENV NODE_ENV=production -WORKDIR / - -CMD ["./runner.sh"] diff --git a/packages/builder/src/components/design/settings/componentSettings.js b/packages/builder/src/components/design/settings/componentSettings.js index c2bd08760a..b740247294 100644 --- a/packages/builder/src/components/design/settings/componentSettings.js +++ b/packages/builder/src/components/design/settings/componentSettings.js @@ -20,7 +20,7 @@ import ValidationEditor from "./controls/ValidationEditor/ValidationEditor.svelt import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import ColumnEditor from "./controls/ColumnEditor/ColumnEditor.svelte" import BasicColumnEditor from "./controls/ColumnEditor/BasicColumnEditor.svelte" -import GridColumnEditor from "./controls/ColumnEditor/GridColumnEditor.svelte" +import GridColumnEditor from "./controls/GridColumnConfiguration/GridColumnConfiguration.svelte" import BarButtonList from "./controls/BarButtonList.svelte" import FieldConfiguration from "./controls/FieldConfiguration/FieldConfiguration.svelte" import ButtonConfiguration from "./controls/ButtonConfiguration/ButtonConfiguration.svelte" @@ -28,6 +28,7 @@ import RelationshipFilterEditor from "./controls/RelationshipFilterEditor.svelte const componentMap = { text: DrawerBindableInput, + plainText: Input, select: Select, radio: RadioGroup, dataSource: DataSourceSelect, diff --git a/packages/builder/src/components/design/settings/controls/ColumnEditor/GridColumnEditor.svelte b/packages/builder/src/components/design/settings/controls/ColumnEditor/GridColumnEditor.svelte deleted file mode 100644 index 291a1b61a8..0000000000 --- a/packages/builder/src/components/design/settings/controls/ColumnEditor/GridColumnEditor.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/FieldSetting.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/FieldSetting.svelte new file mode 100644 index 0000000000..da1fa27ba4 --- /dev/null +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/FieldSetting.svelte @@ -0,0 +1,91 @@ + + +
+
+ +
+ + {item.field} +
+
+
{item.label || item.field}
+
+
+ +
+
+ + diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte new file mode 100644 index 0000000000..4286328367 --- /dev/null +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte @@ -0,0 +1,107 @@ + + +{#if columns.primary} +
+
+
+ columns.update(e.detail)} + /> +
+
+
+{/if} + columns.updateSortable(e.detail)} + on:itemChange={e => columns.update(e.detail)} + items={columns.sortable} + listItemKey={"_id"} + listType={FieldSetting} +/> + + diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte new file mode 100644 index 0000000000..1cb29ac6e7 --- /dev/null +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte @@ -0,0 +1,100 @@ + + +
+
+ +
+ + {item.field} +
+
+
{item.label || item.field}
+
+
+ +
+
+ + diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js new file mode 100644 index 0000000000..72fdbe4108 --- /dev/null +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -0,0 +1,129 @@ +const modernize = columns => { + if (!columns) { + return [] + } + // If the first element has no active key then it's safe to assume all elements are in the old format + if (columns?.[0] && columns[0].active === undefined) { + return columns.map(column => ({ + label: column.displayName, + field: column.name, + active: true, + })) + } + + return columns +} + +const removeInvalidAddMissing = ( + columns = [], + defaultColumns, + primaryDisplayColumnName +) => { + const defaultColumnNames = defaultColumns.map(column => column.field) + const columnNames = columns.map(column => column.field) + + const validColumns = columns.filter(column => + defaultColumnNames.includes(column.field) + ) + let missingColumns = defaultColumns.filter( + defaultColumn => !columnNames.includes(defaultColumn.field) + ) + + // If the user already has fields selected, any appended missing fields should be disabled by default + if (validColumns.length) { + missingColumns = missingColumns.map(field => ({ ...field, active: false })) + } + + const combinedColumns = [...validColumns, ...missingColumns] + + // Ensure the primary display column is always visible + const primaryDisplayIndex = combinedColumns.findIndex( + column => column.field === primaryDisplayColumnName + ) + if (primaryDisplayIndex > -1) { + combinedColumns[primaryDisplayIndex].active = true + } + + return combinedColumns +} + +const getDefault = (schema = {}) => { + const defaultValues = Object.values(schema) + .filter(column => !column.nestedJSON) + .map(column => ({ + label: column.name, + field: column.name, + active: column.visible ?? true, + order: column.visible ? column.order ?? -1 : Number.MAX_SAFE_INTEGER, + })) + + defaultValues.sort((a, b) => a.order - b.order) + + return defaultValues +} + +const toGridFormat = draggableListColumns => { + return draggableListColumns.map(entry => ({ + label: entry.label, + field: entry.field, + active: entry.active, + })) +} + +const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => { + return gridFormatColumns.map(column => { + return createComponent( + "@budibase/standard-components/labelfield", + { + _instanceName: column.field, + active: column.active, + field: column.field, + label: column.label, + columnType: schema[column.field].type, + }, + {} + ) + }) +} + +const getColumns = ({ + columns, + schema, + primaryDisplayColumnName, + onChange, + createComponent, +}) => { + const validatedColumns = removeInvalidAddMissing( + modernize(columns), + getDefault(schema), + primaryDisplayColumnName + ) + const draggableList = toDraggableListFormat( + validatedColumns, + createComponent, + schema + ) + const primary = draggableList.find( + entry => entry.field === primaryDisplayColumnName + ) + const sortable = draggableList.filter( + entry => entry.field !== primaryDisplayColumnName + ) + + return { + primary, + sortable, + updateSortable: newDraggableList => { + onChange(toGridFormat(newDraggableList.concat(primary))) + }, + update: newEntry => { + const newDraggableList = draggableList.map(entry => { + return newEntry.field === entry.field ? newEntry : entry + }) + + onChange(toGridFormat(newDraggableList)) + }, + } +} + +export default getColumns diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.test.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.test.js new file mode 100644 index 0000000000..d7092a2c52 --- /dev/null +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.test.js @@ -0,0 +1,374 @@ +import { it, expect, describe, beforeEach, vi } from "vitest" +import getColumns from "./getColumns" + +describe("getColumns", () => { + beforeEach(ctx => { + ctx.schema = { + one: { name: "one", visible: false, order: 0, type: "foo" }, + two: { name: "two", visible: true, order: 1, type: "foo" }, + three: { name: "three", visible: true, order: 2, type: "foo" }, + four: { name: "four", visible: false, order: 3, type: "foo" }, + five: { + name: "excluded", + visible: true, + order: 4, + type: "foo", + nestedJSON: true, + }, + } + + ctx.primaryDisplayColumnName = "four" + ctx.onChange = vi.fn() + ctx.createComponent = (componentName, props) => { + return { componentName, ...props } + } + }) + + describe("nested json fields", () => { + beforeEach(ctx => { + ctx.columns = getColumns({ + columns: null, + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + }) + + it("does not return nested json fields, as the grid cannot display them", ctx => { + expect(ctx.columns.sortable).not.toContainEqual({ + name: "excluded", + visible: true, + order: 4, + type: "foo", + nestedJSON: true, + }) + }) + }) + + describe("using the old grid column format", () => { + beforeEach(ctx => { + const oldGridFormatColumns = [ + { displayName: "three label", name: "three" }, + { displayName: "two label", name: "two" }, + ] + + ctx.columns = getColumns({ + columns: oldGridFormatColumns, + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + }) + + it("returns the selected and unselected fields in the modern format, respecting the original order", ctx => { + expect(ctx.columns.sortable).toEqual([ + { + _instanceName: "three", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "three", + label: "three label", + }, + { + _instanceName: "two", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "two", + label: "two label", + }, + { + _instanceName: "one", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "one", + label: "one", + }, + ]) + + expect(ctx.columns.primary).toEqual({ + _instanceName: "four", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "four", + label: "four", + }) + }) + }) + + describe("default columns", () => { + beforeEach(ctx => { + ctx.columns = getColumns({ + columns: undefined, + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + }) + + it("returns all columns, with non-hidden columns automatically selected", ctx => { + expect(ctx.columns.sortable).toEqual([ + { + _instanceName: "two", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "two", + label: "two", + }, + { + _instanceName: "three", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "three", + label: "three", + }, + { + _instanceName: "one", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "one", + label: "one", + }, + ]) + + expect(ctx.columns.primary).toEqual({ + _instanceName: "four", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "four", + label: "four", + }) + }) + + it("Unselected columns should be placed at the end", ctx => { + expect(ctx.columns.sortable[2].field).toEqual("one") + }) + }) + + describe("missing columns", () => { + beforeEach(ctx => { + const gridFormatColumns = [ + { label: "three label", field: "three", active: true }, + ] + + ctx.columns = getColumns({ + columns: gridFormatColumns, + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + }) + + it("returns all columns, including those missing from the initial data", ctx => { + expect(ctx.columns.sortable).toEqual([ + { + _instanceName: "three", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "three", + label: "three label", + }, + { + _instanceName: "two", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "two", + label: "two", + }, + { + _instanceName: "one", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "one", + label: "one", + }, + ]) + + expect(ctx.columns.primary).toEqual({ + _instanceName: "four", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "four", + label: "four", + }) + }) + }) + + describe("invalid columns", () => { + beforeEach(ctx => { + const gridFormatColumns = [ + { label: "three label", field: "three", active: true }, + { label: "some nonsense", field: "some nonsense", active: true }, + ] + + ctx.columns = getColumns({ + columns: gridFormatColumns, + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + }) + + it("returns all valid columns, excluding those that aren't valid for the schema", ctx => { + expect(ctx.columns.sortable).toEqual([ + { + _instanceName: "three", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "three", + label: "three label", + }, + { + _instanceName: "two", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "two", + label: "two", + }, + { + _instanceName: "one", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "one", + label: "one", + }, + ]) + + expect(ctx.columns.primary).toEqual({ + _instanceName: "four", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "four", + label: "four", + }) + }) + }) + + describe("methods", () => { + beforeEach(ctx => { + const { update, updateSortable } = getColumns({ + columns: [], + schema: ctx.schema, + primaryDisplayColumnName: ctx.primaryDisplayColumnName, + onChange: ctx.onChange, + createComponent: ctx.createComponent, + }) + + ctx.update = update + ctx.updateSortable = updateSortable + }) + + describe("update", () => { + beforeEach(ctx => { + ctx.update({ + field: "one", + label: "a new label", + active: true, + }) + }) + + it("calls the callback with the updated columns", ctx => { + expect(ctx.onChange).toHaveBeenCalledTimes(1) + expect(ctx.onChange).toHaveBeenCalledWith([ + { + field: "two", + label: "two", + active: true, + }, + { + field: "three", + label: "three", + active: true, + }, + { + field: "one", + label: "a new label", + active: true, + }, + { + field: "four", + label: "four", + active: true, + }, + ]) + }) + }) + + describe("updateSortable", () => { + beforeEach(ctx => { + ctx.updateSortable([ + { + _instanceName: "three", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "three", + label: "three", + }, + { + _instanceName: "one", + active: true, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "one", + label: "one", + }, + { + _instanceName: "two", + active: false, + columnType: "foo", + componentName: "@budibase/standard-components/labelfield", + field: "two", + label: "two", + }, + ]) + }) + + it("calls the callback with the updated columns", ctx => { + expect(ctx.onChange).toHaveBeenCalledTimes(1) + expect(ctx.onChange).toHaveBeenCalledWith([ + { + field: "three", + label: "three", + active: true, + }, + { + field: "one", + label: "one", + active: true, + }, + { + field: "two", + label: "two", + active: false, + }, + { + field: "four", + label: "four", + active: true, + }, + ]) + }) + }) + }) +}) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index a67c2d3c61..c3bb5171a4 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -781,7 +781,7 @@ {/if} {:else} - +
@@ -808,19 +808,21 @@ : Constants.BudibaseRoleOptionsNew.filter( option => option.value !== Constants.BudibaseRoles.Admin )} - label="Role" + label="Access" /> {#if creationRoleType !== Constants.BudibaseRoles.Admin} - + + + {/if} {#if creationRoleType === Constants.BudibaseRoles.Admin} @@ -847,6 +849,13 @@