Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / slices / common.slice.js
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { createSlice } from '@reduxjs/toolkit';
import { PLUGINS_IDS } from '@filerobot/utils/lib/constants';
import createThunk from '@filerobot/utils/lib/createThunk';
import { SORT_ORDER, SORT_BY } from '../components/common/Sort/Sort.constants';
import { fetchMetaAndSettings } from './metadata.slice';
import { viewsChanged } from './views.slice';
import { FILTERS_TYPES_KEYS_AND_I18N, SECTIONS_KEYS_AND_I18N } from '../components/Filters/Filters.constants';
var slicePropName = 'common';
var sliceName = "".concat(PLUGINS_IDS.EXPLORER, "/").concat(slicePropName);
var initialState = {
  loading: true,
  isPluginModalHidden: true,
  isPluginModalClosing: false,
  darkMode: false,
  containerWidth: 0,
  containerHeight: 0,
  areInsidesReadyToBeVisible: false,
  isDraggingOver: false,
  filtersActiveTypes: _defineProperty({}, SECTIONS_KEYS_AND_I18N.TAG, FILTERS_TYPES_KEYS_AND_I18N.ANY_SELECTED),
  publicConstants: {},
  sortOrder: SORT_ORDER.ASC,
  sortedBy: SORT_BY.NAME,
  accessRoles: [],
  accessRolesPermissions: [],
  permissionModel: null
};
export var fetchPublicConstants = createThunk(async function (_, thunkApi) {
  var _await$thunkApi$extra = await thunkApi.extra.apiClient.getAdmin('public/constants', {
      abortSignal: thunkApi.signal
    }),
    _await$thunkApi$extra2 = _await$thunkApi$extra.constants,
    constants = _await$thunkApi$extra2 === void 0 ? {} : _await$thunkApi$extra2;
  return {
    publicConstants: constants
  };
}, {
  actionType: "".concat(sliceName, "/fetchPublicConstants/set")
});
export var fetchAccessConstants = createThunk(async function (_, thunkApi) {
  var _thunkApi$extra$filer;
  var _await$thunkApi$extra3 = await thunkApi.extra.apiClient.getAdmin('keys/permissions', {
      abortSignal: thunkApi.signal
    }),
    permissions = _await$thunkApi$extra3.permissions;
  var accessRolesPermissions = (permissions || []).map(function (perm) {
    return _objectSpread(_objectSpread({}, perm), {}, {
      name: ((perm === null || perm === void 0 ? void 0 : perm.name) || '').replace(/\s\([A-Z_]+\)$/, '')
    });
  });
  var changes = {
    accessRolesPermissions: accessRolesPermissions
  };
  if (!((_thunkApi$extra$filer = thunkApi.extra.filerobot.opts) !== null && _thunkApi$extra$filer !== void 0 && _thunkApi$extra$filer.galleryRoles)) {
    var _await$thunkApi$extra4 = await thunkApi.extra.apiClient.getAdmin("project/".concat(thunkApi.extra.filerobot.opts.projectUuid, "/accesses/constants"), {
        abortSignal: thunkApi.signal
      }),
      roles = _await$thunkApi$extra4.roles;
    var accessRoles = (roles || []).map(function (role) {
      return _objectSpread(_objectSpread({}, role), {}, {
        permissions: typeof (role === null || role === void 0 ? void 0 : role.permissions) === 'string' ? JSON.parse(role.permissions) : (role === null || role === void 0 ? void 0 : role.permissions) || []
      });
    });
    if (roles) {
      roles.sort(function (a, b) {
        return +a.id - +b.id;
      });
    }
    changes.accessRoles = accessRoles;
  }
  return changes;
}, {
  actionType: "".concat(sliceName, "/fetchAccessConstants/set")
});
var commonSlice = createSlice({
  name: sliceName,
  initialState: initialState,
  reducers: {
    explorerPluginLoadingSet: function explorerPluginLoadingSet(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        loading: action.payload
      });
    },
    pluginModalHidden: function pluginModalHidden(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        isPluginModalHidden: action.payload,
        isPluginModalClosing: action.payload === true ? false : state.isPluginModalClosing
      });
    },
    pluginModalClosing: function pluginModalClosing(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        isPluginModalClosing: true
      });
    },
    darkModeUpdated: function darkModeUpdated(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        darkMode: action.payload
      });
    },
    forceFillingMetadataOnUploadUpdated: function forceFillingMetadataOnUploadUpdated(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        forceFillingMetadataOnUpload: action.payload
      });
    },
    filtersActiveTypesSet: function filtersActiveTypesSet(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        filtersActiveTypes: action.payload
      });
    },
    explorerCommonStateUpdated: function explorerCommonStateUpdated(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    },
    sortingUpdated: function sortingUpdated(state, action) {
      var _action$payload = action.payload,
        _action$payload$sortB = _action$payload.sortBy,
        sortBy = _action$payload$sortB === void 0 ? state.sortedBy : _action$payload$sortB,
        _action$payload$order = _action$payload.order,
        order = _action$payload$order === void 0 ? state.sortOrder : _action$payload$order;
      return _objectSpread(_objectSpread({}, state), {}, {
        sortedBy: sortBy,
        sortOrder: order
      });
    }
  },
  extraReducers: function extraReducers(builder) {
    builder.addCase(viewsChanged, function (state) {
      return _objectSpread(_objectSpread({}, state), {}, {
        sortOrder: initialState.sortOrder,
        sortedBy: initialState.sortedBy
      });
    }).addCase(fetchMetaAndSettings.fulfilled, function (state, _ref) {
      var permissionModel = _ref.payload.permissionModel;
      return _objectSpread(_objectSpread({}, state), {}, {
        permissionModel: permissionModel
      });
    }).addMatcher(function (_ref2) {
      var type = _ref2.type;
      return type.startsWith(sliceName) && type.endsWith('/set/pending');
    }, function (state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        error: null
      });
    }).addMatcher(function (_ref3) {
      var type = _ref3.type;
      return type.startsWith(sliceName) && type.endsWith('/set/fulfilled');
    }, function (state, action) {
      return _objectSpread(_objectSpread(_objectSpread({}, state), action.payload), {}, {
        error: null
      });
    }).addMatcher(function (_ref4) {
      var type = _ref4.type;
      return type.startsWith(sliceName) && type.endsWith('/set/rejected');
    }, function (state, action) {
      var _action$message;
      return _objectSpread(_objectSpread({}, state), {}, {
        error: ((_action$message = action.message) === null || _action$message === void 0 ? void 0 : _action$message.error) || action.message
      });
    });
  }
});
var _commonSlice$actions = commonSlice.actions,
  explorerPluginLoadingSet = _commonSlice$actions.explorerPluginLoadingSet,
  pluginModalHidden = _commonSlice$actions.pluginModalHidden,
  pluginModalClosing = _commonSlice$actions.pluginModalClosing,
  darkModeUpdated = _commonSlice$actions.darkModeUpdated,
  forceFillingMetadataOnUploadUpdated = _commonSlice$actions.forceFillingMetadataOnUploadUpdated,
  filtersActiveTypesSet = _commonSlice$actions.filtersActiveTypesSet,
  sortingUpdated = _commonSlice$actions.sortingUpdated,
  explorerCommonStateUpdated = _commonSlice$actions.explorerCommonStateUpdated;
export { explorerPluginLoadingSet, pluginModalHidden, pluginModalClosing, darkModeUpdated, forceFillingMetadataOnUploadUpdated, filtersActiveTypesSet, sortingUpdated, explorerCommonStateUpdated };
export var selectCommon = function selectCommon(state) {
  return state[PLUGINS_IDS.EXPLORER][slicePropName];
};
export var selectIsPluginModalHidden = function selectIsPluginModalHidden(state) {
  return selectCommon(state).isPluginModalHidden;
};
export var selectIsPluginModalClosing = function selectIsPluginModalClosing(state) {
  return selectCommon(state).isPluginModalClosing;
};
export var selectDarkMode = function selectDarkMode(state) {
  return selectCommon(state).darkMode;
};
export var selectAreInsidesReadyToBeVisible = function selectAreInsidesReadyToBeVisible(state) {
  return selectCommon(state).areInsidesReadyToBeVisible;
};
export var selectContainerWidth = function selectContainerWidth(state) {
  return selectCommon(state).containerWidth;
};
export var selectContainerHeight = function selectContainerHeight(state) {
  return selectCommon(state).containerHeight;
};
export var selectFiltersActiveTypes = function selectFiltersActiveTypes(state) {
  return selectCommon(state).filtersActiveTypes;
};
export var selectIsExplorerPluginLoading = function selectIsExplorerPluginLoading(state) {
  return selectCommon(state).loading;
};
export var selectPublicConstants = function selectPublicConstants(state) {
  return selectCommon(state).publicConstants;
};
export var selectSorting = function selectSorting(state) {
  return selectCommon(state).sorting;
};
export var selectVisibilities = function selectVisibilities(state) {
  return selectPublicConstants(state).visibility;
};
export var selectSortedBy = function selectSortedBy(state) {
  return selectCommon(state).sortedBy;
};
export var selectSortOrder = function selectSortOrder(state) {
  return selectCommon(state).sortOrder;
};
export var selectPermissionModel = function selectPermissionModel(state) {
  return selectCommon(state).permissionModel;
};
export var selectAccessRoles = function selectAccessRoles(state) {
  return selectCommon(state).accessRoles;
};
export var selectAccessRolesPermissions = function selectAccessRolesPermissions(state) {
  return selectCommon(state).accessRolesPermissions;
};
export var selectIsAscSortOrder = function selectIsAscSortOrder(state) {
  return selectSortOrder(state) === SORT_ORDER.ASC;
};
export default commonSlice.reducer;